mirror of
https://github.com/bitwarden/browser
synced 2025-12-28 22:23:28 +00:00
[Account Switching] [Feature] Add the ability to maintain state for up to 5 accounts at once (#1079)
* [refactor] Remove references to deprecated services * [feature] Implement account switching * [bug] Fix state handling for authentication dependent system menu items * [bug] Enable the account switcher to fucntion properly when switching to a locked accounts * [feature] Enable locking any account from the menu * [bug] Ensure the avatar instance used in the account switcher updates on account change * [style] Fix lint complaints * [bug] Ensure the logout command callback can handle any user in state * [style] Fix lint complaints * rollup * [style] Fix lint complaints * [bug] Don't clean up state until everything else is done on logout * [bug] Navigate to vault on a succesful account switch * [bug] Init the state service on start * [feature] Limit account switching to 5 account maximum * [bug] Resolve app lock state with 5 logged out accounts * [chore] Update account refrences to match recent jslib restructuring * [bug] Add missing awaits * [bug] Update app menu on logout * [bug] Hide the switcher if there are no authed accounts * [bug] Move authenticationStatus display information out of jslib * [bug] Remove unused active style from scss * [refactor] Rewrite the menu bar * [style] Fix lint complaints * [bug] Clean state of loggout out user after redirect * [bug] Redirect on logout if not explicity provided a userId that isn't active * [bug] Relocated several settings items to persistant storage * [bug] Correct account switcher styles on all themes * [chore] Include state migration service in services * [bug] Swap to next account on logout * [bug] Correct DI service * [bug] fix loginGuard deps in services.module * [chore] update jslib * [bug] Remove badly merged scss * [chore] update jslib * [review] Code review cleanup * [review] Code review cleanup Co-authored-by: Hinton <oscar@oscarhinton.com>
This commit is contained in:
25
src/services/loginGuard.service.ts
Normal file
25
src/services/loginGuard.service.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CanActivate } from '@angular/router';
|
||||
|
||||
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
||||
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
|
||||
import { StateService } from 'jslib-common/abstractions/state.service';
|
||||
|
||||
const maxAllowedAccounts = 5;
|
||||
|
||||
@Injectable()
|
||||
export class LoginGuardService implements CanActivate {
|
||||
protected homepage = 'vault';
|
||||
constructor(private stateService: StateService, private platformUtilsService: PlatformUtilsService,
|
||||
private i18nService: I18nService) { }
|
||||
|
||||
async canActivate() {
|
||||
const accounts = this.stateService.accounts.getValue();
|
||||
if (accounts != null && Object.keys(accounts).length >= maxAllowedAccounts) {
|
||||
this.platformUtilsService.showToast('error', null, this.i18nService.t('accountLimitReached'));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,14 @@ import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
||||
import { LogService } from 'jslib-common/abstractions/log.service';
|
||||
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
|
||||
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
|
||||
import { StorageService } from 'jslib-common/abstractions/storage.service';
|
||||
import { UserService } from 'jslib-common/abstractions/user.service';
|
||||
import { StateService } from 'jslib-common/abstractions/state.service';
|
||||
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
|
||||
|
||||
import { Utils } from 'jslib-common/misc/utils';
|
||||
|
||||
import { SymmetricCryptoKey } from 'jslib-common/models/domain/symmetricCryptoKey';
|
||||
import { ElectronConstants } from 'jslib-electron/electronConstants';
|
||||
|
||||
import { KeySuffixOptions } from 'jslib-common/enums/keySuffixOptions';
|
||||
|
||||
const MessageValidTimeout = 10 * 1000;
|
||||
const EncryptionAlgorithm = 'sha1';
|
||||
@@ -25,9 +26,9 @@ export class NativeMessagingService {
|
||||
|
||||
constructor(private cryptoFunctionService: CryptoFunctionService, private cryptoService: CryptoService,
|
||||
private platformUtilService: PlatformUtilsService, private logService: LogService,
|
||||
private i18nService: I18nService, private userService: UserService, private messagingService: MessagingService,
|
||||
private vaultTimeoutService: VaultTimeoutService, private storageService: StorageService) {
|
||||
ipcRenderer.on('nativeMessaging', async (event: any, message: any) => {
|
||||
private i18nService: I18nService, private messagingService: MessagingService,
|
||||
private vaultTimeoutService: VaultTimeoutService, private stateService: StateService) {
|
||||
ipcRenderer.on('nativeMessaging', async (_event: any, message: any) => {
|
||||
this.messageHandler(message);
|
||||
});
|
||||
}
|
||||
@@ -41,15 +42,15 @@ export class NativeMessagingService {
|
||||
const remotePublicKey = Utils.fromB64ToArray(rawMessage.publicKey).buffer;
|
||||
|
||||
// Valudate the UserId to ensure we are logged into the same account.
|
||||
if (rawMessage.userId !== await this.userService.getUserId()) {
|
||||
if (rawMessage.userId !== await this.stateService.getUserId()) {
|
||||
ipcRenderer.send('nativeMessagingReply', {command: 'wrongUserId', appId: appId});
|
||||
return;
|
||||
}
|
||||
|
||||
if (await this.storageService.get<boolean>(ElectronConstants.enableBrowserIntegrationFingerprint)) {
|
||||
if (await this.stateService.getEnableBrowserIntegrationFingerprint()) {
|
||||
ipcRenderer.send('nativeMessagingReply', {command: 'verifyFingerprint', appId: appId});
|
||||
|
||||
const fingerprint = (await this.cryptoService.getFingerprint(await this.userService.getUserId(), remotePublicKey)).join(' ');
|
||||
const fingerprint = (await this.cryptoService.getFingerprint(await this.stateService.getUserId(), remotePublicKey)).join(' ');
|
||||
|
||||
this.messagingService.send('setFocus');
|
||||
|
||||
@@ -104,7 +105,7 @@ export class NativeMessagingService {
|
||||
});
|
||||
}
|
||||
|
||||
const keyB64 = await (await this.cryptoService.getKeyFromStorage('biometric')).keyB64;
|
||||
const keyB64 = (await this.cryptoService.getKeyFromStorage(KeySuffixOptions.Biometric)).keyB64;
|
||||
|
||||
if (keyB64 != null) {
|
||||
this.send({ command: 'biometricUnlock', response: 'unlocked', keyB64: keyB64 }, appId);
|
||||
|
||||
Reference in New Issue
Block a user