2019-09-15 14:16:32 +02:00
|
|
|
import { Storage } from 'storage';
|
|
|
|
import { Features } from 'util/features';
|
2017-04-16 18:05:58 +02:00
|
|
|
|
2017-01-31 07:50:28 +01:00
|
|
|
const AuthReceiver = {
|
2019-08-18 10:17:09 +02:00
|
|
|
receive() {
|
2019-09-15 08:11:11 +02:00
|
|
|
if (!Features.isPopup && !Features.isStandalone) {
|
2019-03-28 22:02:04 +01:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-31 07:50:28 +01:00
|
|
|
const opener = window.opener || window.parent;
|
2017-04-16 17:00:35 +02:00
|
|
|
const message = this.urlArgsToMessage(window.location.href);
|
2017-06-03 20:11:09 +02:00
|
|
|
const hasKeys = Object.keys(message).filter(key => key !== 'config').length > 0;
|
|
|
|
if (!hasKeys) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-15 08:11:11 +02:00
|
|
|
if (Features.isStandalone) {
|
2019-03-28 22:02:04 +01:00
|
|
|
if (sessionStorage.authStorage) {
|
|
|
|
Storage[sessionStorage.authStorage].handleOAuthReturnMessage(message);
|
|
|
|
}
|
2017-04-16 18:05:58 +02:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
opener.postMessage(message, window.location.origin);
|
|
|
|
window.close();
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-27 16:47:29 +02:00
|
|
|
},
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
urlArgsToMessage(url) {
|
2017-01-31 07:50:28 +01:00
|
|
|
const message = {};
|
2017-05-16 21:29:24 +02:00
|
|
|
url.split(/[?#&]/g).forEach(part => {
|
2017-01-31 07:50:28 +01:00
|
|
|
const parts = part.split('=');
|
2016-03-27 16:47:29 +02:00
|
|
|
if (parts.length === 2) {
|
|
|
|
message[parts[0]] = parts[1];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return message;
|
2016-03-27 13:54:35 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-15 14:16:32 +02:00
|
|
|
export { AuthReceiver };
|