Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
51 lines
1.2 KiB
JavaScript
Executable file
51 lines
1.2 KiB
JavaScript
Executable file
'use strict';
|
|
|
|
/* globals Curtain, oauth2 */
|
|
|
|
if (typeof window.oauthFrame === 'undefined') {
|
|
(function() {
|
|
|
|
var targetService;
|
|
var oauthFrame = window.oauthFrame = {};
|
|
var CONTACTS_APP_ORIGIN = location.origin;
|
|
|
|
function notifyParent(message, origin) {
|
|
parent.postMessage({
|
|
type: message.type || '',
|
|
data: message.data || ''
|
|
}, origin);
|
|
}
|
|
|
|
function cancelCb() {
|
|
Curtain.hide(notifyParent.bind(null, {
|
|
type: 'abort'
|
|
}, CONTACTS_APP_ORIGIN));
|
|
}
|
|
|
|
oauthFrame.start = function(from, service) {
|
|
targetService = service;
|
|
oauth2.getAccessToken(function tokenReady(access_token) {
|
|
Curtain.oncancel = cancelCb;
|
|
|
|
if (!Curtain.visible) {
|
|
Curtain.show('wait', from);
|
|
}
|
|
|
|
parent.postMessage({
|
|
type: 'authenticated',
|
|
data: access_token
|
|
}, CONTACTS_APP_ORIGIN);
|
|
}, from, service);
|
|
};
|
|
|
|
window.addEventListener('message', function messageHandler(e) {
|
|
if (e.origin !== CONTACTS_APP_ORIGIN) {
|
|
return;
|
|
}
|
|
var data = e.data;
|
|
if (data && data.type === 'start') {
|
|
oauthFrame.start(data.data.from, data.data.service);
|
|
}
|
|
});
|
|
})();
|
|
}
|