Skip to content
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

Authentication success returns userid #104

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@ 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<String> {
return ResponseEntity.ok(token)
fun redirect(@RequestParam token: String, @RequestParam userid: Long): ResponseEntity<RedirectResponse> {
return ResponseEntity.ok(RedirectResponse(token, userid))
}
}

data class RegisterRequest(
val username: String,
val password: String
)

data class RedirectResponse(
val token: String,
val userId: Long
)
3 changes: 3 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading