cleanup logs and debug statements

This commit is contained in:
AJ ONeal 2017-02-08 10:37:29 -05:00
parent daf832cab5
commit dfeff76876
1 changed files with 18 additions and 22 deletions

View File

@ -48,17 +48,16 @@
oauth3.hooks = { oauth3.hooks = {
checkSession: function (preq, opts) { checkSession: function (preq, opts) {
if (!preq.session) { if (!preq.session) {
console.error('NO SESSION to consider'); console.warn('[oauth3.hooks.checkSession] no session');
return oauth3.PromiseA.resolve(null); return oauth3.PromiseA.resolve(null);
} }
var freshness = oauth3.core.jwt.getFreshness(preq.session.meta, opts.staletime); 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) { switch (freshness) {
case 'stale': case 'stale':
return oauth3.hooks.sessionStale(preq.session); return oauth3.hooks.sessionStale(preq.session);
case 'expired': case 'expired':
console.log('expired checkSession', preq.session);
return oauth3.hooks.sessionExpired(preq.session).then(function (newSession) { return oauth3.hooks.sessionExpired(preq.session).then(function (newSession) {
preq.session = newSession; preq.session = newSession;
return newSession; return newSession;
@ -69,6 +68,7 @@
} }
} }
, sessionStale: function (staleSession) { , sessionStale: function (staleSession) {
console.info('[oauth3.hooks.sessionStale] called');
if (oauth3.hooks._stalePromise) { if (oauth3.hooks._stalePromise) {
return oauth3.PromiseA.resolve(staleSession); return oauth3.PromiseA.resolve(staleSession);
} }
@ -86,8 +86,7 @@
return oauth3.PromiseA.resolve(staleSession); return oauth3.PromiseA.resolve(staleSession);
} }
, sessionExpired: function (expiredSession) { , sessionExpired: function (expiredSession) {
console.log('expiredSession'); console.info('[oauth3.hooks.sessionExpired] called');
console.log(expiredSession);
return oauth3.requests.refreshToken(expiredSession.provider_uri, expiredSession).then(function (newSession) { return oauth3.requests.refreshToken(expiredSession.provider_uri, expiredSession).then(function (newSession) {
return newSession; // oauth3.hooks.refreshSession(expiredSession, newSession); return newSession; // oauth3.hooks.refreshSession(expiredSession, newSession);
}); });
@ -96,6 +95,8 @@
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;
}); });
@ -103,12 +104,15 @@
oldSession[key] = newSession[key]; 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 = core.jwt.decode(oldSession.access_token).payload;
oldSession.meta.sub = oldSession.meta.sub || oldSession.meta.acx.id; oldSession.meta.sub = oldSession.meta.sub || oldSession.meta.acx.id;
oldSession.client_uri = clientUri;
oldSession.meta.client_uri = clientUri; oldSession.meta.client_uri = clientUri;
oldSession.provider_uri = providerUri;
oldSession.meta.provider_uri = providerUri; oldSession.meta.provider_uri = providerUri;
if (oldSession.refresh_token || oldSession.refreshToken) { if (oldSession.refresh_token || oldSession.refreshToken) {
@ -117,15 +121,18 @@
oldSession.refresh.provider_uri = providerUri; oldSession.refresh.provider_uri = providerUri;
} }
console.info('[oauth3.hooks.refreshSession] refreshedSession', oldSession);
return oauth3.PromiseA.resolve(oauth3.hooks.setSession(oldSession)); return oauth3.PromiseA.resolve(oauth3.hooks.setSession(oldSession));
} }
, setSession: function (newSession) { , setSession: function (newSession) {
console.warn('oauth3.hooks.setSession is not implemented'); console.warn('[oauth3.hooks.setSession] PLEASE IMPLEMENT -- Your Fault');
//console.warn(JSON.parse(JSON.stringify(oldSession)));
console.warn(newSession); console.warn(newSession);
return newSession; return newSession;
} }
}; };
// TODO simplify (nix recase)
oauth3.provideRequest = function (rawRequest, opts) { oauth3.provideRequest = function (rawRequest, opts) {
opts = opts || {}; opts = opts || {};
var Recase = exports.Recase || require('recase'); var Recase = exports.Recase || require('recase');
@ -185,11 +192,8 @@
return oauth3.discover(providerUri, opts).then(function (directive) { return oauth3.discover(providerUri, opts).then(function (directive) {
var prequest = core.urls.loginCode(directive, opts); var prequest = core.urls.loginCode(directive, opts);
console.log('[DEBUG] [core] loginCode URL', prequest);
return oauth3.request(prequest).then(function (res) { return oauth3.request(prequest).then(function (res) {
// result = { uuid, expiresAt } // result = { uuid, expiresAt }
console.log('[DEBUG] [core] loginCode result', res);
return { return {
otpUuid: res.data.uuid otpUuid: res.data.uuid
, otpExpires: res.data.expiresAt , otpExpires: res.data.expiresAt
@ -200,14 +204,11 @@
oauth3.loginCode = oauth3.requests.loginCode; oauth3.loginCode = oauth3.requests.loginCode;
oauth3.requests.resourceOwnerPassword = function (providerUri, opts) { oauth3.requests.resourceOwnerPassword = function (providerUri, opts) {
console.log('DEBUG oauth3.resourceOwnerPassword opts', opts);
//var scope = opts.scope; //var scope = opts.scope;
//var appId = opts.appId; //var appId = opts.appId;
return oauth3.discover(providerUri, opts).then(function (directive) { return oauth3.discover(providerUri, opts).then(function (directive) {
var prequest = core.urls.resourceOwnerPassword(directive, opts); var prequest = core.urls.resourceOwnerPassword(directive, opts);
console.log('[DEBUG] [core] resourceOwnerPassword URL', prequest);
return oauth3.request({ return oauth3.request({
url: prequest.url url: prequest.url
, method: prequest.method , method: prequest.method
@ -228,12 +229,10 @@
oauth3.resourceOwnerPassword = oauth3.requests.resourceOwnerPassword; oauth3.resourceOwnerPassword = oauth3.requests.resourceOwnerPassword;
oauth3.requests.refreshToken = function (providerUri, opts) { 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) { return oauth3.discover(providerUri, opts).then(function (directive) {
var prequest = core.urls.refreshToken(directive, opts); var prequest = core.urls.refreshToken(directive, opts);
console.log('[DEBUG] [core] refreshToken URL', prequest);
return oauth3.request({ return oauth3.request({
url: prequest.url url: prequest.url
, method: prequest.method , method: prequest.method
@ -263,9 +262,6 @@
}; };
oauth3.login = function (providerUri, opts) { oauth3.login = function (providerUri, opts) {
console.log('##### DEBUG oauth3.login providerUri, opts');
console.log(providerUri);
console.log(opts);
// Four styles of login: // Four styles of login:
// * background (hidden iframe) // * background (hidden iframe)
// * iframe (visible iframe, needs border color and width x height params) // * iframe (visible iframe, needs border color and width x height params)