mirror of
https://github.com/bitwarden/browser
synced 2026-02-10 05:30:01 +00:00
Add request models and api service
This commit is contained in:
55
libs/common/src/auth/opaque/default-opaque-api.service.ts
Normal file
55
libs/common/src/auth/opaque/default-opaque-api.service.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||
|
||||
import { OpaqueSessionId } from "../../types/guid";
|
||||
|
||||
import { RegistrationFinishRequest } from "./models/registration-finish.request";
|
||||
import { RegistrationFinishResponse } from "./models/registration-finish.response";
|
||||
import { RegistrationStartRequest } from "./models/registration-start.request";
|
||||
import { RegistrationStartResponse } from "./models/registration-start.response";
|
||||
import { OpaqueApiService } from "./opaque-api.service";
|
||||
|
||||
export class DefaultOpaqueApiService implements OpaqueApiService {
|
||||
constructor(
|
||||
private apiService: ApiService,
|
||||
private environmentService: EnvironmentService,
|
||||
) {}
|
||||
|
||||
async RegistrationStart(request: RegistrationStartRequest): Promise<RegistrationStartResponse> {
|
||||
const env = await firstValueFrom(this.environmentService.environment$);
|
||||
const response = await this.apiService.send(
|
||||
"POST",
|
||||
`/opaque/registration-start`,
|
||||
request,
|
||||
false,
|
||||
true,
|
||||
env.getApiUrl(),
|
||||
);
|
||||
return new RegistrationStartResponse(response);
|
||||
}
|
||||
|
||||
async RegistrationFinish(
|
||||
credentialId: OpaqueSessionId,
|
||||
request: RegistrationFinishRequest,
|
||||
): Promise<RegistrationFinishResponse> {
|
||||
const env = await firstValueFrom(this.environmentService.environment$);
|
||||
const response = await this.apiService.send(
|
||||
"POST",
|
||||
`/opaque/${credentialId}registration-start`,
|
||||
request,
|
||||
false,
|
||||
true,
|
||||
env.getApiUrl(),
|
||||
);
|
||||
return new RegistrationFinishResponse(response);
|
||||
}
|
||||
|
||||
LoginStart(): any {
|
||||
throw new Error("Method not implemented");
|
||||
}
|
||||
LoginFinish(): any {
|
||||
throw new Error("Method not implemented");
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ export class DefaultOpaqueService implements OpaqueService {
|
||||
);
|
||||
|
||||
await this.opaqueApiService.RegistrationFinish(
|
||||
registrationStartResponse.credentialId,
|
||||
registrationStartResponse.sessionId,
|
||||
new RegistrationFinishRequest(
|
||||
Utils.fromBufferToB64(new Uint8Array(registrationFinish.registration_finish_message)),
|
||||
keyset,
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { OpaqueSessionId } from "@bitwarden/common/types/guid";
|
||||
|
||||
export class LoginFinishRequest {
|
||||
constructor(
|
||||
readonly loginSessionId: OpaqueSessionId,
|
||||
readonly clientLoginFinishResult: string,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export class LoginStartRequest {
|
||||
constructor(
|
||||
readonly email: string,
|
||||
readonly clientLoginStartRequest: string,
|
||||
) {}
|
||||
}
|
||||
12
libs/common/src/auth/opaque/models/login-start.response.ts
Normal file
12
libs/common/src/auth/opaque/models/login-start.response.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { BaseResponse } from "../../../models/response/base.response";
|
||||
|
||||
export class LoginStartResponse extends BaseResponse {
|
||||
loginSessionId: string;
|
||||
serverLoginStartResult: string;
|
||||
|
||||
constructor(response: any) {
|
||||
super(response);
|
||||
this.loginSessionId = this.getResponseProperty("LoginSessionId");
|
||||
this.serverLoginStartResult = this.getResponseProperty("ServerRegistrationStartResult");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { BaseResponse } from "@bitwarden/common/models/response/base.response";
|
||||
|
||||
export class RegistrationFinishResponse extends BaseResponse {
|
||||
constructor(response: any) {
|
||||
super(response);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
import { BaseResponse } from "../../../models/response/base.response";
|
||||
import { OpaqueCredentialId } from "../../../types/guid";
|
||||
import { OpaqueSessionId } from "../../../types/guid";
|
||||
|
||||
export class RegistrationStartResponse extends BaseResponse {
|
||||
credentialId: OpaqueCredentialId;
|
||||
sessionId: OpaqueSessionId;
|
||||
serverRegistrationStartResult: string;
|
||||
|
||||
constructor(response: any) {
|
||||
super(response);
|
||||
|
||||
this.credentialId = this.getResponseProperty("CredentialId");
|
||||
this.sessionId = this.getResponseProperty("SessionId");
|
||||
this.serverRegistrationStartResult = this.getResponseProperty("ServerRegistrationStartResult");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { OpaqueCredentialId } from "../../types/guid";
|
||||
import { OpaqueSessionId as OpaqueSessionId } from "../../types/guid";
|
||||
|
||||
import { RegistrationFinishRequest } from "./models/registration-finish.request";
|
||||
import { RegistrationFinishResponse } from "./models/registration-finish.response";
|
||||
import { RegistrationStartRequest } from "./models/registration-start.request";
|
||||
import { RegistrationStartResponse } from "./models/registration-start.response";
|
||||
|
||||
export abstract class OpaqueApiService {
|
||||
abstract RegistrationStart(request: RegistrationStartRequest): Promise<RegistrationStartResponse>;
|
||||
abstract RegistrationFinish(
|
||||
credentialId: OpaqueCredentialId,
|
||||
sessionId: OpaqueSessionId,
|
||||
request: RegistrationFinishRequest,
|
||||
): Promise<void>;
|
||||
): Promise<RegistrationFinishResponse>;
|
||||
abstract LoginStart(): any;
|
||||
abstract LoginFinish(): any;
|
||||
}
|
||||
|
||||
@@ -11,4 +11,4 @@ export type CipherId = Opaque<string, "CipherId">;
|
||||
export type SendId = Opaque<string, "SendId">;
|
||||
export type IndexedEntityId = Opaque<string, "IndexedEntityId">;
|
||||
export type SecurityTaskId = Opaque<string, "SecurityTaskId">;
|
||||
export type OpaqueCredentialId = Opaque<string, "OpaqueCredentialId">;
|
||||
export type OpaqueSessionId = Opaque<string, "OpaqueSessionId">;
|
||||
|
||||
Reference in New Issue
Block a user