Skip to content

Commit 4fe8572

Browse files
committed
refactor: apple login 방식에 login-secret을 추가한다
1 parent e76f208 commit 4fe8572

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

docs/api/identity/login-apple.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## Request
44
### HTTP METHOD : `POST`
55
### url : `https://api.gitanimals.org/logins/oauth/apple`
6+
### Header
7+
- Login-Secret: 내부 로그인 토큰을 전달 하세요.
68

79
### Request Body
810
```json

src/main/kotlin/org/gitanimals/identity/app/AppleLoginFacade.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package org.gitanimals.identity.app
33
import com.fasterxml.jackson.core.type.TypeReference
44
import com.fasterxml.jackson.databind.ObjectMapper
55
import io.jsonwebtoken.Jwts
6+
import org.gitanimals.core.AUTHORIZATION_EXCEPTION
67
import org.gitanimals.identity.app.AppleOauth2Api.AppleAuthKeyResponse
78
import org.gitanimals.identity.domain.EntryPoint
89
import org.gitanimals.identity.domain.UserService
910
import org.slf4j.LoggerFactory
11+
import org.springframework.beans.factory.annotation.Value
1012
import org.springframework.stereotype.Component
1113
import java.math.BigInteger
1214
import java.security.KeyFactory
@@ -20,11 +22,13 @@ class AppleLoginFacade(
2022
private val userService: UserService,
2123
private val appleOauth2Api: AppleOauth2Api,
2224
private val objectMapper: ObjectMapper,
25+
@Value("\${login.secret}") private val loginSecret: String,
2326
) {
2427

2528
private val logger = LoggerFactory.getLogger(this::class.simpleName)
2629

27-
fun login(accessToken: String): String {
30+
fun login(loginSecret: String, accessToken: String): String {
31+
require(this.loginSecret == loginSecret) { throw AUTHORIZATION_EXCEPTION }
2832
val appleUserInfo = getAppleUserInfo(accessToken)
2933

3034
val isExistsUser = userService.existsByEntryPointAndAuthenticationId(

src/main/kotlin/org/gitanimals/identity/controller/Oauth2Controller.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ class Oauth2Controller(
5252
@ResponseStatus(HttpStatus.OK)
5353
fun loginWithApple(
5454
@RequestBody appleLoginRequest: AppleLoginRequest,
55+
@RequestHeader("Login-Secret") loginSecret: String,
5556
): TokenResponse {
5657
val token = appleLoginFacade.login(
57-
accessToken = appleLoginRequest.accessToken
58+
loginSecret = loginSecret,
59+
accessToken = appleLoginRequest.accessToken,
5860
)
5961

6062
return TokenResponse(token)

0 commit comments

Comments
 (0)