mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
Cloud support / Dropbox OAuth reference client (#659)
* bioms shouldn't be masked or the style selection box is useless * fix: misleading comment * Fix: calculating absolute flux from precipitation normal-value. * Fix: River automatic rerender on regeneration. * Dropbox OAuth implementation and Cloud framework * add some space * removing unnecessary logs, defer script load Created by: Mészáros Gergely <monk@geotronic.hu>
This commit is contained in:
parent
f7d72c2255
commit
2d3f465d68
6 changed files with 256 additions and 57 deletions
46
dropbox.html
Normal file
46
dropbox.html
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<script type="text/javascript" src="https://unpkg.com/dropbox@10.8.0/dist/Dropbox-sdk.min.js"></script>
|
||||
<title>FMG Dropbox Auth</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
/*
|
||||
open this page in a new window without query parameter to start auth
|
||||
window.opener.setDropBoxToken(token) will be called on the opener
|
||||
window.
|
||||
*/
|
||||
const REDIRECT_URI = window.location.origin + window.location.pathname;
|
||||
const dbxAuth = new Dropbox.DropboxAuth({ clientId: 'sp7tzwm27u2w5ns', });
|
||||
|
||||
const spObj = new URLSearchParams(window.location.search);
|
||||
const searchParams = Object.fromEntries(spObj.entries())
|
||||
|
||||
if (searchParams.code) getToken()
|
||||
else doAuth(); // start authentication
|
||||
|
||||
function doAuth() {
|
||||
dbxAuth.getAuthenticationUrl(REDIRECT_URI, undefined, 'code', 'offline', undefined, undefined, true)
|
||||
.then(authUrl => {
|
||||
window.sessionStorage.clear();
|
||||
window.sessionStorage.setItem("codeVerifier", dbxAuth.codeVerifier);
|
||||
window.location.href = authUrl;
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
};
|
||||
|
||||
function getToken() {
|
||||
dbxAuth.setCodeVerifier(window.sessionStorage.getItem('codeVerifier'));
|
||||
dbxAuth.getAccessTokenFromCode(REDIRECT_URI, searchParams.code)
|
||||
.then((resp) => {
|
||||
const token = resp.result.access_token;
|
||||
window.opener.Cloud.providers.dropbox.setDropBoxToken(token)
|
||||
}).catch((error) => {
|
||||
console.error(error)
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue