mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-06 09:20:43 +01:00
logout command
This commit is contained in:
parent
33effb1a4d
commit
6fff69c0ea
26
src/bw.ts
26
src/bw.ts
@ -2,9 +2,9 @@ import { AuthService } from 'jslib/services/auth.service';
|
|||||||
|
|
||||||
import { I18nService } from './services/i18n.service';
|
import { I18nService } from './services/i18n.service';
|
||||||
import { NodeEnvSecureStorageService } from './services/nodeEnvSecureStorage.service';
|
import { NodeEnvSecureStorageService } from './services/nodeEnvSecureStorage.service';
|
||||||
import { NodeMessagingService } from './services/nodeMessaging.service';
|
|
||||||
import { NodePlatformUtilsService } from './services/nodePlatformUtils.service';
|
import { NodePlatformUtilsService } from './services/nodePlatformUtils.service';
|
||||||
import { NodeStorageService } from './services/nodeStorage.service';
|
import { NodeStorageService } from './services/nodeStorage.service';
|
||||||
|
import { NoopMessagingService } from './services/noopMessaging.service';
|
||||||
|
|
||||||
import { AppIdService } from 'jslib/services/appId.service';
|
import { AppIdService } from 'jslib/services/appId.service';
|
||||||
import { AuditService } from 'jslib/services/audit.service';
|
import { AuditService } from 'jslib/services/audit.service';
|
||||||
@ -28,7 +28,7 @@ import { UserService } from 'jslib/services/user.service';
|
|||||||
import { Program } from './program';
|
import { Program } from './program';
|
||||||
|
|
||||||
export class Main {
|
export class Main {
|
||||||
messagingService: NodeMessagingService;
|
messagingService: NoopMessagingService;
|
||||||
storageService: NodeStorageService;
|
storageService: NodeStorageService;
|
||||||
secureStorageService: NodeStorageService;
|
secureStorageService: NodeStorageService;
|
||||||
i18nService: I18nService;
|
i18nService: I18nService;
|
||||||
@ -64,9 +64,9 @@ export class Main {
|
|||||||
this.cryptoFunctionService);
|
this.cryptoFunctionService);
|
||||||
this.appIdService = new AppIdService(this.storageService);
|
this.appIdService = new AppIdService(this.storageService);
|
||||||
this.tokenService = new TokenService(this.storageService);
|
this.tokenService = new TokenService(this.storageService);
|
||||||
this.messagingService = new NodeMessagingService();
|
this.messagingService = new NoopMessagingService();
|
||||||
this.apiService = new NodeApiService(this.tokenService, this.platformUtilsService,
|
this.apiService = new NodeApiService(this.tokenService, this.platformUtilsService,
|
||||||
(expired: boolean) => { /* do nothing */ });
|
(expired: boolean) => { this.logout(); });
|
||||||
this.environmentService = new EnvironmentService(this.apiService, this.storageService);
|
this.environmentService = new EnvironmentService(this.apiService, this.storageService);
|
||||||
this.userService = new UserService(this.tokenService, this.storageService);
|
this.userService = new UserService(this.tokenService, this.storageService);
|
||||||
this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService);
|
this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService);
|
||||||
@ -82,7 +82,7 @@ export class Main {
|
|||||||
() => { /* do nothing */ });
|
() => { /* do nothing */ });
|
||||||
this.syncService = new SyncService(this.userService, this.apiService, this.settingsService,
|
this.syncService = new SyncService(this.userService, this.apiService, this.settingsService,
|
||||||
this.folderService, this.cipherService, this.cryptoService, this.collectionService,
|
this.folderService, this.cipherService, this.cryptoService, this.collectionService,
|
||||||
this.storageService, this.messagingService, (expired: boolean) => { /* do nothing */ });
|
this.storageService, this.messagingService, (expired: boolean) => { this.logout(); });
|
||||||
this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.storageService);
|
this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.storageService);
|
||||||
this.totpService = new TotpService(this.storageService, this.cryptoFunctionService);
|
this.totpService = new TotpService(this.storageService, this.cryptoFunctionService);
|
||||||
this.authService = new AuthService(this.cryptoService, this.apiService, this.userService, this.tokenService,
|
this.authService = new AuthService(this.cryptoService, this.apiService, this.userService, this.tokenService,
|
||||||
@ -95,6 +95,22 @@ export class Main {
|
|||||||
this.program.run();
|
this.program.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async logout() {
|
||||||
|
process.env.BW_SESSION = null;
|
||||||
|
const userId = await this.userService.getUserId();
|
||||||
|
await Promise.all([
|
||||||
|
this.syncService.setLastSync(new Date(0)),
|
||||||
|
this.tokenService.clearToken(),
|
||||||
|
this.cryptoService.clearKeys(),
|
||||||
|
this.userService.clear(),
|
||||||
|
this.settingsService.clear(userId),
|
||||||
|
this.cipherService.clear(userId),
|
||||||
|
this.folderService.clear(userId),
|
||||||
|
this.collectionService.clear(userId),
|
||||||
|
this.passwordGenerationService.clear(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
private async init() {
|
private async init() {
|
||||||
this.containerService.attachToWindow(global);
|
this.containerService.attachToWindow(global);
|
||||||
await this.environmentService.setUrlsFromStorage();
|
await this.environmentService.setUrlsFromStorage();
|
||||||
|
17
src/commands/logout.command.ts
Normal file
17
src/commands/logout.command.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import * as program from 'commander';
|
||||||
|
|
||||||
|
import { AuthService } from 'jslib/abstractions/auth.service';
|
||||||
|
|
||||||
|
import { Response } from '../models/response';
|
||||||
|
import { MessageResponse } from '../models/response/messageResponse';
|
||||||
|
|
||||||
|
export class LogoutCommand {
|
||||||
|
constructor(private authService: AuthService, private logoutCallback: () => Promise<void>) { }
|
||||||
|
|
||||||
|
async run(cmd: program.Command) {
|
||||||
|
await this.logoutCallback();
|
||||||
|
this.authService.logOut(() => { /* Do nothing */ });
|
||||||
|
const res = new MessageResponse('You have logged out.', null);
|
||||||
|
return Response.success(res);
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,7 @@ import { EncodeCommand } from './commands/encode.command';
|
|||||||
import { GetCommand } from './commands/get.command';
|
import { GetCommand } from './commands/get.command';
|
||||||
import { ListCommand } from './commands/list.command';
|
import { ListCommand } from './commands/list.command';
|
||||||
import { LoginCommand } from './commands/login.command';
|
import { LoginCommand } from './commands/login.command';
|
||||||
|
import { LogoutCommand } from './commands/logout.command';
|
||||||
import { SyncCommand } from './commands/sync.command';
|
import { SyncCommand } from './commands/sync.command';
|
||||||
|
|
||||||
import { Response } from './models/response';
|
import { Response } from './models/response';
|
||||||
@ -48,7 +49,7 @@ export class Program {
|
|||||||
.option('-m, --method <method>', 'Two-step login method.')
|
.option('-m, --method <method>', 'Two-step login method.')
|
||||||
.option('-c, --code <code>', 'Two-step login code.')
|
.option('-c, --code <code>', 'Two-step login code.')
|
||||||
.action(async (email: string, password: string, cmd: program.Command) => {
|
.action(async (email: string, password: string, cmd: program.Command) => {
|
||||||
// await this.exitIfAuthed();
|
await this.exitIfAuthed();
|
||||||
const command = new LoginCommand(this.main.authService, this.main.apiService,
|
const command = new LoginCommand(this.main.authService, this.main.apiService,
|
||||||
this.main.cryptoFunctionService);
|
this.main.cryptoFunctionService);
|
||||||
const response = await command.run(email, password, cmd);
|
const response = await command.run(email, password, cmd);
|
||||||
@ -60,7 +61,11 @@ export class Program {
|
|||||||
.description('Log out of the current Bitwarden user account.')
|
.description('Log out of the current Bitwarden user account.')
|
||||||
.action(async (cmd) => {
|
.action(async (cmd) => {
|
||||||
await this.exitIfNotAuthed();
|
await this.exitIfNotAuthed();
|
||||||
// TODO
|
const command = new LogoutCommand(this.main.authService, async () => {
|
||||||
|
await this.main.logout();
|
||||||
|
});
|
||||||
|
const response = await command.run(cmd);
|
||||||
|
this.processResponse(response, cmd);
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
||||||
|
|
||||||
export class NodeMessagingService implements MessagingService {
|
export class NoopMessagingService implements MessagingService {
|
||||||
send(subscriber: string, arg: any = {}) {
|
send(subscriber: string, arg: any = {}) {
|
||||||
// TODO
|
// Do nothing...
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user