generated from pricelees/issue-pr-template
feat: 쿠키 관련 확장함수가 정의된 유틸 클래스 구현
This commit is contained in:
parent
1a0ec9d428
commit
636a4abe6b
@ -0,0 +1,27 @@
|
||||
package roomescape.system.auth.web.support
|
||||
|
||||
import jakarta.servlet.http.Cookie
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import jakarta.servlet.http.HttpServletResponse
|
||||
import roomescape.system.auth.web.TokenResponse
|
||||
|
||||
const val ACCESS_TOKEN_COOKIE_NAME = "accessToken"
|
||||
|
||||
fun Cookie.expire(): Unit {
|
||||
this.value = ""
|
||||
this.maxAge = 0
|
||||
}
|
||||
|
||||
fun TokenResponse.toCookie(): Cookie = Cookie(ACCESS_TOKEN_COOKIE_NAME, this.accessToken)
|
||||
.also { it.maxAge = 1800000 }
|
||||
|
||||
fun HttpServletRequest.accessTokenCookie(): Cookie = this.cookies
|
||||
?.firstOrNull { it.name == ACCESS_TOKEN_COOKIE_NAME }
|
||||
?: Cookie(ACCESS_TOKEN_COOKIE_NAME, "")
|
||||
|
||||
fun HttpServletResponse.addAccessTokenCookie(cookie: Cookie) {
|
||||
cookie.isHttpOnly = true
|
||||
cookie.secure = true
|
||||
cookie.path = "/"
|
||||
this.addCookie(cookie)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user