Skip to content

Commit

Permalink
✨feature : 토큰 응답정보 변경
Browse files Browse the repository at this point in the history
 - 토큰 만료시간 추가
 - email 응답데이터 추가
  • Loading branch information
ParkYunHo committed Aug 26, 2023
1 parent fa67854 commit bf307f2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.john.lotto.auth.adapter.out.adapter

import com.fasterxml.jackson.databind.ObjectMapper
import com.john.lotto.auth.application.dto.JwkInfo
import com.john.lotto.auth.application.dto.ResultTokenInfo
import com.john.lotto.auth.application.dto.TokenInfo
Expand All @@ -13,7 +12,6 @@ import com.john.lotto.common.exception.UnAuthorizedException
import com.john.lotto.common.utils.CipherUtils
import com.john.lotto.common.utils.EnvironmentUtils
import com.john.lotto.common.utils.ObjectMapperUtils
import com.john.lotto.member.MemberRepository
import io.jsonwebtoken.ExpiredJwtException
import io.jsonwebtoken.Jwts
import org.slf4j.LoggerFactory
Expand All @@ -30,14 +28,11 @@ import java.math.BigInteger
import java.security.KeyFactory
import java.security.PublicKey
import java.security.spec.RSAPublicKeySpec
import java.time.Instant
import java.time.LocalDateTime
import java.util.*

@Component
class KakaoAuthAdapter(
private val defaultWebClient: WebClient,
private val memberRepository: MemberRepository
private val defaultWebClient: WebClient
): AuthPort {
private val log = LoggerFactory.getLogger(this::class.java)

Expand Down
18 changes: 12 additions & 6 deletions api/src/main/kotlin/com/john/lotto/auth/application/AuthService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ class AuthService(
override fun token(state: String, code: String): Mono<ResultTokenInfo> =
authPort.token(state, code)
.flatMap {
val nickname = ObjectMapperUtils.decode(
val payload = ObjectMapperUtils.decode(
it.idToken.split(".")[1],
JwtTokenInfo.Payload::class.java
).nickname
)

Mono.just(
ResultTokenInfo(
idToken = it.idToken,
expiresIn = it.expiresIn,
refreshToken = it.refreshToken,
nickname = nickname
refreshTokenExpiresIn = it.refreshTokenExpiresIn,
nickname = payload.nickname,
email = payload.email
)
)
}
Expand All @@ -66,16 +69,19 @@ class AuthService(
override fun refresh(refreshToken: String): Mono<ResultTokenInfo> =
authPort.refresh(refreshToken = refreshToken)
.flatMap {
val nickname = ObjectMapperUtils.decode(
val payload = ObjectMapperUtils.decode(
it.idToken.split(".")[1],
JwtTokenInfo.Payload::class.java
).nickname
)

Mono.just(
ResultTokenInfo(
idToken = it.idToken,
expiresIn = it.expiresIn,
refreshToken = it.refreshToken,
nickname = nickname
refreshTokenExpiresIn = it.refreshTokenExpiresIn,
nickname = payload.nickname,
email = payload.email
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ data class ResultTokenInfo(
@field:Schema(description = "OpenID방식의 id_token", example = "header.payload.signature")
@field:JsonProperty("id_token")
val idToken: String,
@field:Schema(description = "id_token 만료시간", example = "0")
@field:JsonProperty("expires_in")
val expiresIn: Long? = 0L,
@field:Schema(description = "리프레시 토큰", example = "0")
@field:JsonProperty("refresh_token")
val refreshToken: String? = "",
@field:Schema(description = "리프레시 토큰 만료시간", example = "0")
@field:JsonProperty("refresh_token_expires_in")
val refreshTokenExpiresIn: Long? = 0L,
@field:Schema(description = "사용자 닉네임", example = "user")
@field:JsonProperty("nickname")
val nickname: String? = ""
val nickname: String? = "",
@field:Schema(description = "사용자 이메일", example = "lotto@email.com")
@field:JsonProperty("email")
val email: String? = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class JwtTokenInfo {
val sub: String,
val auth_time: Int,
val iss: String,
val nickname: String,
val nickname: String? = "",
val email: String? = "",
val exp: Int,
val iat: Int,
): Serializable
Expand Down

0 comments on commit bf307f2

Please sign in to comment.