Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(dropbox): OAuth to use postMessage.

Hristo Terezov827e8201d413
diff --git a/react/features/dropbox/functions.web.js b/react/features/dropbox/functions.web.js
index da739ceab1..c0ddfee842 100644
--- a/react/features/dropbox/functions.web.js
+++ b/react/features/dropbox/functions.web.js
@@ -2,8 +2,6 @@
import { Dropbox, DropboxAuth } from 'dropbox';
-import { getJitsiMeetGlobalNS } from '../base/util';
-
/**
* Executes the oauth flow.
*
@@ -12,18 +10,22 @@ import { getJitsiMeetGlobalNS } from '../base/util';
*/
function authorize(authUrl: string): Promise<string> {
const windowName = `oauth${Date.now()}`;
- const gloabalNS = getJitsiMeetGlobalNS();
-
- gloabalNS.oauthCallbacks = gloabalNS.oauthCallbacks || {};
return new Promise(resolve => {
- const popup = window.open(authUrl, windowName);
-
- gloabalNS.oauthCallbacks[windowName] = url => {
- popup.close();
- delete gloabalNS.oauthCallbacks.windowName;
- resolve(url);
+ // eslint-disable-next-line prefer-const
+ let popup;
+ const handleAuth = ({ data }) => {
+ if (data && data.type === 'dropbox-login' && data.windowName === windowName) {
+ if (popup) {
+ popup.close();
+ }
+ window.removeEventListener('message', handleAuth);
+ resolve(data.url);
+ }
};
+
+ window.addEventListener('message', handleAuth);
+ popup = window.open(authUrl, windowName);
});
}
diff --git a/static/oauth.html b/static/oauth.html
index b5e082e6d7..7f02b24c33 100644
--- a/static/oauth.html
+++ b/static/oauth.html
@@ -8,17 +8,11 @@
<script>
(function() {
var windowName = window.name;
- var parentWindow = window.opener;
- if (parentWindow
- && parentWindow.JitsiMeetJS
- && parentWindow.JitsiMeetJS.app) {
- var globalNS = parentWindow.JitsiMeetJS.app;
- if (globalNS.oauthCallbacks
- && typeof globalNS.oauthCallbacks[windowName]
- === 'function') {
- globalNS.oauthCallbacks[windowName](window.location.href);
- }
- }
+ window.opener && window.opener.postMessage({
+ type: 'dropbox-login',
+ windowName,
+ url: window.location.href
+ }, window.location.origin);
})();
</script>
</head>