Merge pull request #390 from jeroenr/master

Fixed URI encoding for clientId and parse optional client secret from config file
This commit is contained in:
Stian Thorgersen 2014-05-16 13:02:41 +01:00
commit ae4d83107a

View file

@ -54,21 +54,22 @@ var Keycloak = function (config) {
if (initOptions.token || initOptions.refreshToken) { if (initOptions.token || initOptions.refreshToken) {
setToken(initOptions.token, initOptions.refreshToken); setToken(initOptions.token, initOptions.refreshToken);
} else if (initOptions.onLoad) { } else if (initOptions.onLoad) {
if (initOptions.onLoad == 'check-sso' || initOptions.onLoad == 'login-required') { var options = {};
var options = {}; switch (initOptions.onLoad) {
if (initOptions.onLoad == 'check-sso') { case 'check-sso':
options.prompt = 'none'; options.prompt = 'none';
} case 'login-required':
var p = kc.login(options); var p = kc.login(options);
if (p) { if (p) {
p.success(function() { p.success(function() {
initPromise.setSuccess(); initPromise.setSuccess();
}).error(function() { }).error(function() {
initPromise.setError(); initPromise.setError();
}); });
}; };
} else { break;
throw 'Invalid value for onLoad'; default:
throw 'Invalid value for onLoad';
} }
} }
} else { } else {
@ -131,7 +132,7 @@ var Keycloak = function (config) {
kc.createAccountUrl = function(options) { kc.createAccountUrl = function(options) {
var url = getRealmUrl() var url = getRealmUrl()
+ '/account' + '/account'
+ '?referrer=' + kc.clientId + '?referrer=' + encodeURIComponent(kc.clientId)
+ '&referrer_uri=' + encodeURIComponent(adapter.redirectUri(options)); + '&referrer_uri=' + encodeURIComponent(adapter.redirectUri(options));
return url; return url;
@ -143,7 +144,7 @@ var Keycloak = function (config) {
kc.hasRealmRole = function (role) { kc.hasRealmRole = function (role) {
var access = kc.realmAccess; var access = kc.realmAccess;
return access && access.roles.indexOf(role) >= 0 || false; return !!access && access.roles.indexOf(role) >= 0;
} }
kc.hasResourceRole = function(role, resource) { kc.hasResourceRole = function(role, resource) {
@ -152,7 +153,7 @@ var Keycloak = function (config) {
} }
var access = kc.resourceAccess[resource || kc.clientId]; var access = kc.resourceAccess[resource || kc.clientId];
return access && access.roles.indexOf(role) >= 0 || false; return !!access && access.roles.indexOf(role) >= 0;
} }
kc.loadUserProfile = function() { kc.loadUserProfile = function() {
@ -329,6 +330,7 @@ var Keycloak = function (config) {
kc.authServerUrl = config['auth-server-url']; kc.authServerUrl = config['auth-server-url'];
kc.realm = config['realm']; kc.realm = config['realm'];
kc.clientId = config['resource']; kc.clientId = config['resource'];
kc.clientSecret = (config['credentials'] || {})['secret'];
promise.setSuccess(); promise.setSuccess();
} else { } else {
@ -360,6 +362,7 @@ var Keycloak = function (config) {
kc.authServerUrl = config.url; kc.authServerUrl = config.url;
kc.realm = config.realm; kc.realm = config.realm;
kc.clientId = config.clientId; kc.clientId = config.clientId;
kc.clientSecret = (config.credentials || {}).secret;
promise.setSuccess(); promise.setSuccess();
} }