From fb2d06262f5c9618c3e3dfa81ff2fca37340d8ae Mon Sep 17 00:00:00 2001 From: waltkb <68587968+waltkb@users.noreply.github.com> Date: Wed, 15 Jan 2025 04:25:50 +0100 Subject: [PATCH] Implement simple authnz logout for vue frontend --- .../auth/KtorAuthnzFrontendController.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/web/controllers/auth/KtorAuthnzFrontendController.kt b/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/web/controllers/auth/KtorAuthnzFrontendController.kt index dc72d8721..51266e631 100644 --- a/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/web/controllers/auth/KtorAuthnzFrontendController.kt +++ b/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/web/controllers/auth/KtorAuthnzFrontendController.kt @@ -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() { @@ -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(providedToken)["token"]?.jsonPrimitive?.content ?: error("Missing token") + val token = + Json.decodeFromString(providedToken)["token"]?.jsonPrimitive?.content ?: error("Missing token") val session = KtorAuthnzManager.tokenHandler.resolveTokenToSession(token) val account = session.accountId val sessionToken = session.token @@ -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) + } } } }