From 4df99d2d5013109853f58826d654c99c65891b66 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 25 Jan 2017 22:57:32 -0500 Subject: [PATCH] added device registraiton to token migration --- src/background.js | 4 ++-- src/services/apiService.js | 35 +++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/background.js b/src/background.js index 0602b91a03..35268c1ce0 100644 --- a/src/background.js +++ b/src/background.js @@ -5,7 +5,8 @@ var constantsService = new ConstantsService(); var utilsService = new UtilsService(); var cryptoService = new CryptoService(constantsService); var tokenService = new TokenService(); -var apiService = new ApiService(tokenService, logout); +var appIdService = new AppIdService(); +var apiService = new ApiService(tokenService, appIdService, utilsService, logout); var userService = new UserService(tokenService, apiService, cryptoService); var settingsService = new SettingsService(userService); var loginService = new LoginService(cryptoService, userService, apiService, settingsService); @@ -13,7 +14,6 @@ var folderService = new FolderService(cryptoService, userService, apiService); var syncService = new SyncService(loginService, folderService, userService, apiService, settingsService); var autofillService = new AutofillService(); var passwordGenerationService = new PasswordGenerationService(); -var appIdService = new AppIdService(); chrome.commands.onCommand.addListener(function (command) { if (command === 'generate_password') { diff --git a/src/services/apiService.js b/src/services/apiService.js index 147809d1fe..34ff59e67d 100644 --- a/src/services/apiService.js +++ b/src/services/apiService.js @@ -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()) {