Skip to content

Commit

Permalink
Fix Keycloak DevUI template to use a configured dev root
Browse files Browse the repository at this point in the history
  • Loading branch information
sberyozkin committed Oct 18, 2021
1 parent 93f3547 commit 0952e8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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){
Expand All @@ -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);
Expand Down Expand Up @@ -229,7 +232,6 @@
return token;
}
}

{/if}
{/if}

Expand Down

0 comments on commit 0952e8b

Please sign in to comment.