Skip to content

Commit 8a2d52c

Browse files
authored
Merge pull request #172 from Stack-Knowledge/update/same-site
# 172 Same Site 설정
2 parents dc780e1 + 205cd05 commit 8a2d52c

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

src/main/kotlin/com/stack/knowledge/domain/auth/presentation/AuthWebAdapter.kt

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import com.stack.knowledge.domain.auth.application.service.*
44
import com.stack.knowledge.domain.auth.presentation.data.request.GoogleStudentSignInRequest
55
import com.stack.knowledge.domain.auth.presentation.data.request.GoogleTeacherSignInRequest
66
import com.stack.knowledge.domain.auth.presentation.data.response.TokenResponse
7+
import org.springframework.http.HttpHeaders
8+
import org.springframework.http.ResponseCookie
79
import org.springframework.http.ResponseEntity
810
import org.springframework.web.bind.annotation.*
911
import javax.servlet.http.Cookie
@@ -69,36 +71,40 @@ class AuthWebAdapter(
6971
fun googleStudentSignInCookie(@RequestBody @Valid googleStudentSignInRequest: GoogleStudentSignInRequest, response: HttpServletResponse): ResponseEntity<TokenResponse> {
7072
val serviceResponse = googleStudentSignInService.execute(googleStudentSignInRequest)
7173

72-
val accessToken = Cookie("access_token", serviceResponse.accessToken).apply {
73-
path = "/"
74-
isHttpOnly = true
75-
maxAge = 60 * 60 // 1시간
76-
}
77-
78-
val refreshToken = Cookie("refresh_token", serviceResponse.refreshToken).apply {
79-
path = "/"
80-
isHttpOnly = true
81-
maxAge = 60 * 60 * 24 * 30 // 30일
82-
}
83-
84-
val expiredAt = Cookie("expired_at", serviceResponse.expiredAt.toString()).apply {
85-
path = "/"
86-
isHttpOnly = true
87-
maxAge = 60 * 60 // 1시간
88-
}
89-
90-
val authority = Cookie("authority", serviceResponse.authority.toString()).apply {
91-
path = "/"
92-
isHttpOnly = true
93-
maxAge = 60 * 60 // 1시간
94-
}
95-
96-
response.addCookie(accessToken)
97-
response.addCookie(refreshToken)
98-
response.addCookie(expiredAt)
99-
response.addCookie(authority)
100-
101-
return ResponseEntity.ok().build()
74+
val accessToken = ResponseCookie.from("access_token", serviceResponse.accessToken)
75+
.path("/")
76+
.httpOnly(false)
77+
.maxAge(60 * 60)
78+
.sameSite("None")
79+
.build()
80+
81+
val refreshToken = ResponseCookie.from("refresh_token", serviceResponse.refreshToken)
82+
.path("/")
83+
.httpOnly(false)
84+
.maxAge(60 * 60)
85+
.sameSite("None")
86+
.build()
87+
88+
val expiredAt = ResponseCookie.from("expired_at", serviceResponse.expiredAt.toString())
89+
.path("/")
90+
.httpOnly(false)
91+
.maxAge(60 * 60)
92+
.sameSite("None")
93+
.build()
94+
95+
val authority = ResponseCookie.from("authority", serviceResponse.authority.toString())
96+
.path("/")
97+
.httpOnly(false)
98+
.maxAge(60 * 60)
99+
.sameSite("None")
100+
.build()
101+
102+
response.addHeader("Set-Cookie", accessToken.toString())
103+
response.addHeader("Set-Cookie", accessToken.toString())
104+
response.addHeader("Set-Cookie", expiredAt.toString())
105+
response.addHeader("Set-Cookie", authority.toString())
106+
107+
return ResponseEntity.ok().header(HttpHeaders.SET_COOKIE, response.toString()).build()
102108
}
103109

104110
@PatchMapping

src/main/kotlin/com/stack/knowledge/global/config/WebMvcConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class WebMvcConfig : WebMvcConfigurer {
1616
"https://stackknowledge.vercel.app",
1717
"https://stackknowledge-admin.vercel.app"
1818
)
19+
.exposedHeaders("Set-Cookie")
1920
.allowCredentials(true)
2021
}
2122
}

0 commit comments

Comments
 (0)