This commit is contained in:
AJ ONeal 2017-02-14 14:51:28 -07:00
parent 69a92fc2fd
commit 735f3e0cc6
1 changed files with 1 additions and 27 deletions

View File

@ -207,7 +207,6 @@
return result; return result;
} }
, implicitGrant: function (directive, opts) { , implicitGrant: function (directive, opts) {
//console.log('[implicitGrant]');
// //
// Example Implicit Grant Request // Example Implicit Grant Request
// (for generating a browser-only session, not a session on your server) // (for generating a browser-only session, not a session on your server)
@ -352,8 +351,6 @@
var providerUri = oldSession.provider_uri; var providerUri = oldSession.provider_uri;
var clientUri = oldSession.client_uri; var clientUri = oldSession.client_uri;
console.info('[oauth3.hooks.refreshSession] oldSession', JSON.parse(JSON.stringify(oldSession)));
console.info('[oauth3.hooks.refreshSession] newSession', newSession);
Object.keys(oldSession).forEach(function (key) { Object.keys(oldSession).forEach(function (key) {
oldSession[key] = undefined; oldSession[key] = undefined;
}); });
@ -378,18 +375,14 @@
oldSession.refresh.provider_uri = providerUri; oldSession.refresh.provider_uri = providerUri;
} }
console.info('[oauth3.hooks.refreshSession] refreshedSession', oldSession);
// set for a set of audiences // set for a set of audiences
return OAUTH3.PromiseA.resolve(OAUTH3.hooks.session.set(providerUri, oldSession)); return OAUTH3.PromiseA.resolve(OAUTH3.hooks.session.set(providerUri, oldSession));
} }
, check: function (preq, opts) { , check: function (preq, opts) {
if (!preq.session) { if (!preq.session) {
console.warn('[oauth3.hooks.checkSession] no session');
return OAUTH3.PromiseA.resolve(null); return OAUTH3.PromiseA.resolve(null);
} }
var freshness = OAUTH3.jwt.freshness(preq.session.token, opts.staletime); var freshness = OAUTH3.jwt.freshness(preq.session.token, opts.staletime);
console.info('[oauth3.hooks.checkSession] freshness', freshness, preq.session);
switch (freshness) { switch (freshness) {
case 'stale': case 'stale':
@ -405,7 +398,6 @@
} }
} }
, stale: function (staleSession) { , stale: function (staleSession) {
console.info('[oauth3.hooks.sessionStale] called');
if (OAUTH3.hooks.session._stalePromise) { if (OAUTH3.hooks.session._stalePromise) {
return OAUTH3.PromiseA.resolve(staleSession); return OAUTH3.PromiseA.resolve(staleSession);
} }
@ -426,7 +418,6 @@
return OAUTH3.PromiseA.resolve(staleSession); return OAUTH3.PromiseA.resolve(staleSession);
} }
, expired: function (expiredSession) { , expired: function (expiredSession) {
console.info('[oauth3.hooks.sessionExpired] called');
return OAUTH3._refreshToken( return OAUTH3._refreshToken(
expiredSession.provider_uri expiredSession.provider_uri
, { client_uri: expiredSession.client_uri , { client_uri: expiredSession.client_uri
@ -569,12 +560,10 @@
if (opts.broker) { if (opts.broker) {
// Discovery can happen in-flow because we know that this is // Discovery can happen in-flow because we know that this is
// a valid oauth3 provider // a valid oauth3 provider
console.info("broker implicit grant");
promise = OAUTH3._discoverThenImplicitGrant(providerUri, opts); promise = OAUTH3._discoverThenImplicitGrant(providerUri, opts);
} }
else { else {
// Discovery must take place before calling implicitGrant // Discovery must take place before calling implicitGrant
console.info("direct implicit grant");
promise = OAUTH3._implicitGrant(OAUTH3.hooks.directives._getCached(providerUri), opts); promise = OAUTH3._implicitGrant(OAUTH3.hooks.directives._getCached(providerUri), opts);
} }
@ -599,9 +588,7 @@
, _discoverThenImplicitGrant: function(providerUri, opts) { , _discoverThenImplicitGrant: function(providerUri, opts) {
opts.windowType = opts.windowType || 'popup'; opts.windowType = opts.windowType || 'popup';
return OAUTH3.discover(providerUri, opts).then(function (directives) { return OAUTH3.discover(providerUri, opts).then(function (directives) {
console.info('Discover complete');
return OAUTH3._implicitGrant(directives, opts).then(function (tokens) { return OAUTH3._implicitGrant(directives, opts).then(function (tokens) {
console.info('Implicit Grant complete', tokens);
return tokens; return tokens;
}); });
}); });
@ -623,7 +610,6 @@
window.alert("DEBUG MODE: Pausing so you can look at logs and whatnot :) Fire at will!"); window.alert("DEBUG MODE: Pausing so you can look at logs and whatnot :) Fire at will!");
} }
console.log("framing request for implicit grant");
return OAUTH3._browser.frameRequest( return OAUTH3._browser.frameRequest(
OAUTH3.utils.url.resolve(directives.issuer, authReq.url) OAUTH3.utils.url.resolve(directives.issuer, authReq.url)
, authReq.state // state should recycle params , authReq.state // state should recycle params
@ -632,7 +618,6 @@
, debug: opts.debug , debug: opts.debug
} }
).then(function (tokens) { ).then(function (tokens) {
console.log("completed implicit grant");
if (tokens.error) { if (tokens.error) {
// TODO directives.audience // TODO directives.audience
return OAUTH3.PromiseA.reject(OAUTH3.utils._formatError(directives.issuer /*providerUri*/, tokens)); return OAUTH3.PromiseA.reject(OAUTH3.utils._formatError(directives.issuer /*providerUri*/, tokens));
@ -642,7 +627,6 @@
}); });
} }
, _refreshToken: function (providerUri, opts) { , _refreshToken: function (providerUri, opts) {
console.info('[oauth3.requests.refreshToken] called', providerUri, opts);
return OAUTH3.discover(providerUri, opts).then(function (directive) { return OAUTH3.discover(providerUri, opts).then(function (directive) {
var prequest = OAUTH3.urls.refreshToken(directive, opts); var prequest = OAUTH3.urls.refreshToken(directive, opts);
@ -705,7 +689,6 @@
}); });
} }
, frameRequest: function (url, state, opts) { , frameRequest: function (url, state, opts) {
console.log('frameRequest state', state);
opts = opts || {}; opts = opts || {};
var previousFrame = OAUTH3._browser._frames[state]; var previousFrame = OAUTH3._browser._frames[state];
@ -759,26 +742,20 @@
if ('background' === windowType) { if ('background' === windowType) {
if (previousFrame) { if (previousFrame) {
console.log('previous frame in background');
previousFrame.location = url; previousFrame.location = url;
//promise = previousFrame.promise; //promise = previousFrame.promise;
} }
else { else {
console.log('NO previous frame in background');
OAUTH3._browser._frames[state] = OAUTH3._browser.iframe(url, state, opts); OAUTH3._browser._frames[state] = OAUTH3._browser.iframe(url, state, opts);
} }
} else if ('popup' === windowType) { } else if ('popup' === windowType) {
if (previousFrame) { if (previousFrame) {
console.log('previous frame in pop');
console.log(previousFrame);
console.log(url);
previousFrame.location = url; previousFrame.location = url;
if (opts.debug) { if (opts.debug) {
previousFrame.focus(); previousFrame.focus();
} }
} }
else { else {
console.log('NO previous frame in popup');
OAUTH3._browser._frames[state] = OAUTH3._browser.frame(url, state, opts); OAUTH3._browser._frames[state] = OAUTH3._browser.frame(url, state, opts);
} }
} else if ('inline' === windowType) { } else if ('inline' === windowType) {
@ -794,7 +771,6 @@
} }
}).then(function (params) { }).then(function (params) {
console.log('frameRequest formatting params (weird that this place exists, but not weird to be here)');
if (params.error) { if (params.error) {
// TODO directives.issuer || directives.audience // TODO directives.issuer || directives.audience
return OAUTH3.PromiseA.reject(OAUTH3.utils._formatError('https://oauth3.org', params)); return OAUTH3.PromiseA.reject(OAUTH3.utils._formatError('https://oauth3.org', params));
@ -805,15 +781,13 @@
, closeFrame: function (state, opts) { , closeFrame: function (state, opts) {
opts = opts || {}; opts = opts || {};
function close() { function close() {
console.log("Attempting to close... ", OAUTH3._browser._frames[state]);
try { try {
OAUTH3._browser._frames[state].close(); OAUTH3._browser._frames[state].close();
} catch(e) { } catch(e) {
console.error(e);
try { try {
OAUTH3._browser._frames[state].remove(); OAUTH3._browser._frames[state].remove();
} catch(e) { } catch(e) {
console.error(e); console.error(new Error("Could not clase window/iframe. closeFrame may have been called twice."));
} }
} }