|
|
@ -538,13 +538,14 @@ OAUTH3.authz.redirectWithToken = function (providerUri, session, clientParams, s |
|
|
|
var signProms = []; |
|
|
|
signProms.push(OAUTH3.jwt.sign(Object.assign({ |
|
|
|
exp: calcExpiration(clientParams.exp || '1h', now) |
|
|
|
}, payload))); |
|
|
|
}, payload), keyPair)); |
|
|
|
// if (clientParams.refresh_token) {
|
|
|
|
signProms.push(OAUTH3.jwt.sign(Object.assign({ |
|
|
|
exp: calcExpiration(clientParams.refresh_exp, now) |
|
|
|
}, payload))); |
|
|
|
}, payload), keyPair)); |
|
|
|
// }
|
|
|
|
return OAUTH3.PromiseA.all(signProms).then(function (tokens) { |
|
|
|
console.log('created new tokens for client'); |
|
|
|
return { |
|
|
|
access_token: tokens[0] |
|
|
|
, refresh_token: tokens[1] |
|
|
@ -558,6 +559,7 @@ OAUTH3.authz.redirectWithToken = function (providerUri, session, clientParams, s |
|
|
|
// TODO inform client not to persist token
|
|
|
|
OAUTH3.url.redirect(clientParams, scopes, session); |
|
|
|
}, function (err) { |
|
|
|
console.error('unexpected error creating client tokens', err); |
|
|
|
OAUTH3.url.redirect(clientParams, scopes, {error: err}); |
|
|
|
}); |
|
|
|
}; |
|
|
@ -637,7 +639,7 @@ OAUTH3.hooks.grants = { |
|
|
|
if (!clientUri) { |
|
|
|
throw new Error("clientUri is not set"); |
|
|
|
} |
|
|
|
return OAUTH3.PromiseA.resolve(OAUTH3._hooks.grants.get(OAUTH3.uri.normalize(clientUri))); |
|
|
|
return OAUTH3.PromiseA.resolve(OAUTH3._hooks.grants.get(id, OAUTH3.uri.normalize(clientUri))); |
|
|
|
} |
|
|
|
, set: function (id, clientUri, grants) { |
|
|
|
OAUTH3.hooks._checkStorage('grants', 'set'); |
|
|
@ -648,7 +650,7 @@ OAUTH3.hooks.grants = { |
|
|
|
if (!clientUri) { |
|
|
|
throw new Error("clientUri is not set"); |
|
|
|
} |
|
|
|
return OAUTH3.PromiseA.resolve(OAUTH3._hooks.grants.set(OAUTH3.uri.normalize(clientUri), grants)); |
|
|
|
return OAUTH3.PromiseA.resolve(OAUTH3._hooks.grants.set(id, OAUTH3.uri.normalize(clientUri), grants)); |
|
|
|
} |
|
|
|
, all: function () { |
|
|
|
OAUTH3.hooks._checkStorage('grants', 'all'); |
|
|
@ -721,7 +723,8 @@ OAUTH3.hooks.session.get = function (providerUri, id) { |
|
|
|
console.error("too many users, don't know which key to use"); |
|
|
|
} |
|
|
|
if (!pair) { |
|
|
|
return null; |
|
|
|
// even if the access token isn't fresh, the session might have a refresh token
|
|
|
|
return session; |
|
|
|
} |
|
|
|
|
|
|
|
var now = Math.floor(Date.now()/1000); |
|
|
@ -735,6 +738,7 @@ OAUTH3.hooks.session.get = function (providerUri, id) { |
|
|
|
, exp: now + 3600 |
|
|
|
}; |
|
|
|
return OAUTH3.jwt.sign(payload, pair.privateKey).then(function (token) { |
|
|
|
console.log('created new token for provider'); |
|
|
|
return OAUTH3.hooks.session.refresh( |
|
|
|
{ provider_uri: providerUri, client_uri: providerUri || providerUri } |
|
|
|
, { access_token: token } |
|
|
|