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

This commit is contained in:
usbharu 2023-03-24 16:07:33 +09:00
parent ec7b01c7ce
commit e44d0b545f
2 changed files with 10 additions and 7 deletions

View File

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

View File

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