From dfeff76876909cf072dacc571b5f734637a3b745 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 8 Feb 2017 10:37:29 -0500 Subject: [PATCH] cleanup logs and debug statements --- oauth3.js | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/oauth3.js b/oauth3.js index 09f46a4..b0e19e3 100644 --- a/oauth3.js +++ b/oauth3.js @@ -48,17 +48,16 @@ oauth3.hooks = { checkSession: function (preq, opts) { if (!preq.session) { - console.error('NO SESSION to consider'); + console.warn('[oauth3.hooks.checkSession] no session'); return oauth3.PromiseA.resolve(null); } var freshness = oauth3.core.jwt.getFreshness(preq.session.meta, opts.staletime); - console.log('checkSession', freshness, preq.session); + console.info('[oauth3.hooks.checkSession] freshness', freshness, preq.session); switch (freshness) { case 'stale': return oauth3.hooks.sessionStale(preq.session); case 'expired': - console.log('expired checkSession', preq.session); return oauth3.hooks.sessionExpired(preq.session).then(function (newSession) { preq.session = newSession; return newSession; @@ -69,6 +68,7 @@ } } , sessionStale: function (staleSession) { + console.info('[oauth3.hooks.sessionStale] called'); if (oauth3.hooks._stalePromise) { return oauth3.PromiseA.resolve(staleSession); } @@ -86,8 +86,7 @@ return oauth3.PromiseA.resolve(staleSession); } , sessionExpired: function (expiredSession) { - console.log('expiredSession'); - console.log(expiredSession); + console.info('[oauth3.hooks.sessionExpired] called'); return oauth3.requests.refreshToken(expiredSession.provider_uri, expiredSession).then(function (newSession) { return newSession; // oauth3.hooks.refreshSession(expiredSession, newSession); }); @@ -96,6 +95,8 @@ var providerUri = oldSession.provider_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) { oldSession[key] = undefined; }); @@ -103,12 +104,15 @@ oldSession[key] = newSession[key]; }); - console.info('refreshSession', oldSession, newSession); + // info about the session of this API call + oldSession.provider_uri = providerUri; // aud + oldSession.client_uri = clientUri; // azp + + // info about the newly-discovered token oldSession.meta = core.jwt.decode(oldSession.access_token).payload; + oldSession.meta.sub = oldSession.meta.sub || oldSession.meta.acx.id; - oldSession.client_uri = clientUri; oldSession.meta.client_uri = clientUri; - oldSession.provider_uri = providerUri; oldSession.meta.provider_uri = providerUri; if (oldSession.refresh_token || oldSession.refreshToken) { @@ -117,15 +121,18 @@ oldSession.refresh.provider_uri = providerUri; } + console.info('[oauth3.hooks.refreshSession] refreshedSession', oldSession); + return oauth3.PromiseA.resolve(oauth3.hooks.setSession(oldSession)); } , setSession: function (newSession) { - console.warn('oauth3.hooks.setSession is not implemented'); - //console.warn(JSON.parse(JSON.stringify(oldSession))); + console.warn('[oauth3.hooks.setSession] PLEASE IMPLEMENT -- Your Fault'); console.warn(newSession); return newSession; } }; + + // TODO simplify (nix recase) oauth3.provideRequest = function (rawRequest, opts) { opts = opts || {}; var Recase = exports.Recase || require('recase'); @@ -185,11 +192,8 @@ return oauth3.discover(providerUri, opts).then(function (directive) { var prequest = core.urls.loginCode(directive, opts); - console.log('[DEBUG] [core] loginCode URL', prequest); - return oauth3.request(prequest).then(function (res) { // result = { uuid, expiresAt } - console.log('[DEBUG] [core] loginCode result', res); return { otpUuid: res.data.uuid , otpExpires: res.data.expiresAt @@ -200,14 +204,11 @@ oauth3.loginCode = oauth3.requests.loginCode; oauth3.requests.resourceOwnerPassword = function (providerUri, opts) { - console.log('DEBUG oauth3.resourceOwnerPassword opts', opts); //var scope = opts.scope; //var appId = opts.appId; return oauth3.discover(providerUri, opts).then(function (directive) { var prequest = core.urls.resourceOwnerPassword(directive, opts); - console.log('[DEBUG] [core] resourceOwnerPassword URL', prequest); - return oauth3.request({ url: prequest.url , method: prequest.method @@ -228,12 +229,10 @@ oauth3.resourceOwnerPassword = oauth3.requests.resourceOwnerPassword; oauth3.requests.refreshToken = function (providerUri, opts) { - console.warn('oauth3.requests.refreshToken', providerUri, opts); + console.info('[oauth3.requests.refreshToken] called', providerUri, opts); return oauth3.discover(providerUri, opts).then(function (directive) { var prequest = core.urls.refreshToken(directive, opts); - console.log('[DEBUG] [core] refreshToken URL', prequest); - return oauth3.request({ url: prequest.url , method: prequest.method @@ -263,9 +262,6 @@ }; oauth3.login = function (providerUri, opts) { - console.log('##### DEBUG oauth3.login providerUri, opts'); - console.log(providerUri); - console.log(opts); // Four styles of login: // * background (hidden iframe) // * iframe (visible iframe, needs border color and width x height params)