keycloak-aplcache

Updated js example

10/18/2013 3:15:21 PM

Changes

Details

diff --git a/examples/js/index.html b/examples/js/index.html
index bfe60fe..940c146 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 480996d..b52438d 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;