diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 523ebf2..2405fe5 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -3,7 +3,14 @@ import { IdPGuard } from './guard/idp.guard'; import { GroupsGuard } from './guard/groups.guard'; import { GetUser } from './decorator/getUser.decorator'; import { User } from '@prisma/client'; -import { ApiOAuth2, ApiOperation, ApiTags } from '@nestjs/swagger'; +import { + ApiOAuth2, + ApiOkResponse, + ApiOperation, + ApiTags, +} from '@nestjs/swagger'; +import { AccessTokenDto } from './dto/res/accessTokenRes.Dto'; +import { UserResDto } from './dto/res/userRes.dto'; @ApiTags('auth') @Controller('auth') @@ -22,9 +29,13 @@ export class AuthController { description: 'idp login에서 callback을 받아서, idp groups token을 발급받습니다.', }) + @ApiOkResponse({ + type: AccessTokenDto, + description: 'idp groups token', + }) @Get('callback') @UseGuards(IdPGuard) - login(@Req() req: any): any { + login(@Req() req: any): AccessTokenDto { return req.user; } @@ -34,9 +45,13 @@ export class AuthController { '사용자 정보를 조회합니다. 이떄, 사용자 정보는 groups에 저장된 정보만을 가져옵니다.', }) @ApiOAuth2(['openid', 'email', 'profile']) + @ApiOkResponse({ + type: UserResDto, + description: 'User information', + }) @Get('info') @UseGuards(GroupsGuard) - getUserInfo(@GetUser() user: User): any { + getUserInfo(@GetUser() user: User): UserResDto { return user; } } diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 07bfb80..66afa1b 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common'; import { User } from '@prisma/client'; import { IdpService } from 'src/idp/idp.service'; import { UserService } from 'src/user/user.service'; +import { AccessTokenDto } from './dto/res/accessTokenRes.Dto'; @Injectable() export class AuthService { @@ -11,7 +12,7 @@ export class AuthService { private readonly idpService: IdpService, ) {} - async login(accessToken: string): Promise<{ accessToken: string }> { + async login(accessToken: string): Promise { this.logger.log('Login with IDP'); const { uuid, name, email } = await this.idpService.getUserInfo(accessToken); diff --git a/src/auth/dto/res/accessTokenRes.dto.ts b/src/auth/dto/res/accessTokenRes.dto.ts new file mode 100644 index 0000000..1f28712 --- /dev/null +++ b/src/auth/dto/res/accessTokenRes.dto.ts @@ -0,0 +1,6 @@ +import { ApiProperty } from '@nestjs/swagger'; + +export class AccessTokenDto { + @ApiProperty() + accessToken: string; +} diff --git a/src/auth/dto/res/userRes.dto.ts b/src/auth/dto/res/userRes.dto.ts new file mode 100644 index 0000000..45ca31d --- /dev/null +++ b/src/auth/dto/res/userRes.dto.ts @@ -0,0 +1,16 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { User } from '@prisma/client'; + +export class UserResDto implements User { + @ApiProperty() + uuid: string; + + @ApiProperty() + name: string; + + @ApiProperty() + email: string; + + @ApiProperty() + createdAt: Date; +} diff --git a/src/auth/strategy/idp.strategy.ts b/src/auth/strategy/idp.strategy.ts index c85eb01..39cb177 100644 --- a/src/auth/strategy/idp.strategy.ts +++ b/src/auth/strategy/idp.strategy.ts @@ -3,6 +3,7 @@ import { Strategy } from 'passport-oauth2'; import { PassportStrategy } from '@nestjs/passport'; import { ConfigService } from '@nestjs/config'; import { AuthService } from '../auth.service'; +import { AccessTokenDto } from '../dto/res/accessTokenRes.Dto'; @Injectable() export class IdpStrategy extends PassportStrategy(Strategy, 'idp') { @@ -20,7 +21,7 @@ export class IdpStrategy extends PassportStrategy(Strategy, 'idp') { }); } - async validate(accessToken: string): Promise { + async validate(accessToken: string): Promise { return this.authService.login(accessToken); } } diff --git a/src/external/external.controller.ts b/src/external/external.controller.ts index b5529fb..7b98e50 100644 --- a/src/external/external.controller.ts +++ b/src/external/external.controller.ts @@ -2,8 +2,10 @@ import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common'; import { ApiBasicAuth, ApiBearerAuth, + ApiCreatedResponse, ApiForbiddenResponse, ApiInternalServerErrorResponse, + ApiOkResponse, ApiOperation, ApiTags, ApiUnauthorizedResponse, @@ -28,6 +30,7 @@ export class ExternalController { '해당 유저가 가입된 그룹 들을 확인할 수 있는 토큰을 생성합니다.', }) @UseGuards(ClientGuard) + @ApiCreatedResponse({ type: ExternalTokenResDto }) @ApiUnauthorizedResponse() @ApiForbiddenResponse() @ApiInternalServerErrorResponse() @@ -45,6 +48,7 @@ export class ExternalController { description: '해당 유저가 가입된 그룹 들에 관한 정보를 가져옵니다.', }) @UseGuards(ExternalGuard) + @ApiOkResponse({ type: ExternalInfoResDto }) @ApiUnauthorizedResponse() @ApiInternalServerErrorResponse() @ApiBearerAuth('external')