Added device registration information during authentication
This commit is contained in:
parent
5a20f9de01
commit
4be033df71
|
@ -16,10 +16,10 @@ var TokenRequest = function (email, masterPasswordHash, token, device) {
|
|||
this.email = email;
|
||||
this.masterPasswordHash = masterPasswordHash;
|
||||
this.token = token;
|
||||
this.provider = 'Authenticator';
|
||||
this.provider = 0; // authenticator
|
||||
this.device = null;
|
||||
if (device) {
|
||||
this.device = new DeviceRequest(device);
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
this.toIdentityToken = function () {
|
||||
|
@ -62,9 +62,9 @@ var DeviceTokenRequest = function () {
|
|||
this.pushToken = null;
|
||||
};
|
||||
|
||||
var DeviceRequest = function () {
|
||||
this.type = null;
|
||||
this.name = null;
|
||||
this.identifier = null;
|
||||
var DeviceRequest = function (appId, utilsService) {
|
||||
this.type = utilsService.getDeviceType();
|
||||
this.name = utilsService.getBrowser();
|
||||
this.identifier = appId;
|
||||
this.pushToken = null;
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
.module('bit.services')
|
||||
|
||||
.factory('authService', function (cryptoService, apiService, userService, tokenService, $q, $rootScope, loginService,
|
||||
folderService, settingsService, syncService) {
|
||||
folderService, settingsService, syncService, appIdService, utilsService) {
|
||||
var _service = {};
|
||||
|
||||
_service.logIn = function (email, masterPassword, twoFactorToken) {
|
||||
|
@ -10,30 +10,33 @@
|
|||
var key = cryptoService.makeKey(masterPassword, email);
|
||||
var deferred = $q.defer();
|
||||
cryptoService.hashPassword(masterPassword, key, function (hashedPassword) {
|
||||
var request = new TokenRequest(email, hashedPassword, twoFactorToken);
|
||||
appIdService.getAppId(function (appId) {
|
||||
var deviceRequest = new DeviceRequest(appId, utilsService);
|
||||
var request = new TokenRequest(email, hashedPassword, twoFactorToken, deviceRequest);
|
||||
|
||||
apiService.postIdentityToken(request, function (response) {
|
||||
// success
|
||||
if (!response || !response.accessToken) {
|
||||
return;
|
||||
}
|
||||
apiService.postIdentityToken(request, function (response) {
|
||||
// success
|
||||
if (!response || !response.accessToken) {
|
||||
return;
|
||||
}
|
||||
|
||||
tokenService.setTokens(response.accessToken, response.refreshToken, function () {
|
||||
cryptoService.setKey(key, function () {
|
||||
cryptoService.setKeyHash(hashedPassword, function () {
|
||||
userService.setUserIdAndEmail(tokenService.getUserId(), tokenService.getEmail(), function () {
|
||||
chrome.runtime.sendMessage({ command: 'loggedIn' });
|
||||
deferred.resolve(false);
|
||||
tokenService.setTokens(response.accessToken, response.refreshToken, function () {
|
||||
cryptoService.setKey(key, function () {
|
||||
cryptoService.setKeyHash(hashedPassword, function () {
|
||||
userService.setUserIdAndEmail(tokenService.getUserId(), tokenService.getEmail(), function () {
|
||||
chrome.runtime.sendMessage({ command: 'loggedIn' });
|
||||
deferred.resolve(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}, function () {
|
||||
// two factor required
|
||||
deferred.resolve(true);
|
||||
}, function (error) {
|
||||
// error
|
||||
deferred.reject(error);
|
||||
});
|
||||
}, function () {
|
||||
// two factor required
|
||||
deferred.resolve(true);
|
||||
}, function (error) {
|
||||
// error
|
||||
deferred.reject(error);
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
|
|
|
@ -64,6 +64,23 @@ function initUtilsService() {
|
|||
return this.analyticsIdCache;
|
||||
}
|
||||
|
||||
UtilsService.prototype.getDeviceType = function () {
|
||||
if (this.isChrome()) {
|
||||
return 2;
|
||||
}
|
||||
else if (this.isFirefox()) {
|
||||
return 3;
|
||||
}
|
||||
else if (this.isEdge()) {
|
||||
return 5;
|
||||
}
|
||||
else if (this.isOpera()) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
UtilsService.prototype.initListSectionItemListeners = function (doc, angular) {
|
||||
if (!doc) {
|
||||
throw 'doc parameter required';
|
||||
|
|
Loading…
Reference in New Issue