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:
6
libs/common/src/auth/enums/grant-type.enum.ts
Normal file
6
libs/common/src/auth/enums/grant-type.enum.ts
Normal 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];
|
||||
6
libs/common/src/auth/enums/scopes.enum.ts
Normal file
6
libs/common/src/auth/enums/scopes.enum.ts
Normal 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];
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export abstract class SendTokenApiService {
|
||||
// requestSendAccessToken: () => Promise<>;
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ export enum ClientType {
|
||||
// Mobile = "mobile",
|
||||
Cli = "cli",
|
||||
// DirectoryConnector = "connector",
|
||||
Send = "send",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user