From 2e155c699ae4916613e4634d1fc2f65754419935 Mon Sep 17 00:00:00 2001 From: Seungmin Choi Date: Wed, 15 Jan 2025 01:28:55 +0900 Subject: [PATCH] Authentication success returns userid --- .../config/CustomAuthenticationSuccessHandler.kt | 3 ++- .../toyTeam6Airbnb/user/controller/UserController.kt | 9 +++++++-- src/main/resources/application.yaml | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/example/toyTeam6Airbnb/config/CustomAuthenticationSuccessHandler.kt b/src/main/kotlin/com/example/toyTeam6Airbnb/config/CustomAuthenticationSuccessHandler.kt index 8d52d0f..b129f45 100644 --- a/src/main/kotlin/com/example/toyTeam6Airbnb/config/CustomAuthenticationSuccessHandler.kt +++ b/src/main/kotlin/com/example/toyTeam6Airbnb/config/CustomAuthenticationSuccessHandler.kt @@ -1,6 +1,7 @@ package com.example.toyTeam6Airbnb.config import com.example.toyTeam6Airbnb.user.JwtTokenProvider +import com.example.toyTeam6Airbnb.user.controller.PrincipalDetails import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse import org.springframework.beans.factory.annotation.Value @@ -22,6 +23,6 @@ class CustomAuthenticationSuccessHandler( ) { val token = jwtTokenProvider.generateToken(authentication.name) - response.sendRedirect("/redirect?token=$token") + response.sendRedirect("/redirect?token=$token&userid=${(authentication.principal as PrincipalDetails).getId()}") } } diff --git a/src/main/kotlin/com/example/toyTeam6Airbnb/user/controller/UserController.kt b/src/main/kotlin/com/example/toyTeam6Airbnb/user/controller/UserController.kt index 073edeb..6bfaa56 100644 --- a/src/main/kotlin/com/example/toyTeam6Airbnb/user/controller/UserController.kt +++ b/src/main/kotlin/com/example/toyTeam6Airbnb/user/controller/UserController.kt @@ -40,8 +40,8 @@ class UserController( // just return the token parameter in body @Operation(summary = "Redirect", description = "Redirect to the token", hidden = true) @GetMapping("/redirect") - fun redirect(@RequestParam token: String): ResponseEntity { - return ResponseEntity.ok(token) + fun redirect(@RequestParam token: String, @RequestParam userid: Long): ResponseEntity { + return ResponseEntity.ok(RedirectResponse(token, userid)) } } @@ -49,3 +49,8 @@ data class RegisterRequest( val username: String, val password: String ) + +data class RedirectResponse( + val token: String, + val userId: Long +) diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 2887182..2902ab1 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -23,6 +23,9 @@ spring: client-id: ASDF client-secret: ASDF redirect-uri: '{baseUrl}/api/oauth2/callback/{registrationId}' + scope: + - email + - profile naver: client-id: ASDF client-secret: ASDF