Parcourir la source

fix(dropbox): OAuth to use postMessage.

master
Hristo Terezov il y a 3 ans
Parent
révision
827e8201d4
2 fichiers modifiés avec 18 ajouts et 22 suppressions
  1. 13
    11
      react/features/dropbox/functions.web.js
  2. 5
    11
      static/oauth.html

+ 13
- 11
react/features/dropbox/functions.web.js Voir le fichier

@@ -2,8 +2,6 @@
2 2
 
3 3
 import { Dropbox, DropboxAuth } from 'dropbox';
4 4
 
5
-import { getJitsiMeetGlobalNS } from '../base/util';
6
-
7 5
 /**
8 6
  * Executes the oauth flow.
9 7
  *
@@ -12,18 +10,22 @@ import { getJitsiMeetGlobalNS } from '../base/util';
12 10
  */
13 11
 function authorize(authUrl: string): Promise<string> {
14 12
     const windowName = `oauth${Date.now()}`;
15
-    const gloabalNS = getJitsiMeetGlobalNS();
16
-
17
-    gloabalNS.oauthCallbacks = gloabalNS.oauthCallbacks || {};
18 13
 
19 14
     return new Promise(resolve => {
20
-        const popup = window.open(authUrl, windowName);
21
-
22
-        gloabalNS.oauthCallbacks[windowName] = url => {
23
-            popup.close();
24
-            delete gloabalNS.oauthCallbacks.windowName;
25
-            resolve(url);
15
+        // eslint-disable-next-line prefer-const
16
+        let popup;
17
+        const handleAuth = ({ data }) => {
18
+            if (data && data.type === 'dropbox-login' && data.windowName === windowName) {
19
+                if (popup) {
20
+                    popup.close();
21
+                }
22
+                window.removeEventListener('message', handleAuth);
23
+                resolve(data.url);
24
+            }
26 25
         };
26
+
27
+        window.addEventListener('message', handleAuth);
28
+        popup = window.open(authUrl, windowName);
27 29
     });
28 30
 }
29 31
 

+ 5
- 11
static/oauth.html Voir le fichier

@@ -8,17 +8,11 @@
8 8
     <script>
9 9
         (function() {
10 10
             var windowName = window.name;
11
-            var parentWindow = window.opener;
12
-            if (parentWindow
13
-                && parentWindow.JitsiMeetJS
14
-                && parentWindow.JitsiMeetJS.app) {
15
-                var globalNS = parentWindow.JitsiMeetJS.app;
16
-                if (globalNS.oauthCallbacks
17
-                    && typeof globalNS.oauthCallbacks[windowName]
18
-                        === 'function') {
19
-                    globalNS.oauthCallbacks[windowName](window.location.href);
20
-                }
21
-            }
11
+            window.opener && window.opener.postMessage({
12
+                type: 'dropbox-login',
13
+                windowName,
14
+                url: window.location.href
15
+            }, window.location.origin);
22 16
         })();
23 17
     </script>
24 18
 </head>

Chargement…
Annuler
Enregistrer