Auth/pm 14943/auth request extension dialog approve (#16132)
* feat(notification-processing): [PM-19877] System Notification Implementation - Implemented the full feature set for device approval from extension. * test(notification-processing): [PM-19877] System Notification Implementation - Updated tests. --------- Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>pull/16264/head^2
parent
493788c9d0
commit
fe692acc07
@ -0,0 +1,10 @@
|
||||
# Auth Request Answering Service
|
||||
|
||||
This feature is to allow for the taking of auth requests that are received via websockets by the background service to
|
||||
be acted on when the user loads up a client. Currently only implemented with the browser client.
|
||||
|
||||
See diagram for the high level picture of how this is wired up.
|
||||
|
||||
## Diagram
|
||||
|
||||

|
||||
|
After Width: | Height: | Size: 670 KiB |
@ -0,0 +1,57 @@
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
import {
|
||||
AUTH_REQUEST_DISK_LOCAL,
|
||||
GlobalState,
|
||||
KeyDefinition,
|
||||
StateProvider,
|
||||
} from "@bitwarden/common/platform/state";
|
||||
import { UserId } from "@bitwarden/user-core";
|
||||
|
||||
export type PendingAuthUserMarker = {
|
||||
userId: UserId;
|
||||
receivedAtMs: number;
|
||||
};
|
||||
|
||||
export const PENDING_AUTH_REQUESTS = KeyDefinition.array<PendingAuthUserMarker>(
|
||||
AUTH_REQUEST_DISK_LOCAL,
|
||||
"pendingAuthRequests",
|
||||
{
|
||||
deserializer: (json) => json,
|
||||
},
|
||||
);
|
||||
|
||||
export class PendingAuthRequestsStateService {
|
||||
private readonly state: GlobalState<PendingAuthUserMarker[]>;
|
||||
|
||||
constructor(private readonly stateProvider: StateProvider) {
|
||||
this.state = this.stateProvider.getGlobal(PENDING_AUTH_REQUESTS);
|
||||
}
|
||||
|
||||
getAll$(): Observable<PendingAuthUserMarker[] | null> {
|
||||
return this.state.state$;
|
||||
}
|
||||
|
||||
async add(userId: UserId): Promise<void> {
|
||||
const now = Date.now();
|
||||
await this.stateProvider.getGlobal(PENDING_AUTH_REQUESTS).update((current) => {
|
||||
const list = (current ?? []).filter((e) => e.userId !== userId);
|
||||
return [...list, { userId, receivedAtMs: now }];
|
||||
});
|
||||
}
|
||||
|
||||
async pruneOlderThan(maxAgeMs: number): Promise<void> {
|
||||
const cutoff = Date.now() - maxAgeMs;
|
||||
await this.stateProvider.getGlobal(PENDING_AUTH_REQUESTS).update((current) => {
|
||||
const list = current ?? [];
|
||||
return list.filter((e) => e.receivedAtMs >= cutoff);
|
||||
});
|
||||
}
|
||||
|
||||
async clear(userId: UserId): Promise<void> {
|
||||
await this.stateProvider.getGlobal(PENDING_AUTH_REQUESTS).update((current) => {
|
||||
const list = current ?? [];
|
||||
return list.filter((e) => e.userId !== userId);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue