Skip to content

Commit f003222

Browse files
authored
Merge pull request #146 from gsainfoteam/145-kdh
docs: add http respones in swagger
2 parents cb70baa + f28c631 commit f003222

File tree

3 files changed

+96
-4
lines changed

3 files changed

+96
-4
lines changed

src/auth/auth.controller.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ import {
1515
import {
1616
ApiCreatedResponse,
1717
ApiInternalServerErrorResponse,
18+
ApiNotFoundResponse,
1819
ApiOkResponse,
1920
ApiOperation,
2021
ApiTags,
2122
ApiUnauthorizedResponse,
2223
} from '@nestjs/swagger';
23-
import { PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/types';
2424
import { FastifyReply, FastifyRequest } from 'fastify';
25+
import { PasskeyOptionResDto } from 'src/user/dto/res.dto';
2526

2627
import { AuthService } from './auth.service';
2728
import {
@@ -142,17 +143,27 @@ export class AuthController {
142143
summary: 'get the passkey options',
143144
description: '패스키 로그인을 위한 정보를 불러옵니다.',
144145
})
146+
@ApiOkResponse({
147+
description: 'success',
148+
type: PasskeyOptionResDto,
149+
})
150+
@ApiNotFoundResponse({ description: 'Email is not found' })
151+
@ApiInternalServerErrorResponse({ description: 'server error' })
145152
@Post('passkey')
146153
async authenticateOptions(
147154
@Body() { email }: PasskeyDto,
148-
): Promise<PublicKeyCredentialRequestOptionsJSON> {
155+
): Promise<PasskeyOptionResDto> {
149156
return this.authService.authenticateOptions(email);
150157
}
151158

152159
@ApiOperation({
153160
summary: 'verify the passkey options',
154161
description: '패스키를 인증합니다.',
155162
})
163+
@ApiCreatedResponse({ description: 'success', type: LoginResDto })
164+
@ApiUnauthorizedResponse({ description: 'Response is invalid' })
165+
@ApiNotFoundResponse({ description: 'Email is not found' })
166+
@ApiInternalServerErrorResponse({ description: 'server error' })
156167
@Post('passkey/verify')
157168
async verifyAuthentication(
158169
@Body() { email, authenticationResponse }: VerifyPasskeyAuthenticationDto,

src/user/dto/res.dto.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
22
import { User } from '@prisma/client';
3+
import { AuthenticatorTransportFuture } from '@simplewebauthn/types';
34
import { Exclude } from 'class-transformer';
45

56
import { UserConsentType } from '../types/userConsent.type';
@@ -154,3 +155,72 @@ export class UserConsentListResDto {
154155
})
155156
list: UserConsentResDto[];
156157
}
158+
159+
class AllowCredentialDto {
160+
@ApiProperty({
161+
description: 'CredentialID of passkey (Base64URL)',
162+
example: 'aUF_gprsh...',
163+
})
164+
id: string;
165+
166+
@ApiProperty({ description: 'Credential type', example: 'public-key' })
167+
type: 'public-key';
168+
169+
@ApiPropertyOptional({
170+
description: 'List of communication method',
171+
example: ['internal'],
172+
})
173+
transports?: AuthenticatorTransportFuture[];
174+
}
175+
176+
class AuthenticationExtensionsDto {
177+
@ApiPropertyOptional({ description: 'appid extension' })
178+
appid?: string;
179+
180+
@ApiPropertyOptional({ description: 'credProps extension' })
181+
credProps?: boolean;
182+
183+
@ApiPropertyOptional({ description: 'hmacCreateSecret extension' })
184+
hmacCreateSecret?: boolean;
185+
186+
@ApiPropertyOptional({ description: 'minPinLength extension' })
187+
minPinLength?: boolean;
188+
}
189+
190+
export class PasskeyOptionResDto {
191+
@ApiProperty({
192+
description: 'challenge (Base64URL)',
193+
example: 'HPv7vydo...',
194+
})
195+
challenge: string;
196+
197+
@ApiPropertyOptional({ description: 'request timeout(ms)', example: 60000 })
198+
timeout?: number;
199+
200+
@ApiPropertyOptional({
201+
description: 'Relying Party ID',
202+
example: 'idp.gistory.me',
203+
})
204+
rpId?: string;
205+
206+
@ApiPropertyOptional({
207+
example: [AllowCredentialDto],
208+
description: 'Passkey list',
209+
type: [AllowCredentialDto],
210+
})
211+
allowCredentials?: AllowCredentialDto[];
212+
213+
@ApiPropertyOptional({
214+
description: 'User verification policy',
215+
example: 'preferred',
216+
enum: ['required', 'discouraged', 'preferred'],
217+
})
218+
userVerification?: 'required' | 'discouraged' | 'preferred';
219+
220+
@ApiPropertyOptional({
221+
example: AuthenticationExtensionsDto,
222+
description: 'WebAuthn extensions',
223+
type: AuthenticationExtensionsDto,
224+
})
225+
extensions?: AuthenticationExtensionsDto;
226+
}

src/user/user.controller.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import {
2222
ApiCreatedResponse,
2323
ApiForbiddenResponse,
2424
ApiInternalServerErrorResponse,
25+
ApiNotFoundResponse,
2526
ApiOkResponse,
2627
ApiOperation,
2728
ApiTags,
2829
ApiUnauthorizedResponse,
2930
} from '@nestjs/swagger';
3031
import { User } from '@prisma/client';
31-
import { PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/types';
3232
import { GetUser } from 'src/auth/decorator/getUser.decorator';
3333
import { UserGuard } from 'src/auth/guard/auth.guard';
3434

@@ -40,6 +40,7 @@ import {
4040
VerifyPasskeyRegistrationDto,
4141
} from './dto/req.dto';
4242
import {
43+
PasskeyOptionResDto,
4344
UpdateUserPictureResDto,
4445
UserConsentListResDto,
4546
UserConsentResDto,
@@ -190,17 +191,27 @@ export class UserController {
190191
summary: 'register the passkey',
191192
description: '패스키를 등록을 위한 challenge를 발급합니다.',
192193
})
194+
@ApiOkResponse({
195+
description: 'success',
196+
type: PasskeyOptionResDto,
197+
})
198+
@ApiNotFoundResponse({ description: 'Email is not found' })
199+
@ApiInternalServerErrorResponse({ description: 'server error' })
193200
@Post('passkey')
194201
async registerOptions(
195202
@Body() { email }: IssueUserSecretDto,
196-
): Promise<PublicKeyCredentialRequestOptionsJSON> {
203+
): Promise<PasskeyOptionResDto> {
197204
return await this.userService.registerOptions(email);
198205
}
199206

200207
@ApiOperation({
201208
summary: 'verify the registration options',
202209
description: '패스키 등록합니다.',
203210
})
211+
@ApiOkResponse({ description: 'success', type: Boolean })
212+
@ApiUnauthorizedResponse({ description: 'Response is invalid' })
213+
@ApiNotFoundResponse({ description: 'Email is not found' })
214+
@ApiInternalServerErrorResponse({ description: 'server error' })
204215
@Post('passkey/verify')
205216
async verifyRegistration(
206217
@Body() { email, registrationResponse }: VerifyPasskeyRegistrationDto,

0 commit comments

Comments
 (0)