Authentication v2

This commit is contained in:
2025-02-04 21:47:29 +01:00
parent ec43e7eba8
commit 6aeecd444e
4 changed files with 224 additions and 0 deletions
@@ -20,7 +20,11 @@
package de.steamwar.plugins
import de.steamwar.sql.Token
import de.steamwar.util.TokenType
import de.steamwar.util.isValid
import de.steamwar.util.type
import io.ktor.http.*
import io.ktor.http.auth.*
import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
@@ -66,6 +70,14 @@ fun Application.configurePlugins() {
if (token == null) {
null
} else {
if (!token.isValid) {
token.delete()
return@authenticate null
}
if (token.type == TokenType.RESET_PASSWORD || token.type == TokenType.REFRESH_TOKEN) {
token.delete()
}
SWAuthPrincipal(token, token.owner)
}
}