Skip to content

Commit

Permalink
🐛 로그인 시 리다이렉트 주소 origin 헤더 값으로 할당
Browse files Browse the repository at this point in the history
  • Loading branch information
mangchhe committed Apr 20, 2024
1 parent d5747ae commit 1923fe5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ import backend.team.ahachul_backend.api.member.application.port.`in`.AuthUseCase
import backend.team.ahachul_backend.api.member.application.port.`in`.command.GetRedirectUrlCommand
import backend.team.ahachul_backend.api.member.domain.model.ProviderType
import backend.team.ahachul_backend.common.exception.CommonException
import backend.team.ahachul_backend.common.properties.OAuthProperties
import backend.team.ahachul_backend.common.response.CommonResponse
import backend.team.ahachul_backend.common.response.ResponseCode
import io.jsonwebtoken.ExpiredJwtException
import io.jsonwebtoken.MalformedJwtException
import io.jsonwebtoken.UnsupportedJwtException
import io.jsonwebtoken.security.SignatureException
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*

@RestController
class AuthController(
private val authUseCase: AuthUseCase,

private val oAuthProperties: OAuthProperties,
) {

@GetMapping("/v1/auth/redirect-url")
Expand All @@ -30,7 +29,9 @@ class AuthController(
}

@PostMapping("/v1/auth/login")
fun login(@RequestBody request: LoginMemberDto.Request): CommonResponse<LoginMemberDto.Response> {
fun login(@RequestHeader(value="Origin") origin: String?, @RequestBody request: LoginMemberDto.Request): CommonResponse<LoginMemberDto.Response> {
// TODO 개발용 코드. 추후 삭제
oAuthProperties.client[request.providerType.toString().lowercase()]!!.redirectUri = "$origin/onboarding/redirect?type=${request.providerType}"
return CommonResponse.success(authUseCase.login(request.toCommand()))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class OAuthProperties(
) {

data class Client(
val clientId: String,
val clientSecret: String?,
val redirectUri: String,
val scope: String?,
val responseType: String,
val accessType: String?
val clientId: String,
val clientSecret: String?,
var redirectUri: String,
val scope: String?,
val responseType: String,
val accessType: String?
)

data class Provider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import backend.team.ahachul_backend.api.member.adapter.web.`in`.dto.GetTokenDto
import backend.team.ahachul_backend.api.member.adapter.web.`in`.dto.LoginMemberDto
import backend.team.ahachul_backend.api.member.application.port.`in`.AuthUseCase
import backend.team.ahachul_backend.api.member.domain.model.ProviderType
import backend.team.ahachul_backend.common.properties.OAuthProperties
import backend.team.ahachul_backend.config.controller.CommonDocsTestConfig
import io.jsonwebtoken.lang.Maps
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.mockito.BDDMockito.given
import org.mockito.BDDMockito.willDoNothing
import org.mockito.Mock
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.http.MediaType
Expand All @@ -27,6 +31,9 @@ class AuthControllerDocsTest : CommonDocsTestConfig() {
@MockBean
lateinit var authUseCase: AuthUseCase

@MockBean
lateinit var oAuthProperties: OAuthProperties

@Test
fun getRedirectUrlTest() {
// given
Expand Down Expand Up @@ -77,6 +84,11 @@ class AuthControllerDocsTest : CommonDocsTestConfig() {
given(authUseCase.login(any()))
.willReturn(response)

// TODO 개발용 코드. 추후 삭제
given(oAuthProperties.client).willReturn(
mapOf("kakao" to OAuthProperties.Client("", "", "", "", "", ""))
)

val request = LoginMemberDto.Request(
providerType = ProviderType.KAKAO,
providerCode = "providerCode"
Expand Down

0 comments on commit 1923fe5

Please sign in to comment.