1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-08 04:33:38 +00:00

PM-20532 - WIP on SendAccessTokenRequest + various enum creation & updates

This commit is contained in:
Jared Snider
2025-05-17 12:13:06 -04:00
parent 9a02f03592
commit 5218ddf8eb
5 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
export const GrantTypes = {
SendAccess: "send_access",
// TODO: migrate other grant types to this object
};
export type GrantType = (typeof GrantTypes)[keyof typeof GrantTypes];

View File

@@ -0,0 +1,6 @@
export const Scopes = {
Send: "api.send",
// TODO: migrate other scopes to this object
};
export type Scope = (typeof Scopes)[keyof typeof Scopes];

View File

@@ -0,0 +1,43 @@
import { ClientType } from "../../../../enums";
import { GrantTypes } from "../../../enums/grant-type.enum";
import { Scopes } from "../../../enums/scopes.enum";
import { DeviceRequest } from "./device.request";
import { TokenRequest } from "./token.request";
export class SendAccessTokenRequest extends TokenRequest {
constructor(
public sendId: string,
public device: DeviceRequest,
public password?: string,
public email?: string,
public oneTimePassword?: string,
) {
super(undefined, device);
}
toIdentityToken(clientId: ClientType) {
// Super call handles setting up client id and device properties
const obj = super.toIdentityToken(clientId);
obj.grant_type = GrantTypes.SendAccess;
// override base scopes
obj.scope = [Scopes.Send].join(" ");
// Add required and optional properties
obj.sendId = this.sendId;
if (this.password) {
obj.password = this.password;
}
if (this.email && this.oneTimePassword) {
obj.email = this.email;
obj.oneTimePassword = this.oneTimePassword;
}
return obj;
}
}

View File

@@ -0,0 +1,3 @@
export abstract class SendTokenApiService {
// requestSendAccessToken: () => Promise<>;
}

View File

@@ -7,4 +7,5 @@ export enum ClientType {
// Mobile = "mobile",
Cli = "cli",
// DirectoryConnector = "connector",
Send = "send",
}