-
-
Notifications
You must be signed in to change notification settings - Fork 886
Dropbox authentication #1367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dropbox authentication #1367
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| <!DOCTYPE html> | ||
| <!doctype html> | ||
| <html lang="en" dir="ltr"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
|
|
@@ -17,7 +17,7 @@ | |
| const error = params.get("error"); | ||
|
|
||
| if (code) getToken(); | ||
| else if (error) window.opener.Cloud.providers.dropbox.returnError(params.get("error_description")); | ||
| else if (error) returnError(params.get("error_description")); | ||
| else startAuth(); | ||
|
|
||
| function startAuth() { | ||
|
|
@@ -31,13 +31,23 @@ | |
| .catch(error => console.error(error)); | ||
| } | ||
|
|
||
| function returnError(description) { | ||
| const channel = new BroadcastChannel("dropbox-auth"); | ||
| channel.postMessage({type: "error", description}); | ||
| channel.close(); | ||
| window.close(); | ||
| } | ||
|
|
||
| function getToken() { | ||
| auth.setCodeVerifier(window.sessionStorage.getItem("codeVerifier")); | ||
| auth | ||
| .getAccessTokenFromCode(REDIRECT_URI, code) | ||
| .then(resp => { | ||
| const token = resp.result.access_token; | ||
| window.opener.Cloud.providers.dropbox.setDropBoxToken(token); | ||
| const channel = new BroadcastChannel("dropbox-auth"); | ||
| channel.postMessage({type: "token", token}); | ||
| channel.close(); | ||
| window.close(); | ||
| }) | ||
| .catch(error => { | ||
| console.error(error); | ||
|
Comment on lines
+49
to
53
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,26 +95,30 @@ window.Cloud = (function () { | |
| reject(new Error("Timeout. No auth for Dropbox")); | ||
| }, 120 * 1000); | ||
|
|
||
| window.addEventListener("dropboxauth", e => { | ||
| const channel = new BroadcastChannel("dropbox-auth"); | ||
| channel.onmessage = async ({data}) => { | ||
| channel.close(); | ||
| clearTimeout(watchDog); | ||
|
Comment on lines
+98
to
101
|
||
| resolve(); | ||
| }); | ||
| if (data.type === "token") { | ||
| await this.setDropBoxToken(data.token); | ||
|
Comment on lines
+99
to
+103
|
||
| resolve(); | ||
| } else { | ||
| this.returnError(data.description); | ||
| reject(new Error(data.description)); | ||
| } | ||
|
Comment on lines
+102
to
+108
|
||
| }; | ||
| }); | ||
| }, | ||
|
|
||
| // Callback function for auth window | ||
| async setDropBoxToken(token) { | ||
| DEBUG.cloud && console.info("Access token:", token); | ||
| setToken(this.name, token); | ||
| await this.connect(token); | ||
| this.authWindow.close(); | ||
| window.dispatchEvent(new Event("dropboxauth")); | ||
| }, | ||
|
|
||
| returnError(errorDescription) { | ||
| console.error(errorDescription); | ||
| tip(errorDescription.replaceAll("+", " "), true, "error", 4000); | ||
| this.authWindow.close(); | ||
| }, | ||
|
|
||
| async getLink(path) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
params.get("error_description")can benull, which will then be broadcast and eventually crashreturnErrorin the opener (it callsreplaceAllon the value). Provide a fallback string before callingreturnError(and/or coercedescriptionto a string insidereturnError).