import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { IsIn, IsNotEmpty, IsString, IsUrl, ValidateIf } from 'class-validator'; /** OAuth2 token request (RFC 6749), as JSON or application/x-www-form-urlencoded. */ export class IssueTokenDto { @ApiProperty({ enum: ['authorization_code', 'password', 'refresh_token'] }) @IsIn(['authorization_code', 'password', 'refresh_token']) grant_type!: 'authorization_code' | 'password' | 'refresh_token'; @ValidateIf((dto: IssueTokenDto) => dto.grant_type === 'authorization_code') @IsString() @IsNotEmpty() @ApiPropertyOptional({ description: 'authorization_code: code returned by Pireon', }) code?: string; @ValidateIf((dto: IssueTokenDto) => dto.grant_type === 'authorization_code') @IsString() @IsNotEmpty() @ApiPropertyOptional({ description: 'authorization_code: PKCE verifier' }) code_verifier?: string; @ValidateIf((dto: IssueTokenDto) => dto.grant_type === 'authorization_code') @IsUrl({ require_tld: false }) @ApiPropertyOptional({ description: 'authorization_code: redirect URI used to authorize', }) redirect_uri?: string; @ValidateIf((dto: IssueTokenDto) => dto.grant_type === 'password') @IsString() @IsNotEmpty() @ApiPropertyOptional({ description: 'password: Pireon email' }) username?: string; @ValidateIf((dto: IssueTokenDto) => dto.grant_type === 'password') @IsString() @IsNotEmpty() @ApiPropertyOptional({ description: 'password: Pireon password' }) password?: string; @ValidateIf((dto: IssueTokenDto) => dto.grant_type === 'refresh_token') @IsString() @IsNotEmpty() @ApiPropertyOptional({ description: 'refresh_token' }) refresh_token?: string; }