From 5b90d5ef38102c13097bc0b9e5fc75ffb2a1988f Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 29 Jun 2018 12:06:34 +0000 Subject: [PATCH] correct order of operations --- lib/relay.js | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/lib/relay.js b/lib/relay.js index 65656ad..449b3b2 100644 --- a/lib/relay.js +++ b/lib/relay.js @@ -257,21 +257,31 @@ var Server = { newAuth = JSON.stringify(newAuth); } + // TODO don't fire the onAuth event on non-authz updates + if (!grant.jwt && !(grant.domains||[]).length && !(grant.ports||[]).length) { + return null; + } + console.log('[onAuth] check for upgrade token'); - if (grant.jwt && newAuth !== grant.jwt) { - console.log('new token to send back'); - // Access Token - Server.sendTunnelMsg( - srv - , null - , [ 3 - , 'access_token' - , { jwt: grant.jwt } - ] - , 'control' - ); - // these aren't needed internally once they're sent - grant.jwt = null; + if (grant.jwt) { + if (newAuth !== grant.jwt) { + console.log('[onAuth] new token to send back'); + } + // TODO only send token when new + if (true) { + // Access Token + Server.sendTunnelMsg( + srv + , null + , [ 3 + , 'access_token' + , { jwt: grant.jwt } + ] + , 'control' + ); + // these aren't needed internally once they're sent + grant.jwt = null; + } } /* @@ -425,22 +435,24 @@ var Server = { } return state.authenticate({ auth: newAuth }).then(function (authnToken) { - console.log('\n[relay.js] newAuth'); console.log(newAuth); console.log('\n[relay.js] authnToken'); console.log(authnToken); - if (authnToken.id) { - state.srvs[authnToken.id] = state.srvs[authnToken.id] || {}; + // For tracking state between token exchanges + // and tacking on extra attributes (i.e. for extensions) + // TODO close on delete + if (!state.srvs[authnToken.id]) { + state.srvs[authnToken.id] = {}; + } + if (!state.srvs[authnToken.id].updateAuth) { state.srvs[authnToken.id].updateAuth = function (validToken) { return Server.onAuth(state, srv, newAuth, validToken); }; } - - // will return rejection if necessary - return state.srvs[authnToken.id].updateAuth(authnToken); + state.srvs[authnToken.id].updateAuth(authnToken); }); } , removeToken: function removeToken(state, srv, jwtoken) {