-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
adapters/in-web/src/main/kotlin/com/pokit/auth/aop/KakaoAuth.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.pokit.auth.aop | ||
|
||
@Target(AnnotationTarget.FUNCTION) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
annotation class KakaoAuth |
34 changes: 34 additions & 0 deletions
34
adapters/in-web/src/main/kotlin/com/pokit/auth/aop/KakaoAuthenticationAspect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.pokit.auth.aop | ||
|
||
import com.pokit.common.exception.ClientValidationException | ||
import com.pokit.common.exception.InvalidRequestException | ||
import com.pokit.token.exception.AuthErrorCode | ||
import jakarta.servlet.http.HttpServletRequest | ||
import org.aspectj.lang.annotation.Aspect | ||
import org.aspectj.lang.annotation.Before | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.stereotype.Component | ||
|
||
@Aspect | ||
@Component | ||
class KakaoAuthenticationAspect( | ||
private val request: HttpServletRequest | ||
) { | ||
@Value("\${auth.kakao.app-admin-key}") | ||
lateinit var adminKey: String | ||
|
||
@Before("@annotation(com.pokit.auth.aop.KakaoAuth)") | ||
fun checkCallbackHeader() { | ||
val authorizationHeader = request.getHeader(HttpHeaders.AUTHORIZATION) | ||
|
||
if (authorizationHeader.isNullOrBlank()) { | ||
throw ClientValidationException(AuthErrorCode.TOKEN_REQUIRED) | ||
} | ||
|
||
val (type, token) = authorizationHeader.split(" ", limit = 2) | ||
if (type != "KakaoAK" || adminKey != token) { | ||
throw InvalidRequestException(AuthErrorCode.INVALID_TOKEN) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters