mirror of
https://github.com/bitwarden/browser
synced 2026-02-08 04:33:38 +00:00
PM-20532 - WIP
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { ClientType } from "../../../../enums";
|
||||
import { GrantType, GrantTypes } from "../../../enums/grant-type.enum";
|
||||
import { Scope, Scopes } from "../../../enums/scopes.enum";
|
||||
import { SendAccessCredentials } from "../../../send-access/abstractions/send-token.service";
|
||||
|
||||
export type SendAccessTokenPasswordPayload = { password: string };
|
||||
export type SendAccessTokenEmailOtpPayload = { email: string; otp: string };
|
||||
@@ -28,11 +29,7 @@ export class SendAccessTokenRequest {
|
||||
|
||||
constructor(
|
||||
public sendId: string,
|
||||
|
||||
public password?: string,
|
||||
|
||||
public email?: string,
|
||||
public otp?: string,
|
||||
public sendAccessCredentials?: SendAccessCredentials,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -47,10 +44,14 @@ export class SendAccessTokenRequest {
|
||||
send_id: this.sendId,
|
||||
};
|
||||
|
||||
if (this.password) {
|
||||
return { ...base, password: this.password };
|
||||
} else if (this.email && this.otp) {
|
||||
return { ...base, email: this.email, otp: this.otp };
|
||||
if (this.sendAccessCredentials && this.sendAccessCredentials.type === "password") {
|
||||
return { ...base, password: this.sendAccessCredentials.password };
|
||||
} else if (this.sendAccessCredentials && this.sendAccessCredentials.type === "email-otp") {
|
||||
return {
|
||||
...base,
|
||||
email: this.sendAccessCredentials.email,
|
||||
otp: this.sendAccessCredentials.otp,
|
||||
};
|
||||
} else {
|
||||
return base;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
export interface SendPasswordCredentials {
|
||||
export type SendAccessCredentialsType = "password" | "email-otp";
|
||||
|
||||
export type SendPasswordCredentials = {
|
||||
type: "password";
|
||||
password: string;
|
||||
}
|
||||
export interface SendEmailOtpCredentials {
|
||||
};
|
||||
export type SendEmailOtpCredentials = {
|
||||
type: "email-otp";
|
||||
email: string;
|
||||
otp: string;
|
||||
}
|
||||
};
|
||||
export type SendAccessCredentials = SendPasswordCredentials | SendEmailOtpCredentials;
|
||||
|
||||
export abstract class SendTokenService {
|
||||
// TODO: talk with Tools about what expected behavior is for expired access tokens.
|
||||
// Do we implement any local TTL or do we just rely on the server to return a 401 and then we handle that in the api service?
|
||||
|
||||
// SendAccessTokens need to be stored in session storage once retrieved.
|
||||
// All SendAccessTokens are scoped to a specific send id so all getting and setting should accept a send id.
|
||||
|
||||
@@ -23,14 +24,12 @@ export abstract class SendTokenService {
|
||||
|
||||
// Returned error types should be discriminated union with a type that can be conditioned off for logic.
|
||||
|
||||
// Attempts to get a send access token for a specific send id.
|
||||
// If the token is not found or is expired, it will request a new token from the server.
|
||||
// As send access tokens can be protected by different credentials, the credentials must be passed in for those sends.
|
||||
abstract getSendAccessToken: (
|
||||
sendId: string,
|
||||
sendCredentials?: SendAccessCredentials,
|
||||
) => Promise<void>;
|
||||
// TODO: define return types.
|
||||
// TODO: consider converting to observable.
|
||||
abstract tryGetSendAccessToken: (sendId: string) => Promise<void>;
|
||||
|
||||
// Private internal logic for getting the access token.
|
||||
// abstract setSendAccessToken: (sendId: string, token: string) => Promise<void>;
|
||||
abstract getSendAccessTokenWithCredentials: (
|
||||
sendId: string,
|
||||
sendAccessCredentials: SendAccessCredentials,
|
||||
) => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { GlobalStateProvider, KeyDefinition, SEND_ACCESS_DISK } from "../../../platform/state";
|
||||
// import { SendAccessTokenRequest } from "../../models/request/identity-token/send-access-token.request";
|
||||
import {
|
||||
SendAccessCredentials,
|
||||
SendTokenService as SendTokenServiceAbstraction,
|
||||
} from "../abstractions/send-token.service";
|
||||
import { SendAccessToken } from "../models/send-access-token";
|
||||
|
||||
import { SendTokenApiService } from "./send-token-api.service";
|
||||
|
||||
// Will need to map sendId to access token
|
||||
// TODO: will need to build a better type for access token where it contains
|
||||
// the expires in and the token itself.
|
||||
export const SEND_ACCESS_TOKEN_DICT = KeyDefinition.record<string, string>(
|
||||
export const SEND_ACCESS_TOKEN_DICT = KeyDefinition.record<SendAccessToken, string>(
|
||||
SEND_ACCESS_DISK,
|
||||
"accessTokenDict",
|
||||
{
|
||||
@@ -23,9 +25,14 @@ export class SendTokenService implements SendTokenServiceAbstraction {
|
||||
private sendTokenApiService: SendTokenApiService,
|
||||
) {}
|
||||
|
||||
async getSendAccessToken(sendId: string, sendCredentials?: SendAccessCredentials): Promise<void> {
|
||||
async getSendAccessToken(
|
||||
sendId: string,
|
||||
sendCredentials: SendAccessCredentials | undefined,
|
||||
): Promise<void> {
|
||||
// TODO: check in storage for the access token and if it is expired.
|
||||
// If it is expired, we will need to request a new token from the server.
|
||||
// If it is not expired, we will return the token from storage.
|
||||
// const request = new SendAccessTokenRequest(sendId, sendCredentials);
|
||||
// const result = await this.sendTokenApiService.requestSendAccessToken(request);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user