Updated js example

This commit is contained in:
Stian Thorgersen 2013-10-18 19:15:21 +01:00
parent 7d6f88f617
commit a40568ed54
2 changed files with 7 additions and 8 deletions

View file

@ -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) {

View file

@ -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;