oauth2flow.ts (1207B)
1 import { Ephemeral } from "#core/domain/ephemeral.ts"; 2 import { OAuth2Flow } from "#core/domain/oauth2flow.ts"; 3 import { Scope } from "#core/domain/scope.ts"; 4 import { Token } from "#core/domain/token.ts"; 5 import { UUID } from "#core/domain/uuid.ts"; 6 7 export type OAuth2FlowDto = { 8 uuid: string; 9 clientId: string; 10 scope: string; 11 state?: string | null; 12 resourceOwner?: string | null; 13 token?: string | null; 14 tokenExpire: Date; 15 version: number; 16 }; 17 18 export function mapFromOAuth2Flow(flow: OAuth2Flow): OAuth2FlowDto { 19 return { 20 uuid: flow.id.toString(), 21 clientId: flow.clientId.toString(), 22 scope: flow.scope.toString(), 23 state: flow.state, 24 resourceOwner: flow.resourceOwner?.toString() ?? null, 25 token: flow.token?.toString() ?? null, 26 tokenExpire: new Date(flow.expire), 27 version: flow.version, 28 }; 29 } 30 31 export function mapToOAuth2Flow(dto: OAuth2FlowDto) { 32 return new OAuth2Flow( 33 new UUID(dto.uuid), 34 new UUID(dto.clientId), 35 Scope.of(dto.scope), 36 dto.state, 37 dto.resourceOwner ? new UUID(dto.resourceOwner) : null, 38 new Ephemeral( 39 dto.token ? new Token(dto.token) : null, 40 dto.tokenExpire.getTime(), 41 ), 42 dto.version, 43 ); 44 }