diff --git a/src/main/java/dev/dinauer/oidcproxy/LogoutService.java b/src/main/java/dev/dinauer/oidcproxy/LogoutService.java new file mode 100644 index 0000000..837dc41 --- /dev/null +++ b/src/main/java/dev/dinauer/oidcproxy/LogoutService.java @@ -0,0 +1,24 @@ +package dev.dinauer.oidcproxy; + +import io.vertx.core.http.Cookie; +import io.vertx.core.http.HttpServerResponse; +import jakarta.enterprise.context.ApplicationScoped; +import org.eclipse.microprofile.config.inject.ConfigProperty; + +@ApplicationScoped +public class LogoutService +{ + private static final String EMPTY = ""; + + @ConfigProperty(name = "oidc.proxy.logout.redirect.url") + String logoutRedirectUrl; + + public void logout(HttpServerResponse response) + { + response.addCookie(Cookie.cookie("session", EMPTY).setMaxAge(0).setPath("/").setHttpOnly(true).setSecure(true)); + response.addCookie(Cookie.cookie("identity", EMPTY).setMaxAge(0).setPath("/").setHttpOnly(false).setSecure(true)); + response.setStatusCode(302); + response.putHeader("Location", logoutRedirectUrl); + response.send(); + } +} diff --git a/src/main/java/dev/dinauer/oidcproxy/proxy/ProxyResource.java b/src/main/java/dev/dinauer/oidcproxy/proxy/ProxyResource.java index 4a87280..de1374a 100644 --- a/src/main/java/dev/dinauer/oidcproxy/proxy/ProxyResource.java +++ b/src/main/java/dev/dinauer/oidcproxy/proxy/ProxyResource.java @@ -1,5 +1,6 @@ package dev.dinauer.oidcproxy.proxy; +import dev.dinauer.oidcproxy.LogoutService; import dev.dinauer.oidcproxy.callback.CallbackService; import dev.dinauer.oidcproxy.proxy.exception.ProxyHttpException; import dev.dinauer.oidcproxy.proxy.exception.TokenNotFoundException; @@ -36,6 +37,9 @@ public class ProxyResource @Inject CallbackService callbackService; + @Inject + LogoutService logoutService; + @Route(path = "/auth/callback", order = 0) @Blocking public void callback(@Context RoutingContext context) @@ -47,11 +51,7 @@ public class ProxyResource @Blocking public void logout(@Context HttpServerResponse response) { - response.addCookie(Cookie.cookie("session", "").setMaxAge(0).setPath("/").setHttpOnly(true).setSecure(true)); - response.addCookie(Cookie.cookie("identity", "").setMaxAge(0).setPath("/").setHttpOnly(false).setSecure(true)); - response.setStatusCode(302); - response.putHeader("Location", "http://localhost:3000"); - response.send(); + logoutService.logout(response); } @Route(path = "/*", order = 2) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a5446a7..71eddbf 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -14,6 +14,8 @@ oidc.proxy.client.redirect=http://localhost:3000 %dev,test.oidc.proxy.crypto.secret=test +%dev,test.oidc.proxy.logout.redirect.url=http://localhost:3000 + %dev,test.quarkus.flyway.clean-at-start=true %dev.quarkus.flyway.locations=db/migration,db/dev quarkus.flyway.migrate-at-start=true \ No newline at end of file