Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth.checkBearerToken() returns undefined after refreshing a token #148

Closed
eatyourgreens opened this issue Nov 25, 2021 · 1 comment
Closed
Labels

Comments

@eatyourgreens
Copy link
Contributor

eatyourgreens commented Nov 25, 2021

auth.checkBearerToken() returns undefined after refreshing a token, but it should return the refreshed token. The refreshed token is correctly set in the client, so subsequent calls do work.

// check an expired token. This should set token to the refreshed token but actually returns undefined.
let token = await auth.checkBearerToken()
// token is now refreshed. This sets it correctly.
token = await auth.checkBearerToken()

The underlying cause is that _refreshBearerToken returns undefined. It should return a Promise that resolves to the refreshed token.

_refreshBearerToken: function() {
if (this._tokenRefreshPromise === null) {
console.log('Refreshing expired bearer token');
var url = config.host + '/oauth/token';
var data = {
grant_type: 'refresh_token',
refresh_token: this._refreshToken,
client_id: config.clientAppID,
};
this._tokenRefreshPromise = makeHTTPRequest('POST', url, data, config.jsonHeaders)
.then(function(request) {
var token = this._handleNewBearerToken(request);
console.info('Refreshed bearer token', token.slice(-6));
}.bind(this))
.catch(function(request) {
console.error('Failed to refresh bearer token');
apiClient.handleError(request);
})
.then(function() {
this._tokenRefreshPromise = null;
}.bind(this));
}
return this._tokenRefreshPromise;
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant