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

@ -5,7 +5,8 @@ var constantsService = new ConstantsService();
var utilsService = new UtilsService(); var utilsService = new UtilsService();
var cryptoService = new CryptoService(constantsService); var cryptoService = new CryptoService(constantsService);
var tokenService = new TokenService(); 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 userService = new UserService(tokenService, apiService, cryptoService);
var settingsService = new SettingsService(userService); var settingsService = new SettingsService(userService);
var loginService = new LoginService(cryptoService, userService, apiService, settingsService); 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 syncService = new SyncService(loginService, folderService, userService, apiService, settingsService);
var autofillService = new AutofillService(); var autofillService = new AutofillService();
var passwordGenerationService = new PasswordGenerationService(); var passwordGenerationService = new PasswordGenerationService();
var appIdService = new AppIdService();
chrome.commands.onCommand.addListener(function (command) { chrome.commands.onCommand.addListener(function (command) {
if (command === 'generate_password') { if (command === 'generate_password') {

View File

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