-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: REAT API kakao login * feat: /auth swagger 반영 * docs: Auth server 콘솔 출력 * chore: remove generic * feat: 카카오계정 간편로그인 &prompt=select_account * feat: /kakao/unlink * format: fix prettier line separator `lf` * fix: memberExcel > memberFile
- Loading branch information
Showing
9 changed files
with
203 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,49 @@ | ||
import { Controller } from '@nestjs/common'; | ||
import { ApiTags } from '@nestjs/swagger'; | ||
import { Controller, Get, Post, Query } from '@nestjs/common'; | ||
import { ApiQuery, ApiTags } from '@nestjs/swagger'; | ||
|
||
import { AuthService } from './auth.service'; | ||
|
||
@ApiTags('Auth') | ||
@Controller('auth') | ||
export class AuthController { | ||
constructor() {} | ||
constructor(private readonly authService: AuthService) {} | ||
|
||
@Get('kakao/callback') | ||
async kakaoCallback( | ||
@Query('code') code: string, | ||
// @Query('error') error: string, | ||
// @Query('error_description') error_description: string, | ||
// @Query('state') state: string, | ||
) { | ||
return this.authService.kakaoCallback( | ||
code, | ||
// error, | ||
// error_description, | ||
// state, | ||
); | ||
} | ||
|
||
@Post('kakao/token') | ||
@ApiQuery({ name: 'code', required: true }) | ||
async kakaoToken(@Query('code') code: string) { | ||
return this.authService.kakaoToken(code); | ||
} | ||
|
||
@Post('kakao/login') | ||
@ApiQuery({ name: 'kakaoToken', required: true }) | ||
async kakaoLogin(@Query('kakaoToken') kakaoToken: string) { | ||
return this.authService.kakaoLogin(kakaoToken); | ||
} | ||
|
||
@Post('kakao/logout') | ||
@ApiQuery({ name: 'kakaoToken', required: true }) | ||
async kakaoLogout(@Query('kakaoToken') kakaoToken: string) { | ||
return this.authService.kakaoLogout(kakaoToken); | ||
} | ||
|
||
@Post('kakao/unlink') | ||
@ApiQuery({ name: 'kakaoToken', required: true }) | ||
async kakaoUnlink(@Query('kakaoToken') kakaoToken: string) { | ||
return this.authService.kakaoUnlink(kakaoToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,89 @@ | ||
import { HttpService } from '@nestjs/axios'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { firstValueFrom } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class AuthService {} | ||
export class AuthService { | ||
constructor( | ||
private readonly configService: ConfigService, | ||
private readonly httpService: HttpService, | ||
) {} | ||
|
||
kakaoCallback( | ||
code: string, | ||
// error: string, | ||
// error_description: string, | ||
// state: string, | ||
) { | ||
return code; | ||
} | ||
|
||
async kakaoToken(code: string) { | ||
const { data } = await firstValueFrom( | ||
this.httpService.post( | ||
'https://kauth.kakao.com/oauth/token', | ||
{ | ||
grant_type: 'authorization_code', | ||
client_id: this.configService.get<string>('KAKAO_REST_API_KEY'), | ||
redirect_uri: this.configService.get<string>('KAKAO_REDIRECT_URI'), | ||
code, | ||
}, | ||
{ | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', | ||
}, | ||
}, | ||
), | ||
); | ||
|
||
return data['access_token']; | ||
} | ||
|
||
async kakaoLogin(kakaoToken: string) { | ||
const { data } = await firstValueFrom( | ||
this.httpService.get('https://kapi.kakao.com/v2/user/me', { | ||
headers: { | ||
Authorization: `Bearer ${kakaoToken}`, | ||
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', | ||
}, | ||
}), | ||
); | ||
|
||
return data; | ||
} | ||
|
||
async kakaoLogout(kakaoToken: string) { | ||
const { data } = await firstValueFrom( | ||
this.httpService.post( | ||
'https://kapi.kakao.com/v1/user/logout', | ||
{}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${kakaoToken}`, | ||
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', | ||
}, | ||
}, | ||
), | ||
); | ||
|
||
return data; | ||
} | ||
|
||
async kakaoUnlink(kakaoToken: string) { | ||
const { data } = await firstValueFrom( | ||
this.httpService.post( | ||
'https://kapi.kakao.com/v1/user/unlink', | ||
{}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${kakaoToken}`, | ||
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', | ||
}, | ||
}, | ||
), | ||
); | ||
|
||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,63 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; | ||
import * as process from 'node:process'; | ||
|
||
import { AuthModule } from '../../auth/auth.module'; | ||
import { EventModule } from '../../event/event.module'; | ||
import { GroupModule } from '../../group/group.module'; | ||
import { MemberModule } from '../../member/member.module'; | ||
import { TransactionModule } from '../../transaction/transaction.module'; | ||
import { UserModule } from '../../user/user.module'; | ||
|
||
export const swaggerConfig = (app: INestApplication<any>) => { | ||
export const swaggerConfig = (app: INestApplication) => { | ||
const config = new DocumentBuilder() | ||
.setTitle('sometime API') | ||
.addTag('Group', '모임 관련 API') | ||
.addTag('Member', '모임 회원 관련 API') | ||
.addTag('Event', '이벤트 관련 API') | ||
.addTag('Auth', 'OAuth 인증 관련 API') | ||
.addTag('User', '사용자 관련 API') | ||
.addTag('Transaction', '거래 내역 관련 API') | ||
.build(); | ||
|
||
const document = SwaggerModule.createDocument(app, config, { | ||
include: [GroupModule, MemberModule, EventModule, UserModule], | ||
include: [GroupModule, MemberModule, EventModule, TransactionModule], | ||
}); | ||
SwaggerModule.setup('api', app, document); | ||
}; | ||
|
||
export const devSwaggerConfig = (app: INestApplication<any>) => { | ||
export const devSwaggerConfig = (app: INestApplication) => { | ||
const config = new DocumentBuilder() | ||
.setTitle('sometime API') | ||
.addTag('Debug', '개발용 API') | ||
.addTag('Group', '모임 관련 API') | ||
.addTag('Member', '모임 회원 관련 API') | ||
.addTag('Event', '이벤트 관련 API') | ||
.addTag('Auth', 'OAuth 인증 관련 API') | ||
.addTag('User', '사용자 관련 API') | ||
.addTag('Transaction', '거래 내역 관련 API') | ||
.build(); | ||
|
||
const document = SwaggerModule.createDocument(app, config); | ||
SwaggerModule.setup('dev', app, document); | ||
}; | ||
|
||
export const authSwaggerConfig = (app: INestApplication) => { | ||
const authorizationUrl = `https://kauth.kakao.com/oauth/authorize?client_id=${process.env.KAKAO_REST_API_KEY}&redirect_uri=${process.env.KAKAO_REDIRECT_URI}&response_type=code&prompt=select_account`; | ||
const config = new DocumentBuilder() | ||
.setTitle('sometime API') | ||
.addTag('Auth', 'OAuth 인증 관련 API') | ||
.addTag('User', '사용자 관련 API') | ||
.addOAuth2({ | ||
type: 'oauth2', | ||
flows: { | ||
authorizationCode: { | ||
authorizationUrl, | ||
// tokenUrl: 'https://kauth.kakao.com/oauth/token', | ||
scopes: undefined, | ||
}, | ||
}, | ||
}) | ||
.build(); | ||
|
||
const document = SwaggerModule.createDocument(app, config, { | ||
include: [AuthModule, UserModule], | ||
}); | ||
SwaggerModule.setup('auth', app, document); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters