-
Notifications
You must be signed in to change notification settings - Fork 16
fix(be): add redirection to frontend after kakao oauth callback #3627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/remove-whitelist
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { | |||||||||||||||||||||||
| Param, | ||||||||||||||||||||||||
| ParseEnumPipe | ||||||||||||||||||||||||
| } from '@nestjs/common' | ||||||||||||||||||||||||
| import { ConfigService } from '@nestjs/config' | ||||||||||||||||||||||||
| import { AuthGuard } from '@nestjs/passport' | ||||||||||||||||||||||||
| import { Provider } from '@prisma/client' | ||||||||||||||||||||||||
| import { Request, Response } from 'express' | ||||||||||||||||||||||||
|
|
@@ -27,7 +28,10 @@ import type { GithubUser, KakaoUser } from './interface/social-user.interface' | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| @Controller('auth') | ||||||||||||||||||||||||
| export class AuthController { | ||||||||||||||||||||||||
| constructor(private readonly authService: AuthService) {} | ||||||||||||||||||||||||
| constructor( | ||||||||||||||||||||||||
| private readonly authService: AuthService, | ||||||||||||||||||||||||
| private readonly configService: ConfigService | ||||||||||||||||||||||||
| ) {} | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| setJwtResponse = (res: Response, jwtTokens: JwtTokens) => { | ||||||||||||||||||||||||
| res.setHeader('authorization', `Bearer ${jwtTokens.accessToken}`) | ||||||||||||||||||||||||
|
|
@@ -158,15 +162,18 @@ export class AuthController { | |||||||||||||||||||||||
| @AuthNotNeededIfPublic() | ||||||||||||||||||||||||
| @Get('kakao-callback') | ||||||||||||||||||||||||
| @UseGuards(AuthGuard('kakao')) | ||||||||||||||||||||||||
| async kakaoLogin( | ||||||||||||||||||||||||
| @Res({ passthrough: true }) res: Response, | ||||||||||||||||||||||||
| @Req() req: Request | ||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||
| async kakaoLogin(@Res() res: Response, @Req() req: Request) { | ||||||||||||||||||||||||
| const kakaoUser = req.user as KakaoUser | ||||||||||||||||||||||||
| const result = await this.authService.kakaoLogin(kakaoUser) | ||||||||||||||||||||||||
| const frontendUrl = this.configService.getOrThrow('FRONTEND_URL') | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if ('oauthToken' in result) return result | ||||||||||||||||||||||||
| if ('oauthToken' in result) { | ||||||||||||||||||||||||
| return res.redirect( | ||||||||||||||||||||||||
| `${frontendUrl}/login?modal=social-unlinked&oauthToken=${result.oauthToken}` | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+170
to
+174
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 하드코딩된 문자열 템플릿 대신
Suggested change
References
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| this.setJwtResponse(res, result.jwtTokens) | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 리다이렉트(302 Redirect) 응답에 따라서 프론트엔드가 로그인 완료 후
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거 제미나이 코멘트도 지금 코드상으로는 반영해야 할거 같아요! 나머지 medium priority 2개는 흠.. 안해도 괜찮을거 같은데 잘 모르겠네요
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
위 쪽 코멘트 통해서 FE쪽에 이미 요청드렸습니다! 저희 쪽에서는 처리가 힘든 문제라서요 |
||||||||||||||||||||||||
| return res.redirect(`${frontendUrl}/`) | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oauthToken이 URL에 포함되어 있으면 브라우저 히스토리에 기록이 남으니 보안에 안좋을거 같아서
쿠키에 저장하고, 리다이렉트 후 프론트에서 쿠키를 읽는 방식은 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
원래는 쿠키를 통해서 이를 전달하려고 했는데, 다음 이유 때문에 Query String으로 바꾸었어요.
FE에서 쿠키에 저장된 값을 직접 읽어서 사용하려면
httpOnly값을false로 두어야 하는데 그러면 XSS 공격에 노출될 수 있어요. 이럴 경우에는 사실 상 QueryString으로 전달하는 것이랑 크게 다른게 없지 않나 싶어서요.또, 쿠키로 전달하면 브라우저 내부에 쿠키가 지속적으로 저장될 텐데, 회원가입이나 소셜 연동 이후에 FE 쪽에서 쿠키 무효화까지 신경써줘야 할 것 같은데, 그럴 경우에는 품이 크게 들 수 있을 것 같아요.
추가적으로, oauthToken 내부에 사실 provider 값과 provider에서 제공하는 oauthId 정도인데 이게 보안 상 그렇게 중요한가? 싶기도 해요