1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

feat(auth): [PM-9723] Refresh LoginViaAuthRequestComponent (#11545)

Creates a refreshed and consolidated LoginViaAuthRequestComponent for use on all visual clients, which will be used when the UnauthenticatedExtensionUIRefresh feature flag is on.
This commit is contained in:
rr-bw
2024-11-19 14:53:01 -08:00
committed by GitHub
parent 2df8643e29
commit 9429ae1d06
32 changed files with 1025 additions and 69 deletions

View File

@@ -0,0 +1,37 @@
import { AuthRequest } from "@bitwarden/common/auth/models/request/auth.request";
import { AuthRequestResponse } from "@bitwarden/common/auth/models/response/auth-request.response";
export abstract class AuthRequestApiService {
/**
* Gets an auth request by its ID.
*
* @param requestId The ID of the auth request.
* @returns A promise that resolves to the auth request response.
*/
abstract getAuthRequest: (requestId: string) => Promise<AuthRequestResponse>;
/**
* Gets an auth request response by its ID and access code.
*
* @param requestId The ID of the auth request.
* @param accessCode The access code of the auth request.
* @returns A promise that resolves to the auth request response.
*/
abstract getAuthResponse: (requestId: string, accessCode: string) => Promise<AuthRequestResponse>;
/**
* Sends an admin auth request.
*
* @param request The auth request object.
* @returns A promise that resolves to the auth request response.
*/
abstract postAdminAuthRequest: (request: AuthRequest) => Promise<AuthRequestResponse>;
/**
* Sends an auth request.
*
* @param request The auth request object.
* @returns A promise that resolves to the auth request response.
*/
abstract postAuthRequest: (request: AuthRequest) => Promise<AuthRequestResponse>;
}

View File

@@ -1,3 +1,4 @@
export * from "./auth-request-api.service";
export * from "./pin.service.abstraction";
export * from "./login-email.service";
export * from "./login-strategy.service";

View File

@@ -0,0 +1,65 @@
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { AuthRequest } from "@bitwarden/common/auth/models/request/auth.request";
import { AuthRequestResponse } from "@bitwarden/common/auth/models/response/auth-request.response";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { AuthRequestApiService } from "../../abstractions/auth-request-api.service";
export class DefaultAuthRequestApiService implements AuthRequestApiService {
constructor(
private apiService: ApiService,
private logService: LogService,
) {}
async getAuthRequest(requestId: string): Promise<AuthRequestResponse> {
try {
const path = `/auth-requests/${requestId}`;
const response = await this.apiService.send("GET", path, null, true, true);
return response;
} catch (e: unknown) {
this.logService.error(e);
throw e;
}
}
async getAuthResponse(requestId: string, accessCode: string): Promise<AuthRequestResponse> {
try {
const path = `/auth-requests/${requestId}/response?code=${accessCode}`;
const response = await this.apiService.send("GET", path, null, false, true);
return response;
} catch (e: unknown) {
this.logService.error(e);
throw e;
}
}
async postAdminAuthRequest(request: AuthRequest): Promise<AuthRequestResponse> {
try {
const response = await this.apiService.send(
"POST",
"/auth-requests/admin-request",
request,
true,
true,
);
return response;
} catch (e: unknown) {
this.logService.error(e);
throw e;
}
}
async postAuthRequest(request: AuthRequest): Promise<AuthRequestResponse> {
try {
const response = await this.apiService.send("POST", "/auth-requests/", request, false, true);
return response;
} catch (e: unknown) {
this.logService.error(e);
throw e;
}
}
}

View File

@@ -3,5 +3,6 @@ export * from "./login-email/login-email.service";
export * from "./login-strategies/login-strategy.service";
export * from "./user-decryption-options/user-decryption-options.service";
export * from "./auth-request/auth-request.service";
export * from "./auth-request/auth-request-api.service";
export * from "./register-route.service";
export * from "./accounts/lock.service";