mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-23 11:56:00 +01:00
refresh access token after creating org
This commit is contained in:
parent
8984ec3127
commit
400932c6de
@ -10,7 +10,7 @@ angular
|
|||||||
whiteListedDomains: ['api.bitwarden.com', 'localhost']
|
whiteListedDomains: ['api.bitwarden.com', 'localhost']
|
||||||
});
|
});
|
||||||
var refreshPromise;
|
var refreshPromise;
|
||||||
jwtInterceptorProvider.tokenGetter = /*@ngInject*/ function (options, appSettings, tokenService, apiService,
|
jwtInterceptorProvider.tokenGetter = /*@ngInject*/ function (options, appSettings, tokenService, authService,
|
||||||
jwtHelper, $q) {
|
jwtHelper, $q) {
|
||||||
if (options.url.indexOf(appSettings.apiUri) !== 0) {
|
if (options.url.indexOf(appSettings.apiUri) !== 0) {
|
||||||
return;
|
return;
|
||||||
@ -29,23 +29,10 @@ angular
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
var refreshToken = tokenService.getRefreshToken();
|
refreshPromise = authService.refreshAccessToken().then(function (newToken) {
|
||||||
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 = null;
|
refreshPromise = null;
|
||||||
deferred.resolve(response.access_token);
|
return newToken || token;
|
||||||
});
|
});
|
||||||
refreshPromise = deferred.promise;
|
|
||||||
return refreshPromise;
|
return refreshPromise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -168,5 +168,22 @@ angular
|
|||||||
return tokenService.getToken() !== null;
|
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;
|
return _service;
|
||||||
});
|
});
|
||||||
|
@ -70,7 +70,15 @@
|
|||||||
|
|
||||||
$analytics.eventTrack('Created Organization');
|
$analytics.eventTrack('Created Organization');
|
||||||
authService.addProfileOrganizationOwner(result, shareKey);
|
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');
|
toastr.success('Your new organization is ready to go!', 'Organization Created');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<section class="content">
|
<section class="content">
|
||||||
<p>
|
<p>
|
||||||
Organizations allow you to share parts of your vault with others as well as manage related users
|
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>
|
</p>
|
||||||
<form name="createOrgForm" ng-submit="createOrgForm.$valid && submit(model)" api-form="submitPromise">
|
<form name="createOrgForm" ng-submit="createOrgForm.$valid && submit(model)" api-form="submitPromise">
|
||||||
<div class="box box-default">
|
<div class="box box-default">
|
||||||
|
Loading…
Reference in New Issue
Block a user