From 0952e8baa268402a35fd4a42732184a5f90f197f Mon Sep 17 00:00:00 2001 From: Sergey Beryozkin Date: Mon, 18 Oct 2021 13:12:19 +0100 Subject: [PATCH] Fix Keycloak DevUI template to use a configured dev root --- .../security-openid-connect-dev-services.adoc | 4 ++++ .../src/main/resources/dev-templates/provider.html | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/src/main/asciidoc/security-openid-connect-dev-services.adoc b/docs/src/main/asciidoc/security-openid-connect-dev-services.adoc index 5173080046f1a..69f6f207f1018 100644 --- a/docs/src/main/asciidoc/security-openid-connect-dev-services.adoc +++ b/docs/src/main/asciidoc/security-openid-connect-dev-services.adoc @@ -304,6 +304,10 @@ Additionally, the extension should produce a `io.quarkus.oidc.deployment.devserv Please follow the link:dev-ui[Dev UI] tutorial as well as check the `extensions/oidc/deployment` sources for more ideas. +== Non Application Root Path Considerations + +This document refers to the `http://localhost:8080/q/dev` Dev UI URL in several places where `q` is a default non application root path. If you customize `quarkus.http.root-path` and/or `quarkus.http.non-application-root-path` properties then replace `q` accordingly, please see https://quarkus.io/blog/path-resolution-in-quarkus/[Path Resolution in Quarkus] for more information. + == References * link:dev-ui[Dev UI] diff --git a/extensions/oidc/deployment/src/main/resources/dev-templates/provider.html b/extensions/oidc/deployment/src/main/resources/dev-templates/provider.html index aa40f306396c6..b6e82843f42f1 100644 --- a/extensions/oidc/deployment/src/main/resources/dev-templates/provider.html +++ b/extensions/oidc/deployment/src/main/resources/dev-templates/provider.html @@ -11,6 +11,9 @@ var port = {config:property('quarkus.http.port')}; {#if info:oidcApplicationType is 'service'} + var devRoot = '{devRootAppend}'; + var encodedDevRoot = devRoot.replaceAll("/", "%2F"); + {#if info:oidcGrantType is 'implicit' || info:oidcGrantType is 'code'} var accessToken; var idToken; @@ -81,13 +84,13 @@ {#if info:oidcGrantType is 'implicit'} window.location.href = '{info:authorizationUrl}' + "?client_id=" + '{info:clientId}' - + "&redirect_uri=" + "http%3A%2F%2Flocalhost%3A" + port + "%2Fq%2Fdev%2Fio.quarkus.quarkus-oidc%2Fprovider" + + "&redirect_uri=" + "http%3A%2F%2Flocalhost%3A" + port + encodedDevRoot + "%2Fio.quarkus.quarkus-oidc%2Fprovider" + "&scope=openid&response_type=token id_token&response_mode=query&prompt=login" + "&nonce=" + makeid(); {#else} window.location.href = '{info:authorizationUrl}' + "?client_id=" + '{info:clientId}' - + "&redirect_uri=" + "http%3A%2F%2Flocalhost%3A" + port + "%2Fq%2Fdev%2Fio.quarkus.quarkus-oidc%2Fprovider" + + "&redirect_uri=" + "http%3A%2F%2Flocalhost%3A" + port + encodedDevRoot + "%2Fio.quarkus.quarkus-oidc%2Fprovider" + "&scope=openid&response_type=code&response_mode=query&prompt=login" + "&nonce=" + makeid(); {/if} @@ -166,7 +169,7 @@ localStorage.removeItem('authorized'); window.location.assign('{info:logoutUrl??}' - + "?post_logout_redirect_uri=" + "http%3A%2F%2Flocalhost%3A" + port + "%2Fq%2Fdev%2Fio.quarkus.quarkus-oidc%2Fprovider"); + + "?post_logout_redirect_uri=" + "http%3A%2F%2Flocalhost%3A" + port + encodedDevRoot + "%2Fio.quarkus.quarkus-oidc%2Fprovider"); } function exchangeCodeForTokens(code){ @@ -176,7 +179,7 @@ client: '{info:clientId}', clientSecret: '{info:clientSecret}', authorizationCode: code, - redirectUri: "http://localhost:" + port + "/q/dev/io.quarkus.quarkus-oidc/provider" + redirectUri: "http://localhost:" + port + devRoot + "/io.quarkus.quarkus-oidc/provider" }, function(data, status){ var tokens = JSON.parse(data); @@ -229,7 +232,6 @@ return token; } } - {/if} {/if}