1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-24 16:49:26 +01:00

refresh access token after creating org

This commit is contained in:
Kyle Spearrin 2017-04-11 15:00:53 -04:00
parent 8984ec3127
commit 400932c6de
4 changed files with 31 additions and 19 deletions

View File

@ -10,7 +10,7 @@ angular
whiteListedDomains: ['api.bitwarden.com', 'localhost']
});
var refreshPromise;
jwtInterceptorProvider.tokenGetter = /*@ngInject*/ function (options, appSettings, tokenService, apiService,
jwtInterceptorProvider.tokenGetter = /*@ngInject*/ function (options, appSettings, tokenService, authService,
jwtHelper, $q) {
if (options.url.indexOf(appSettings.apiUri) !== 0) {
return;
@ -24,28 +24,15 @@ angular
if (!token) {
return;
}
if (!tokenService.tokenNeedsRefresh(token)) {
return token;
}
var refreshToken = tokenService.getRefreshToken();
if (!refreshToken) {
return;
}
var deferred = $q.defer();
apiService.identity.token({
grant_type: 'refresh_token',
client_id: 'web',
refresh_token: refreshToken
}, function (response) {
tokenService.setToken(response.access_token);
tokenService.setRefreshToken(response.refresh_token);
refreshPromise = authService.refreshAccessToken().then(function (newToken) {
refreshPromise = null;
deferred.resolve(response.access_token);
return newToken || token;
});
refreshPromise = deferred.promise;
return refreshPromise;
};

View File

@ -168,5 +168,22 @@ angular
return tokenService.getToken() !== null;
};
_service.refreshAccessToken = function () {
var refreshToken = tokenService.getRefreshToken();
if (!refreshToken) {
return null;
}
return apiService.identity.token({
grant_type: 'refresh_token',
client_id: 'web',
refresh_token: refreshToken
}).$promise.then(function (response) {
tokenService.setToken(response.access_token);
tokenService.setRefreshToken(response.refresh_token);
return response.access_token;
});
}
return _service;
});

View File

@ -70,7 +70,15 @@
$analytics.eventTrack('Created Organization');
authService.addProfileOrganizationOwner(result, shareKey);
$state.go('backend.org.dashboard', { orgId: result.Id }).then(function () {
authService.refreshAccessToken().then(function () {
goToOrg(result.Id);
}, function () {
goToOrg(result.Id);
});
}
function goToOrg(id) {
$state.go('backend.org.dashboard', { orgId: id }).then(function () {
toastr.success('Your new organization is ready to go!', 'Organization Created');
});
}

View File

@ -4,7 +4,7 @@
<section class="content">
<p>
Organizations allow you to share parts of your vault with others as well as manage related users
for a specific entity (such as a company).
for a specific entity (such as a family, small team, or large company).
</p>
<form name="createOrgForm" ng-submit="createOrgForm.$valid && submit(model)" api-form="submitPromise">
<div class="box box-default">