Skip to content

Commit

Permalink
Implement simple authnz logout for vue frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
waltkb committed Jan 15, 2025
1 parent 5b0faac commit fb2d062
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.util.date.*
import kotlinx.serialization.json.*

fun Application.ktorAuthnzFrontendRoutes() {
Expand All @@ -38,14 +39,13 @@ fun Application.ktorAuthnzFrontendRoutes() {
}
}

post("login") { // also in authenticate {} block as it just relays authnz auth
//call.sessions.set(LoginTokenSession(token))

post("login") {
val providedToken = call.receiveText()
println("providedToken: $providedToken")

val (account, token) = if (providedToken.isNotEmpty()) {
val token = Json.decodeFromString<JsonObject>(providedToken)["token"]?.jsonPrimitive?.content ?: error("Missing token")
val token =
Json.decodeFromString<JsonObject>(providedToken)["token"]?.jsonPrimitive?.content ?: error("Missing token")
val session = KtorAuthnzManager.tokenHandler.resolveTokenToSession(token)
val account = session.accountId
val sessionToken = session.token
Expand All @@ -64,6 +64,13 @@ fun Application.ktorAuthnzFrontendRoutes() {
}
)
}

post("logout") {
call.response.cookies.append("ktor-authnz-auth", "", CookieEncoding.URI_ENCODING, 0L, GMTDate())
call.response.cookies.append("auth.token", "", CookieEncoding.URI_ENCODING, 0L, GMTDate())

context.respond(HttpStatusCode.OK)
}
}
}
}

0 comments on commit fb2d062

Please sign in to comment.