Merge pull request #277 from stianst/master
Remove clientSecret required in JS lib, and removed storing token to ses...
This commit is contained in:
commit
d8c13c9ac2
1 changed files with 7 additions and 10 deletions
|
@ -29,18 +29,11 @@ var Keycloak = function (options) {
|
||||||
throw 'clientId missing';
|
throw 'clientId missing';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.clientSecret) {
|
|
||||||
throw 'clientSecret missing';
|
|
||||||
}
|
|
||||||
|
|
||||||
kc.init = function (successCallback, errorCallback) {
|
kc.init = function (successCallback, errorCallback) {
|
||||||
if (window.oauth.callback) {
|
if (window.oauth.callback) {
|
||||||
delete sessionStorage.oauthToken;
|
|
||||||
processCallback(successCallback, errorCallback);
|
processCallback(successCallback, errorCallback);
|
||||||
} else if (options.token) {
|
} else if (options.token) {
|
||||||
kc.setToken(options.token, successCallback);
|
kc.setToken(options.token, successCallback);
|
||||||
} else if (sessionStorage.oauthToken) {
|
|
||||||
kc.setToken(sessionStorage.oauthToken, successCallback);
|
|
||||||
} else if (options.onload) {
|
} else if (options.onload) {
|
||||||
switch (options.onload) {
|
switch (options.onload) {
|
||||||
case 'login-required' :
|
case 'login-required' :
|
||||||
|
@ -166,7 +159,13 @@ var Keycloak = function (options) {
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
req.open('POST', url, true);
|
req.open('POST', url, true);
|
||||||
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||||
|
|
||||||
|
if (options.clientId && options.clientSecret) {
|
||||||
req.setRequestHeader('Authorization', 'Basic ' + btoa(options.clientId + ':' + options.clientSecret));
|
req.setRequestHeader('Authorization', 'Basic ' + btoa(options.clientId + ':' + options.clientSecret));
|
||||||
|
} else {
|
||||||
|
params += '&client_id=' + encodeURIComponent(options.clientId);
|
||||||
|
}
|
||||||
|
|
||||||
req.withCredentials = true;
|
req.withCredentials = true;
|
||||||
|
|
||||||
req.onreadystatechange = function () {
|
req.onreadystatechange = function () {
|
||||||
|
@ -193,7 +192,6 @@ var Keycloak = function (options) {
|
||||||
|
|
||||||
kc.setToken = function(token, successCallback) {
|
kc.setToken = function(token, successCallback) {
|
||||||
if (token) {
|
if (token) {
|
||||||
sessionStorage.oauthToken = token;
|
|
||||||
window.oauth.token = token;
|
window.oauth.token = token;
|
||||||
kc.token = token;
|
kc.token = token;
|
||||||
|
|
||||||
|
@ -207,7 +205,6 @@ var Keycloak = function (options) {
|
||||||
successCallback && successCallback({ authenticated: kc.authenticated, subject: kc.subject });
|
successCallback && successCallback({ authenticated: kc.authenticated, subject: kc.subject });
|
||||||
}, 0);
|
}, 0);
|
||||||
} else {
|
} else {
|
||||||
delete sessionStorage.oauthToken;
|
|
||||||
delete window.oauth.token;
|
delete window.oauth.token;
|
||||||
delete kc.token;
|
delete kc.token;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue