From a40568ed5414935d468727fe5cdea7c0fd850a61 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Fri, 18 Oct 2013 19:15:21 +0100 Subject: [PATCH] Updated js example --- examples/js/index.html | 3 ++- examples/js/keycloak.js | 12 +++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/js/index.html b/examples/js/index.html index bfe60fe70d..940c1460b2 100644 --- a/examples/js/index.html +++ b/examples/js/index.html @@ -10,7 +10,8 @@ clientId : 'test-app', clientSecret : 'password', baseUrl : 'http://localhost:8081/auth-server', - realm : 'test' + realm : 'test', + redirectUri : 'http://localhost/js' }); if (keycloak.authenticated) { diff --git a/examples/js/keycloak.js b/examples/js/keycloak.js index 480996d343..b52438d3a0 100644 --- a/examples/js/keycloak.js +++ b/examples/js/keycloak.js @@ -4,7 +4,8 @@ window.keycloak = (function () { baseUrl: null, clientId: null, clientSecret: null, - realm: null + realm: null, + redirectUri: null }; kc.init = function (c) { @@ -30,12 +31,9 @@ window.keycloak = (function () { } kc.login = function () { - var clientId = encodeURIComponent(config.clientId); - var redirectUri = encodeURIComponent(window.location.href); - var state = encodeURIComponent(createUUID()); - var realm = encodeURIComponent(config.realm); - var url = config.baseUrl + '/rest/realms/' + realm + '/tokens/login?response_type=code&client_id=' + clientId + '&redirect_uri=' + redirectUri - + '&state=' + state; + var state = createUUID(); + var url = config.baseUrl + '/rest/realms/' + encodeURIComponent(config.realm) + '/tokens/login?response_type=code&client_id=' + + encodeURIComponent(config.clientId) + '&redirect_uri=' + encodeURIComponent(config.redirectUri) + '&state=' + encodeURIComponent(state); sessionStorage.state = state;