mirror of https://github.com/usbharu/Hideout.git
fix: セッション認証を廃止
This commit is contained in:
parent
08f4d38712
commit
39be6647e0
|
@ -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"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -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}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue