Browse Source

fix(dropbox): OAuth to use postMessage.

master
Hristo Terezov 3 years ago
parent
commit
827e8201d4
2 changed files with 18 additions and 22 deletions
  1. 13
    11
      react/features/dropbox/functions.web.js
  2. 5
    11
      static/oauth.html

+ 13
- 11
react/features/dropbox/functions.web.js View File

2
 
2
 
3
 import { Dropbox, DropboxAuth } from 'dropbox';
3
 import { Dropbox, DropboxAuth } from 'dropbox';
4
 
4
 
5
-import { getJitsiMeetGlobalNS } from '../base/util';
6
-
7
 /**
5
 /**
8
  * Executes the oauth flow.
6
  * Executes the oauth flow.
9
  *
7
  *
12
  */
10
  */
13
 function authorize(authUrl: string): Promise<string> {
11
 function authorize(authUrl: string): Promise<string> {
14
     const windowName = `oauth${Date.now()}`;
12
     const windowName = `oauth${Date.now()}`;
15
-    const gloabalNS = getJitsiMeetGlobalNS();
16
-
17
-    gloabalNS.oauthCallbacks = gloabalNS.oauthCallbacks || {};
18
 
13
 
19
     return new Promise(resolve => {
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 View File

8
     <script>
8
     <script>
9
         (function() {
9
         (function() {
10
             var windowName = window.name;
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
     </script>
17
     </script>
24
 </head>
18
 </head>

Loading…
Cancel
Save