Skip to content

Commit

Permalink
PM-5263 - Clear all tokens on logout (#8536)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredSnider-Bitwarden authored and jlf0dev committed Mar 28, 2024
1 parent a1e6fb0 commit ea3f9a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions libs/common/src/auth/services/token.state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { KeyDefinition, TOKEN_DISK, TOKEN_DISK_LOCAL, TOKEN_MEMORY } from "../../platform/state";

// Note: all tokens / API key information must be cleared on logout.
// because we are using secure storage, we must manually call to clean up our tokens.
// See stateService.deAuthenticateAccount for where we call clearTokens(...)

export const ACCESS_TOKEN_DISK = new KeyDefinition<string>(TOKEN_DISK, "accessToken", {
deserializer: (accessToken) => accessToken,
});
Expand Down
4 changes: 3 additions & 1 deletion libs/common/src/platform/services/state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,9 @@ export class StateService<
}

protected async deAuthenticateAccount(userId: string): Promise<void> {
await this.tokenService.clearAccessToken(userId as UserId);
// We must have a manual call to clear tokens as we can't leverage state provider to clean
// up our data as we have secure storage in the mix.
await this.tokenService.clearTokens(userId as UserId);
await this.setLastActive(null, { userId: userId });
await this.updateState(async (state) => {
state.authenticatedAccounts = state.authenticatedAccounts.filter((id) => id !== userId);
Expand Down

0 comments on commit ea3f9a6

Please sign in to comment.