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 ba0e3f57193bb..276398521aec9 100644 --- a/extensions/oidc/deployment/src/main/resources/dev-templates/provider.html +++ b/extensions/oidc/deployment/src/main/resources/dev-templates/provider.html @@ -1,6 +1,5 @@ {#include main fluid=true} {#title}Keycloak{/title} - {#script} {#if info:oidcApplicationType is 'service'} @@ -8,6 +7,7 @@ var accessToken; var idToken; var loggedIn = false; + var userName; $( document ).ready(function() { @@ -18,8 +18,8 @@ var hash = window.location.hash; accessToken = hash.match(/access_token=([^&]+)/)[1]; idToken = hash.match(/id_token=([^&]+)/)[1]; - $('#accessTokenArea').text(accessToken); - $('#idTokenArea').text(idToken); + $('#accessTokenArea').text(decodeToken(accessToken)); + $('#idTokenArea').text(decodeToken(idToken)); }else if(codeInUrl()){ loggedIn === true; $('.implicitLoggedOut').hide(); @@ -33,6 +33,7 @@ $('.implicitLoggedIn').hide(); accessToken = null; idToken = null; + userName = null; $('#accessTokenArea').text(''); $('#idTokenArea').text(''); @@ -151,11 +152,33 @@ var tokens = JSON.parse(data); accessToken = tokens.access_token idToken = tokens.id_token - $('#accessTokenArea').text(accessToken); - $('#idTokenArea').text(idToken); + $('#accessTokenArea').text(decodeToken(accessToken)); + $('#idTokenArea').text(decodeToken(idToken)); }); } + function decodeToken(token) { + var parts = token.split("."); + if (parts.length == 3) { + var headers = window.atob(parts[0]); + var payload = window.atob(parts[1]); + var jsonPayload = JSON.parse(payload); + if (!userName) { + if (jsonPayload.upn) { + userName = jsonPayload.upn; + } else if (jsonPayload.preferred_username) { + userName = jsonPayload.preferred_username; + } + if (userName) { + $('#userName').append("" + "as " + userName + ""); + } + } + return JSON.stringify(JSON.parse(headers), null, '\t') + "\r\n.\r\n" + JSON.stringify(jsonPayload,null,'\t') + "\r\n.\r\n" + parts[2]; + } else { + return token; + } + } + {/if} {/if} @@ -242,7 +265,7 @@
@@ -252,9 +275,9 @@