fix(dropbox): OAuth to use postMessage.

This commit is contained in:
Hristo Terezov 2021-12-01 13:15:17 -06:00 committed by Дамян Минков
parent 591eab7c97
commit 827e8201d4
2 changed files with 18 additions and 22 deletions

View File

@ -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);
});
}

View File

@ -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>