From cd1ff73eeaa5552265dceb6155eb99f980dfc731 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Mon, 3 Jul 2017 12:45:21 -0600 Subject: [PATCH] handled case of un-refreshable saved session --- js/issuer.js | 52 +++++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/js/issuer.js b/js/issuer.js index bc575d2..549b546 100644 --- a/js/issuer.js +++ b/js/issuer.js @@ -171,9 +171,6 @@ $(function () { }); $('.js-authz').show().addClass('in'); - }, function (err) { - window.alert('grantResults: ' + err.message); - console.error('scope results', err); }); } @@ -283,35 +280,31 @@ $(function () { , expire: opts.rememberDevice || (1 * 60 * 60 * 1000) , mock: true }).then(function (session) { - $('.js-authn').removeClass('in').hide(); - - function getAccount(session) { - if (session.token.sub) { - return OAUTH3.PromiseA.resolve(session); - } - - return OAUTH3.requests.accounts.create(CONFIG.directives, session, { - display_name: email.replace(/@.*/, '') - , comment: "created for '" + email + "' by '" + CONFIG.host + "'" - , priority: 1000 // default priority for first account - , name: undefined // TODO we could ask in the UI - }).then(function (resp) { - var results = resp.data; - return OAUTH3.hooks.session.refresh(session, { - access_token: (results.access_token || results.accessToken) - , refresh_token: (results.refresh_token || results.refreshToken) - }); - }); + if (session.token.sub) { + return OAUTH3.PromiseA.resolve(session); } - return getAccount(session).then(function () { - return getGrants(session); + return OAUTH3.requests.accounts.create(CONFIG.directives, session, { + display_name: email.replace(/@.*/, '') + , comment: "created for '" + email + "' by '" + CONFIG.host + "'" + , priority: 1000 // default priority for first account + , name: undefined // TODO we could ask in the UI + }).then(function (resp) { + var results = resp.data; + return OAUTH3.hooks.session.refresh(session, { + access_token: (results.access_token || results.accessToken) + , refresh_token: (results.refresh_token || results.refreshToken) + }); + }); + }).then(function (session) { + return getGrants(session).catch(function (err) { + window.alert('grantResults: ' + err.message); + console.error('scope results', err); }); }, function (error) { $('.error-msg').text('Incorrect code'); }); - }; util.acceptScopesAndLogin = function (ev) { ev.preventDefault(); @@ -371,6 +364,8 @@ $(function () { // // Page Setup // + $('.js-authorization-dialog').hide(); + $('.js-logout-container').hide(); $('.js-userid-container').hide(); $('.js-authn').hide(); $('.js-authz').hide(); @@ -387,7 +382,7 @@ $(function () { function handleAuthorizationDialog() { return getSession(CONFIG.host).then(function (session) { return getGrants(session); - }, function (e) { + }).catch(function () { // TODO select the providers the client wants to show // providers=daplie.com,facebook.com,google.com // etc // TODO let the client specify switch_user @@ -405,8 +400,6 @@ $(function () { $('.js-authn-show').prop('disabled', false); } $('.js-userid-container').show(); - }).then(function () { - //$('body').addClass('in'); }); } @@ -416,9 +409,6 @@ $(function () { CONFIG.directives = directives; directives.issuer = directives.issuer || (window.location.host + window.location.pathname).replace(/\/$/, ''); - $('.js-authorization-dialog').hide(); - $('.js-logout-container').hide(); - if (/authorization_dialog/.test(window.location.href)) { $('.js-authorization-dialog').show(); handleAuthorizationDialog();