1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-06 09:20:43 +01:00

doRefreshToken to its own function

This commit is contained in:
Kyle Spearrin 2017-09-07 23:56:05 -04:00
parent 219a434594
commit f36c046a36

View File

@ -83,7 +83,7 @@ function initApiService() {
};
ApiService.prototype.refreshIdentityToken = function (success, error) {
refreshToken(this, function () {
doRefreshToken(this, function () {
success();
}, function (jqXHR) {
if (jqXHR) {
@ -530,12 +530,27 @@ function initApiService() {
if (!self.tokenService.tokenNeedsRefresh()) {
log('Token doesn\'t need refreshing');
resolveTokenQs(accessToken, self, deferred);
resolveTokenQs(accessToken, deferred);
return;
}
log('Token needs refresh');
doRefreshToken(self, function (response) {
var tokenResponse = new IdentityTokenResponse(response);
self.tokenService.setTokens(tokenResponse.accessToken, tokenResponse.refreshToken, function () {
log('New token set.');
resolveTokenQs(tokenResponse.accessToken, deferred);
});
}, function (jqXHR) {
deferred.reject(jqXHR);
});
});
return deferred.promise;
}
function doRefreshToken(self, success, error) {
self.tokenService.getRefreshToken(function (refreshToken) {
if (!refreshToken || refreshToken === '') {
log('No existing refresh token.');
@ -557,25 +572,17 @@ function initApiService() {
dataType: 'json',
success: function (response) {
log('Successfully refreshed.');
var tokenResponse = new IdentityTokenResponse(response);
self.tokenService.setTokens(tokenResponse.accessToken, tokenResponse.refreshToken, function () {
log('New token set.');
resolveTokenQs(tokenResponse.accessToken, self, deferred);
});
success(response);
},
error: function (jqXHR, textStatus, errorThrown) {
log('Error refreshing.');
deferred.reject(jqXHR);
error(jqXHR);
}
});
});
});
return deferred.promise;
}
function resolveTokenQs(token, self, deferred) {
function resolveTokenQs(token, deferred) {
log('Resolving token.');
deferred.resolve('access_token3=' + token);
}