Commit d0bfcce7 authored by Sean Hammond's avatar Sean Hammond

Don't cache the OAuth grant token

Simplify the oauth-auth service by not caching the grant token in memory
- it is (now) only used once anyway.
parent 4e51fe3e
...@@ -16,11 +16,6 @@ function auth($http, settings) { ...@@ -16,11 +16,6 @@ function auth($http, settings) {
var cachedToken; var cachedToken;
var tokenUrl = resolve('token', settings.apiUrl); var tokenUrl = resolve('token', settings.apiUrl);
var grantToken;
if (Array.isArray(settings.services) && settings.services.length > 0) {
grantToken = settings.services[0].grantToken;
}
// Exchange the JWT grant token for an access token. // Exchange the JWT grant token for an access token.
// See https://tools.ietf.org/html/rfc7523#section-4 // See https://tools.ietf.org/html/rfc7523#section-4
function exchangeToken(grantToken) { function exchangeToken(grantToken) {
...@@ -43,15 +38,23 @@ function auth($http, settings) { ...@@ -43,15 +38,23 @@ function auth($http, settings) {
function tokenGetter() { function tokenGetter() {
if (cachedToken) { if (cachedToken) {
return Promise.resolve(cachedToken.token); return Promise.resolve(cachedToken.token);
} else if (grantToken) { } else {
var grantToken;
if (Array.isArray(settings.services) && settings.services.length > 0) {
grantToken = settings.services[0].grantToken;
}
if (!grantToken) {
return Promise.resolve(null);
}
return exchangeToken(grantToken).then(function (tokenInfo) { return exchangeToken(grantToken).then(function (tokenInfo) {
cachedToken = { cachedToken = {
token: tokenInfo.access_token, token: tokenInfo.access_token,
}; };
return cachedToken.token; return cachedToken.token;
}); });
} else {
return Promise.resolve(null);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment