1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-07-10 12:55:16 +02: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

@ -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') {

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()) {