fix: セッション認証を廃止

This commit is contained in:
usbharu 2023-03-24 16:07:33 +09:00
parent 08f4d38712
commit 39be6647e0
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
2 changed files with 10 additions and 7 deletions

View File

@ -1,24 +1,27 @@
package dev.usbharu.hideout.plugins package dev.usbharu.hideout.plugins
import dev.usbharu.hideout.service.IUserAuthService import dev.usbharu.hideout.service.IUserAuthService
import dev.usbharu.hideout.service.UserService
import io.ktor.server.application.* import io.ktor.server.application.*
import io.ktor.server.auth.* import io.ktor.server.auth.*
import io.ktor.server.sessions.* import io.ktor.server.sessions.*
import kotlin.time.Duration.Companion.days import kotlin.collections.set
data class UserSession(val username: String) : Principal data class UserSession(val username: String) : Principal
const val tokenAuth = "token-auth" const val tokenAuth = "token-auth"
fun Application.configureSecurity(userAuthService: IUserAuthService) { fun Application.configureSecurity(userAuthService: IUserAuthService) {
install(Authentication){ install(Authentication) {
bearer(tokenAuth) { bearer(tokenAuth) {
authenticate { authenticate { bearerTokenCredential ->
bearerTokenCredential ->
UserIdPrincipal(bearerTokenCredential.token) UserIdPrincipal(bearerTokenCredential.token)
} }
skipWhen { true } skipWhen { true }
} }
} }
// install(Sessions) {
// cookie<UserSession>("MY_SESSION") {
// cookie.extensions["SameSite"] = "lax"
// }
// }
} }

View File

@ -15,8 +15,8 @@ fun Application.login(){
post("/login") { post("/login") {
println("aaaaaaaaaaaaaaaaaaaaa") println("aaaaaaaaaaaaaaaaaaaaa")
val principal = call.principal<UserIdPrincipal>() val principal = call.principal<UserIdPrincipal>()
call.sessions.set(UserSession(principal!!.name)) // call.sessions.set(UserSession(principal!!.name))
call.respondRedirect("/users/${principal.name}") call.respondRedirect("/users/${principal!!.name}")
} }
} }