1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 11:13:46 +00:00

added device registraiton to token migration

This commit is contained in:
Kyle Spearrin
2017-01-25 22:57:32 -05:00
parent 4be033df71
commit 4df99d2d50
2 changed files with 23 additions and 16 deletions

View File

@@ -1,8 +1,10 @@
function ApiService(tokenService, logoutCallback) {
function ApiService(tokenService, appIdService, utilsService, logoutCallback) {
//this.baseUrl = 'http://localhost:4000';
this.baseUrl = 'https://api.bitwarden.com';
this.tokenService = tokenService;
this.logoutCallback = logoutCallback;
this.appIdService = appIdService;
this.utilsService = utilsService;
initApiService();
};
@@ -342,21 +344,26 @@ function initApiService() {
self.tokenService.getToken(function (accessToken) {
// handle transferring from old auth bearer
if (authBearer && !accessToken) {
postConnectToken(self, {
grant_type: 'password',
oldAuthBearer: authBearer,
username: 'abcdefgh', // has to be something
password: 'abcdefgh', // has to be something
scope: 'api offline_access',
client_id: 'browser'
}, function (token) {
self.tokenService.clearAuthBearer(function () {
tokenService.setTokens(token.accessToken, token.refreshToken, function () {
deferred.resolve(token.accessToken);
self.appIdService.getAppId(function (appId) {
postConnectToken(self, {
grant_type: 'password',
oldAuthBearer: authBearer,
username: 'abcdefgh', // has to be something
password: 'abcdefgh', // has to be something
scope: 'api offline_access',
client_id: 'browser',
deviceIdentifier: appId,
deviceType: self.utilsService.getDeviceType(),
deviceName: self.utilsService.getBrowser()
}, function (token) {
self.tokenService.clearAuthBearer(function () {
tokenService.setTokens(token.accessToken, token.refreshToken, function () {
deferred.resolve(token.accessToken);
});
});
}, function (jqXHR) {
deferred.reject(jqXHR);
});
}, function (jqXHR) {
deferred.reject(jqXHR);
});
} // handle token refresh
else if (self.tokenService.tokenNeedsRefresh()) {