Skip to content

Commit

Permalink
Add JWT SecretKey in production env
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Diger committed Dec 9, 2023
1 parent 4653b1b commit 6256054
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ interface AuthService {
/**
* 사용자가 전달한 토큰을 가지고 사용자의 카카오 유저 아이디를 반환하는 메소드입니다.
*
* @param accessToken 사용자가 클라이언트에서 발급받은 토큰입니다.
* @param userToken 사용자가 클라이언트에서 발급받은 토큰입니다.
* @return 사용자의 카카오 유저 아이디. 반환 값이 없거나 유효하지 않은 토큰인 경우 null을 반환합니다.
*/
fun verifyKaKao(accessToken: String): String
fun verifyKaKao(userToken: String): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class JwtAgentImpl(

private fun buildClaims(user: User): Claims {
val claims = Jwts.claims()
claims.setSubject(user.nickname.nickname)
claims.setSubject(user.nickname.value)
claims["id"] = user.id
return claims
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class KakaoOAuthService(
) : AuthService {

private val KAKAO_USERINFO_REQUEST_URL = "https://kapi.kakao.com/v2/user/me"
override fun verifyKaKao(accessToken: String): String {
override fun verifyKaKao(userToken: String): String {
val headers = HttpHeaders()
headers.contentType = MediaType.APPLICATION_FORM_URLENCODED
headers.setBearerAuth(accessToken)
headers.setBearerAuth(userToken)

val request = HttpEntity(
null,
Expand All @@ -29,6 +29,6 @@ class KakaoOAuthService(
KakaoLoginResponse::class.java
)

return response.body!!.id!!
return response.body?.id!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ fun User.fromDto(): UserEntity = UserEntity(
)

@Embeddable
data class Nickname(val nickname: String) {
data class Nickname(
@Column(name = "nickname")
val value: String
) {
companion object {
fun generateRandomNickname(): Nickname {
return Nickname("random nickname")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ class UserService(
private val userRepository: UserRepository,
) {


@Transactional(readOnly = true)
fun loadByOAuthPayload(payload: String): User? {
val user = userRepository.findByOauthTokenPayload(payload) ?: return null
return user.toDto()
return userRepository.findByOauthTokenPayload(payload)?.toDto()
}

fun create(user: User): User {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
jwt:
secret-key: ENC(nFedRKX5zt00VoNk/11zZcZVAtdnl/AHTDJW74urxj103ameypl1NctWnJYl90thp8OS/DIP8B0oHXgvMVJ02TPFiMZes3Kf3/EPG9t/MnUKvjc4iz1HZ+F76oDcvxXheKiioRZkGt1b0g9iyh7PW4CKSo5T/rScgXsg2c+05bg=)

spring:
config:
activate:
Expand Down

0 comments on commit 6256054

Please sign in to comment.