2016-02-03 10:20:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
|
|
|
* and other contributors as indicated by the @author tags.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
(function( window, undefined ) {
|
|
|
|
|
|
|
|
var Keycloak = function (config) {
|
|
|
|
if (!(this instanceof Keycloak)) {
|
|
|
|
return new Keycloak(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
var kc = this;
|
|
|
|
var adapter;
|
|
|
|
var refreshQueue = [];
|
2016-07-04 18:58:15 +00:00
|
|
|
var callbackStorage;
|
2015-07-17 11:45:43 +00:00
|
|
|
|
|
|
|
var loginIframe = {
|
|
|
|
enable: true,
|
2016-10-17 12:05:36 +00:00
|
|
|
callbackList: [],
|
2015-07-17 11:45:43 +00:00
|
|
|
interval: 5
|
|
|
|
};
|
|
|
|
|
2017-07-04 19:18:34 +00:00
|
|
|
var scripts = document.getElementsByTagName('script');
|
|
|
|
for (var i = 0; i < scripts.length; i++) {
|
|
|
|
if ((scripts[i].src.indexOf('keycloak.js') !== -1 || scripts[i].src.indexOf('keycloak.min.js') !== -1) && scripts[i].src.indexOf('version=') !== -1) {
|
|
|
|
kc.iframeVersion = scripts[i].src.substring(scripts[i].src.indexOf('version=') + 8).split('&')[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-12 10:00:02 +00:00
|
|
|
var useNonce = true;
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
kc.init = function (initOptions) {
|
|
|
|
kc.authenticated = false;
|
2016-04-15 12:09:07 +00:00
|
|
|
|
2016-07-04 18:58:15 +00:00
|
|
|
callbackStorage = createCallbackStorage();
|
2016-04-15 12:09:07 +00:00
|
|
|
|
2016-04-14 10:00:41 +00:00
|
|
|
if (initOptions && initOptions.adapter === 'cordova') {
|
2016-07-04 11:07:17 +00:00
|
|
|
adapter = loadAdapter('cordova');
|
2016-04-14 09:59:34 +00:00
|
|
|
} else if (initOptions && initOptions.adapter === 'default') {
|
2015-07-17 11:45:43 +00:00
|
|
|
adapter = loadAdapter();
|
2016-04-14 09:59:34 +00:00
|
|
|
} else {
|
2017-10-06 04:24:07 +00:00
|
|
|
if (window.Cordova || window.cordova) {
|
2016-04-14 09:59:34 +00:00
|
|
|
adapter = loadAdapter('cordova');
|
|
|
|
} else {
|
|
|
|
adapter = loadAdapter();
|
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
2016-04-15 12:09:07 +00:00
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
if (initOptions) {
|
2018-02-12 10:00:02 +00:00
|
|
|
if (typeof initOptions.useNonce !== 'undefined') {
|
|
|
|
useNonce = initOptions.useNonce;
|
|
|
|
}
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
if (typeof initOptions.checkLoginIframe !== 'undefined') {
|
|
|
|
loginIframe.enable = initOptions.checkLoginIframe;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initOptions.checkLoginIframeInterval) {
|
|
|
|
loginIframe.interval = initOptions.checkLoginIframeInterval;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initOptions.onLoad === 'login-required') {
|
|
|
|
kc.loginRequired = true;
|
|
|
|
}
|
2015-11-24 13:26:41 +00:00
|
|
|
|
|
|
|
if (initOptions.responseMode) {
|
|
|
|
if (initOptions.responseMode === 'query' || initOptions.responseMode === 'fragment') {
|
|
|
|
kc.responseMode = initOptions.responseMode;
|
|
|
|
} else {
|
|
|
|
throw 'Invalid value for responseMode';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initOptions.flow) {
|
|
|
|
switch (initOptions.flow) {
|
|
|
|
case 'standard':
|
|
|
|
kc.responseType = 'code';
|
|
|
|
break;
|
|
|
|
case 'implicit':
|
2015-11-27 07:29:50 +00:00
|
|
|
kc.responseType = 'id_token token';
|
2015-11-24 13:26:41 +00:00
|
|
|
break;
|
|
|
|
case 'hybrid':
|
2015-11-27 07:29:50 +00:00
|
|
|
kc.responseType = 'code id_token token';
|
2015-11-24 13:26:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw 'Invalid value for flow';
|
|
|
|
}
|
2015-11-27 07:29:50 +00:00
|
|
|
kc.flow = initOptions.flow;
|
2015-11-24 13:26:41 +00:00
|
|
|
}
|
2017-02-02 09:57:03 +00:00
|
|
|
|
|
|
|
if (initOptions.timeSkew != null) {
|
|
|
|
kc.timeSkew = initOptions.timeSkew;
|
|
|
|
}
|
2015-11-24 13:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!kc.responseMode) {
|
|
|
|
kc.responseMode = 'fragment';
|
|
|
|
}
|
|
|
|
if (!kc.responseType) {
|
|
|
|
kc.responseType = 'code';
|
2015-11-27 07:29:50 +00:00
|
|
|
kc.flow = 'standard';
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var promise = createPromise();
|
|
|
|
|
|
|
|
var initPromise = createPromise();
|
|
|
|
initPromise.promise.success(function() {
|
|
|
|
kc.onReady && kc.onReady(kc.authenticated);
|
|
|
|
promise.setSuccess(kc.authenticated);
|
2016-07-14 21:55:27 +00:00
|
|
|
}).error(function(errorData) {
|
|
|
|
promise.setError(errorData);
|
2015-07-17 11:45:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var configPromise = loadConfig(config);
|
|
|
|
|
|
|
|
function onLoad() {
|
|
|
|
var doLogin = function(prompt) {
|
|
|
|
if (!prompt) {
|
|
|
|
options.prompt = 'none';
|
|
|
|
}
|
|
|
|
kc.login(options).success(function () {
|
|
|
|
initPromise.setSuccess();
|
|
|
|
}).error(function () {
|
|
|
|
initPromise.setError();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var options = {};
|
|
|
|
switch (initOptions.onLoad) {
|
|
|
|
case 'check-sso':
|
|
|
|
if (loginIframe.enable) {
|
|
|
|
setupCheckLoginIframe().success(function() {
|
|
|
|
checkLoginIframe().success(function () {
|
|
|
|
doLogin(false);
|
|
|
|
}).error(function () {
|
|
|
|
initPromise.setSuccess();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
doLogin(false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'login-required':
|
|
|
|
doLogin(true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw 'Invalid value for onLoad';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function processInit() {
|
|
|
|
var callback = parseCallback(window.location.href);
|
|
|
|
|
|
|
|
if (callback) {
|
2018-02-12 13:48:46 +00:00
|
|
|
window.history.replaceState({}, null, callback.newUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (callback && callback.valid) {
|
2017-10-13 14:18:34 +00:00
|
|
|
return setupCheckLoginIframe().success(function() {
|
|
|
|
processCallback(callback, initPromise);
|
|
|
|
}).error(function (e) {
|
2017-12-01 13:19:51 +00:00
|
|
|
initPromise.setError();
|
2017-10-13 14:18:34 +00:00
|
|
|
});
|
2015-07-17 11:45:43 +00:00
|
|
|
} else if (initOptions) {
|
2017-04-21 11:39:53 +00:00
|
|
|
if (initOptions.token && initOptions.refreshToken) {
|
2016-09-06 11:00:37 +00:00
|
|
|
setToken(initOptions.token, initOptions.refreshToken, initOptions.idToken);
|
2015-07-17 11:45:43 +00:00
|
|
|
|
|
|
|
if (loginIframe.enable) {
|
|
|
|
setupCheckLoginIframe().success(function() {
|
|
|
|
checkLoginIframe().success(function () {
|
2016-09-06 06:59:58 +00:00
|
|
|
kc.onAuthSuccess && kc.onAuthSuccess();
|
2015-07-17 11:45:43 +00:00
|
|
|
initPromise.setSuccess();
|
|
|
|
}).error(function () {
|
2017-02-02 09:57:03 +00:00
|
|
|
setToken(null, null, null);
|
|
|
|
initPromise.setSuccess();
|
2015-07-17 11:45:43 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
2016-09-06 06:59:58 +00:00
|
|
|
kc.updateToken(-1).success(function() {
|
|
|
|
kc.onAuthSuccess && kc.onAuthSuccess();
|
|
|
|
initPromise.setSuccess();
|
|
|
|
}).error(function() {
|
|
|
|
kc.onAuthError && kc.onAuthError();
|
|
|
|
if (initOptions.onLoad) {
|
|
|
|
onLoad();
|
2016-09-15 21:25:29 +00:00
|
|
|
} else {
|
|
|
|
initPromise.setError();
|
2016-09-06 06:59:58 +00:00
|
|
|
}
|
|
|
|
});
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
} else if (initOptions.onLoad) {
|
|
|
|
onLoad();
|
2016-03-18 11:06:28 +00:00
|
|
|
} else {
|
|
|
|
initPromise.setSuccess();
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
initPromise.setSuccess();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
configPromise.success(processInit);
|
|
|
|
configPromise.error(function() {
|
|
|
|
promise.setError();
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.login = function (options) {
|
|
|
|
return adapter.login(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.createLoginUrl = function(options) {
|
|
|
|
var state = createUUID();
|
2015-11-24 13:26:41 +00:00
|
|
|
var nonce = createUUID();
|
2015-07-17 11:45:43 +00:00
|
|
|
|
|
|
|
var redirectUri = adapter.redirectUri(options);
|
2016-10-20 14:06:51 +00:00
|
|
|
|
|
|
|
var callbackState = {
|
|
|
|
state: state,
|
|
|
|
nonce: nonce,
|
2017-08-22 06:10:09 +00:00
|
|
|
redirectUri: encodeURIComponent(redirectUri)
|
2016-10-20 14:06:51 +00:00
|
|
|
}
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
if (options && options.prompt) {
|
2016-10-20 14:06:51 +00:00
|
|
|
callbackState.prompt = options.prompt;
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 14:06:51 +00:00
|
|
|
callbackStorage.add(callbackState);
|
2015-07-17 11:45:43 +00:00
|
|
|
|
2018-02-12 10:00:02 +00:00
|
|
|
var baseUrl;
|
2015-07-17 11:45:43 +00:00
|
|
|
if (options && options.action == 'register') {
|
2018-02-12 10:00:02 +00:00
|
|
|
baseUrl = kc.endpoints.register();
|
|
|
|
} else {
|
|
|
|
baseUrl = kc.endpoints.authorize();
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 17:31:07 +00:00
|
|
|
var scope = (options && options.scope) ? "openid " + options.scope : "openid";
|
|
|
|
|
2018-02-12 10:00:02 +00:00
|
|
|
var url = baseUrl
|
2015-07-17 11:45:43 +00:00
|
|
|
+ '?client_id=' + encodeURIComponent(kc.clientId)
|
|
|
|
+ '&redirect_uri=' + encodeURIComponent(redirectUri)
|
|
|
|
+ '&state=' + encodeURIComponent(state)
|
2015-11-24 13:26:41 +00:00
|
|
|
+ '&response_mode=' + encodeURIComponent(kc.responseMode)
|
2016-07-14 17:31:07 +00:00
|
|
|
+ '&response_type=' + encodeURIComponent(kc.responseType)
|
|
|
|
+ '&scope=' + encodeURIComponent(scope);
|
2018-02-12 10:00:02 +00:00
|
|
|
if (useNonce) {
|
|
|
|
url = url + '&nonce=' + encodeURIComponent(nonce);
|
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
|
|
|
|
if (options && options.prompt) {
|
2015-11-09 15:27:33 +00:00
|
|
|
url += '&prompt=' + encodeURIComponent(options.prompt);
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:18:05 +00:00
|
|
|
if (options && options.maxAge) {
|
|
|
|
url += '&max_age=' + encodeURIComponent(options.maxAge);
|
|
|
|
}
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
if (options && options.loginHint) {
|
2015-11-09 15:27:33 +00:00
|
|
|
url += '&login_hint=' + encodeURIComponent(options.loginHint);
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options && options.idpHint) {
|
2015-11-09 15:27:33 +00:00
|
|
|
url += '&kc_idp_hint=' + encodeURIComponent(options.idpHint);
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
|
2015-10-23 10:23:24 +00:00
|
|
|
if (options && options.locale) {
|
2015-11-09 15:27:33 +00:00
|
|
|
url += '&ui_locales=' + encodeURIComponent(options.locale);
|
2015-10-23 10:23:24 +00:00
|
|
|
}
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.logout = function(options) {
|
|
|
|
return adapter.logout(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.createLogoutUrl = function(options) {
|
2018-02-12 10:00:02 +00:00
|
|
|
var url = kc.endpoints.logout()
|
2016-02-06 16:43:38 +00:00
|
|
|
+ '?redirect_uri=' + encodeURIComponent(adapter.redirectUri(options, false));
|
2015-07-17 11:45:43 +00:00
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2015-10-07 11:53:25 +00:00
|
|
|
kc.register = function (options) {
|
|
|
|
return adapter.register(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.createRegisterUrl = function(options) {
|
|
|
|
if (!options) {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
options.action = 'register';
|
|
|
|
return kc.createLoginUrl(options);
|
|
|
|
}
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
kc.createAccountUrl = function(options) {
|
2018-02-12 10:00:02 +00:00
|
|
|
var realm = getRealmUrl();
|
|
|
|
var url = undefined;
|
|
|
|
if (typeof realm !== 'undefined') {
|
|
|
|
url = realm
|
2015-07-17 11:45:43 +00:00
|
|
|
+ '/account'
|
|
|
|
+ '?referrer=' + encodeURIComponent(kc.clientId)
|
|
|
|
+ '&referrer_uri=' + encodeURIComponent(adapter.redirectUri(options));
|
2018-02-12 10:00:02 +00:00
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.accountManagement = function() {
|
|
|
|
return adapter.accountManagement();
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.hasRealmRole = function (role) {
|
|
|
|
var access = kc.realmAccess;
|
|
|
|
return !!access && access.roles.indexOf(role) >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.hasResourceRole = function(role, resource) {
|
|
|
|
if (!kc.resourceAccess) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var access = kc.resourceAccess[resource || kc.clientId];
|
|
|
|
return !!access && access.roles.indexOf(role) >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.loadUserProfile = function() {
|
|
|
|
var url = getRealmUrl() + '/account';
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
req.open('GET', url, true);
|
|
|
|
req.setRequestHeader('Accept', 'application/json');
|
|
|
|
req.setRequestHeader('Authorization', 'bearer ' + kc.token);
|
|
|
|
|
|
|
|
var promise = createPromise();
|
|
|
|
|
|
|
|
req.onreadystatechange = function () {
|
|
|
|
if (req.readyState == 4) {
|
|
|
|
if (req.status == 200) {
|
|
|
|
kc.profile = JSON.parse(req.responseText);
|
|
|
|
promise.setSuccess(kc.profile);
|
|
|
|
} else {
|
|
|
|
promise.setError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
req.send();
|
|
|
|
|
|
|
|
return promise.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.loadUserInfo = function() {
|
2018-02-12 10:00:02 +00:00
|
|
|
var url = kc.endpoints.userinfo();
|
2015-07-17 11:45:43 +00:00
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
req.open('GET', url, true);
|
|
|
|
req.setRequestHeader('Accept', 'application/json');
|
|
|
|
req.setRequestHeader('Authorization', 'bearer ' + kc.token);
|
|
|
|
|
|
|
|
var promise = createPromise();
|
|
|
|
|
|
|
|
req.onreadystatechange = function () {
|
|
|
|
if (req.readyState == 4) {
|
|
|
|
if (req.status == 200) {
|
|
|
|
kc.userInfo = JSON.parse(req.responseText);
|
|
|
|
promise.setSuccess(kc.userInfo);
|
|
|
|
} else {
|
|
|
|
promise.setError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
req.send();
|
|
|
|
|
|
|
|
return promise.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.isTokenExpired = function(minValidity) {
|
2015-11-27 07:29:50 +00:00
|
|
|
if (!kc.tokenParsed || (!kc.refreshToken && kc.flow != 'implicit' )) {
|
2015-07-17 11:45:43 +00:00
|
|
|
throw 'Not authenticated';
|
|
|
|
}
|
|
|
|
|
2017-02-02 09:57:03 +00:00
|
|
|
if (kc.timeSkew == null) {
|
|
|
|
console.info('[KEYCLOAK] Unable to determine if token is expired as timeskew is not set');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-21 07:13:05 +00:00
|
|
|
var expiresIn = kc.tokenParsed['exp'] - Math.ceil(new Date().getTime() / 1000) + kc.timeSkew;
|
2015-07-17 11:45:43 +00:00
|
|
|
if (minValidity) {
|
|
|
|
expiresIn -= minValidity;
|
|
|
|
}
|
|
|
|
return expiresIn < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.updateToken = function(minValidity) {
|
|
|
|
var promise = createPromise();
|
|
|
|
|
2017-01-10 08:09:50 +00:00
|
|
|
if (!kc.refreshToken) {
|
2015-07-17 11:45:43 +00:00
|
|
|
promise.setError();
|
|
|
|
return promise.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
minValidity = minValidity || 5;
|
|
|
|
|
|
|
|
var exec = function() {
|
2016-09-21 07:13:05 +00:00
|
|
|
var refreshToken = false;
|
2017-01-10 08:09:50 +00:00
|
|
|
if (minValidity == -1) {
|
2016-09-21 07:13:05 +00:00
|
|
|
refreshToken = true;
|
|
|
|
console.info('[KEYCLOAK] Refreshing token: forced refresh');
|
2017-01-10 08:09:50 +00:00
|
|
|
} else if (!kc.tokenParsed || kc.isTokenExpired(minValidity)) {
|
2016-09-21 07:13:05 +00:00
|
|
|
refreshToken = true;
|
|
|
|
console.info('[KEYCLOAK] Refreshing token: token expired');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!refreshToken) {
|
2015-07-17 11:45:43 +00:00
|
|
|
promise.setSuccess(false);
|
|
|
|
} else {
|
|
|
|
var params = 'grant_type=refresh_token&' + 'refresh_token=' + kc.refreshToken;
|
2018-02-12 10:00:02 +00:00
|
|
|
var url = kc.endpoints.token();
|
2015-07-17 11:45:43 +00:00
|
|
|
|
|
|
|
refreshQueue.push(promise);
|
|
|
|
|
|
|
|
if (refreshQueue.length == 1) {
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
req.open('POST', url, true);
|
|
|
|
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
2016-08-26 15:23:44 +00:00
|
|
|
req.withCredentials = true;
|
2015-07-17 11:45:43 +00:00
|
|
|
|
|
|
|
if (kc.clientId && kc.clientSecret) {
|
|
|
|
req.setRequestHeader('Authorization', 'Basic ' + btoa(kc.clientId + ':' + kc.clientSecret));
|
|
|
|
} else {
|
|
|
|
params += '&client_id=' + encodeURIComponent(kc.clientId);
|
|
|
|
}
|
|
|
|
|
2015-08-20 11:29:32 +00:00
|
|
|
var timeLocal = new Date().getTime();
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
req.onreadystatechange = function () {
|
|
|
|
if (req.readyState == 4) {
|
|
|
|
if (req.status == 200) {
|
2016-09-21 07:13:05 +00:00
|
|
|
console.info('[KEYCLOAK] Token refreshed');
|
|
|
|
|
2015-08-20 11:29:32 +00:00
|
|
|
timeLocal = (timeLocal + new Date().getTime()) / 2;
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
var tokenResponse = JSON.parse(req.responseText);
|
2015-08-20 11:29:32 +00:00
|
|
|
|
2016-09-21 07:13:05 +00:00
|
|
|
setToken(tokenResponse['access_token'], tokenResponse['refresh_token'], tokenResponse['id_token'], timeLocal);
|
2016-09-06 11:00:37 +00:00
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
kc.onAuthRefreshSuccess && kc.onAuthRefreshSuccess();
|
|
|
|
for (var p = refreshQueue.pop(); p != null; p = refreshQueue.pop()) {
|
|
|
|
p.setSuccess(true);
|
|
|
|
}
|
|
|
|
} else {
|
2016-09-21 07:13:05 +00:00
|
|
|
console.warn('[KEYCLOAK] Failed to refresh token');
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
kc.onAuthRefreshError && kc.onAuthRefreshError();
|
|
|
|
for (var p = refreshQueue.pop(); p != null; p = refreshQueue.pop()) {
|
|
|
|
p.setError(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.send(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loginIframe.enable) {
|
|
|
|
var iframePromise = checkLoginIframe();
|
|
|
|
iframePromise.success(function() {
|
|
|
|
exec();
|
|
|
|
}).error(function() {
|
|
|
|
promise.setError();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
return promise.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.clearToken = function() {
|
|
|
|
if (kc.token) {
|
2016-09-06 11:00:37 +00:00
|
|
|
setToken(null, null, null);
|
2015-07-17 11:45:43 +00:00
|
|
|
kc.onAuthLogout && kc.onAuthLogout();
|
|
|
|
if (kc.loginRequired) {
|
|
|
|
kc.login();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getRealmUrl() {
|
2018-02-12 10:00:02 +00:00
|
|
|
if (typeof kc.authServerUrl !== 'undefined') {
|
|
|
|
if (kc.authServerUrl.charAt(kc.authServerUrl.length - 1) == '/') {
|
|
|
|
return kc.authServerUrl + 'realms/' + encodeURIComponent(kc.realm);
|
|
|
|
} else {
|
|
|
|
return kc.authServerUrl + '/realms/' + encodeURIComponent(kc.realm);
|
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
} else {
|
2018-02-12 10:00:02 +00:00
|
|
|
return undefined;
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getOrigin() {
|
|
|
|
if (!window.location.origin) {
|
|
|
|
return window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
|
|
|
|
} else {
|
|
|
|
return window.location.origin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function processCallback(oauth, promise) {
|
|
|
|
var code = oauth.code;
|
|
|
|
var error = oauth.error;
|
|
|
|
var prompt = oauth.prompt;
|
|
|
|
|
2015-11-24 13:26:41 +00:00
|
|
|
var timeLocal = new Date().getTime();
|
|
|
|
|
2015-11-27 07:29:50 +00:00
|
|
|
if (error) {
|
|
|
|
if (prompt != 'none') {
|
2016-07-14 21:55:27 +00:00
|
|
|
var errorData = { error: error, error_description: oauth.error_description };
|
|
|
|
kc.onAuthError && kc.onAuthError(errorData);
|
|
|
|
promise && promise.setError(errorData);
|
2015-11-27 07:29:50 +00:00
|
|
|
} else {
|
|
|
|
promise && promise.setSuccess();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if ((kc.flow != 'standard') && (oauth.access_token || oauth.id_token)) {
|
|
|
|
authSuccess(oauth.access_token, null, oauth.id_token, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((kc.flow != 'implicit') && code) {
|
2015-07-17 11:45:43 +00:00
|
|
|
var params = 'code=' + code + '&grant_type=authorization_code';
|
2018-02-12 10:00:02 +00:00
|
|
|
var url = kc.endpoints.token();
|
2015-07-17 11:45:43 +00:00
|
|
|
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
req.open('POST', url, true);
|
|
|
|
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
|
|
|
|
|
|
|
if (kc.clientId && kc.clientSecret) {
|
|
|
|
req.setRequestHeader('Authorization', 'Basic ' + btoa(kc.clientId + ':' + kc.clientSecret));
|
|
|
|
} else {
|
|
|
|
params += '&client_id=' + encodeURIComponent(kc.clientId);
|
|
|
|
}
|
|
|
|
|
|
|
|
params += '&redirect_uri=' + oauth.redirectUri;
|
|
|
|
|
|
|
|
req.withCredentials = true;
|
|
|
|
|
|
|
|
req.onreadystatechange = function() {
|
|
|
|
if (req.readyState == 4) {
|
|
|
|
if (req.status == 200) {
|
2015-08-20 11:29:32 +00:00
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
var tokenResponse = JSON.parse(req.responseText);
|
2015-11-27 07:29:50 +00:00
|
|
|
authSuccess(tokenResponse['access_token'], tokenResponse['refresh_token'], tokenResponse['id_token'], kc.flow === 'standard');
|
2015-07-17 11:45:43 +00:00
|
|
|
} else {
|
|
|
|
kc.onAuthError && kc.onAuthError();
|
|
|
|
promise && promise.setError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.send(params);
|
|
|
|
}
|
2015-11-24 13:26:41 +00:00
|
|
|
|
2015-11-27 07:29:50 +00:00
|
|
|
function authSuccess(accessToken, refreshToken, idToken, fulfillPromise) {
|
2015-11-24 13:26:41 +00:00
|
|
|
timeLocal = (timeLocal + new Date().getTime()) / 2;
|
|
|
|
|
2016-09-21 07:13:05 +00:00
|
|
|
setToken(accessToken, refreshToken, idToken, timeLocal);
|
2015-11-24 13:26:41 +00:00
|
|
|
|
2018-02-12 10:00:02 +00:00
|
|
|
if (useNonce && ((kc.tokenParsed && kc.tokenParsed.nonce != oauth.storedNonce) ||
|
2015-11-24 13:26:41 +00:00
|
|
|
(kc.refreshTokenParsed && kc.refreshTokenParsed.nonce != oauth.storedNonce) ||
|
2018-02-12 10:00:02 +00:00
|
|
|
(kc.idTokenParsed && kc.idTokenParsed.nonce != oauth.storedNonce))) {
|
2015-11-24 13:26:41 +00:00
|
|
|
|
2016-09-21 07:13:05 +00:00
|
|
|
console.info('[KEYCLOAK] Invalid nonce, clearing token');
|
2015-11-24 13:26:41 +00:00
|
|
|
kc.clearToken();
|
|
|
|
promise && promise.setError();
|
|
|
|
} else {
|
2015-11-27 07:29:50 +00:00
|
|
|
if (fulfillPromise) {
|
|
|
|
kc.onAuthSuccess && kc.onAuthSuccess();
|
|
|
|
promise && promise.setSuccess();
|
|
|
|
}
|
2015-11-24 13:26:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadConfig(url) {
|
|
|
|
var promise = createPromise();
|
|
|
|
var configUrl;
|
|
|
|
|
|
|
|
if (!config) {
|
|
|
|
configUrl = 'keycloak.json';
|
|
|
|
} else if (typeof config === 'string') {
|
|
|
|
configUrl = config;
|
|
|
|
}
|
|
|
|
|
2018-02-12 10:00:02 +00:00
|
|
|
function setupOidcEndoints(oidcConfiguration) {
|
|
|
|
if (! oidcConfiguration) {
|
|
|
|
kc.endpoints = {
|
|
|
|
authorize: function() {
|
|
|
|
return getRealmUrl() + '/protocol/openid-connect/auth';
|
|
|
|
},
|
|
|
|
token: function() {
|
|
|
|
return getRealmUrl() + '/protocol/openid-connect/token';
|
|
|
|
},
|
|
|
|
logout: function() {
|
|
|
|
return getRealmUrl() + '/protocol/openid-connect/logout';
|
|
|
|
},
|
|
|
|
checkSessionIframe: function() {
|
|
|
|
var src = getRealmUrl() + '/protocol/openid-connect/login-status-iframe.html';
|
|
|
|
if (kc.iframeVersion) {
|
|
|
|
src = src + '?version=' + kc.iframeVersion;
|
|
|
|
}
|
|
|
|
return src;
|
|
|
|
},
|
|
|
|
register: function() {
|
|
|
|
return getRealmUrl() + '/protocol/openid-connect/registrations';
|
|
|
|
},
|
|
|
|
userinfo: function() {
|
|
|
|
return getRealmUrl() + '/protocol/openid-connect/userinfo';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
kc.endpoints = {
|
|
|
|
authorize: function() {
|
|
|
|
return oidcConfiguration.authorization_endpoint;
|
|
|
|
},
|
|
|
|
token: function() {
|
|
|
|
return oidcConfiguration.token_endpoint;
|
|
|
|
},
|
|
|
|
logout: function() {
|
|
|
|
if (!oidcConfiguration.end_session_endpoint) {
|
|
|
|
throw "Not supported by the OIDC server";
|
|
|
|
}
|
|
|
|
return oidcConfiguration.end_session_endpoint;
|
|
|
|
},
|
|
|
|
checkSessionIframe: function() {
|
|
|
|
if (!oidcConfiguration.check_session_iframe) {
|
|
|
|
throw "Not supported by the OIDC server";
|
|
|
|
}
|
|
|
|
return oidcConfiguration.check_session_iframe;
|
|
|
|
},
|
|
|
|
register: function() {
|
|
|
|
throw 'Redirection to "Register user" page not supported in standard OIDC mode';
|
|
|
|
},
|
|
|
|
userinfo: function() {
|
|
|
|
if (!oidcConfiguration.userinfo_endpoint) {
|
|
|
|
throw "Not supported by the OIDC server";
|
|
|
|
}
|
|
|
|
return oidcConfiguration.userinfo_endpoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
if (configUrl) {
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
req.open('GET', configUrl, true);
|
|
|
|
req.setRequestHeader('Accept', 'application/json');
|
|
|
|
|
|
|
|
req.onreadystatechange = function () {
|
|
|
|
if (req.readyState == 4) {
|
2017-05-01 19:19:24 +00:00
|
|
|
if (req.status == 200 || fileLoaded(req)) {
|
2015-07-17 11:45:43 +00:00
|
|
|
var config = JSON.parse(req.responseText);
|
|
|
|
|
|
|
|
kc.authServerUrl = config['auth-server-url'];
|
|
|
|
kc.realm = config['realm'];
|
|
|
|
kc.clientId = config['resource'];
|
|
|
|
kc.clientSecret = (config['credentials'] || {})['secret'];
|
2018-02-12 10:00:02 +00:00
|
|
|
setupOidcEndoints(null);
|
2015-07-17 11:45:43 +00:00
|
|
|
promise.setSuccess();
|
|
|
|
} else {
|
|
|
|
promise.setError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.send();
|
|
|
|
} else {
|
|
|
|
if (!config.clientId) {
|
|
|
|
throw 'clientId missing';
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.clientId = config.clientId;
|
|
|
|
kc.clientSecret = (config.credentials || {}).secret;
|
|
|
|
|
2018-02-12 10:00:02 +00:00
|
|
|
var oidcProvider = config['oidcProvider'];
|
|
|
|
if (!oidcProvider) {
|
|
|
|
if (!config['url']) {
|
|
|
|
var scripts = document.getElementsByTagName('script');
|
|
|
|
for (var i = 0; i < scripts.length; i++) {
|
|
|
|
if (scripts[i].src.match(/.*keycloak\.js/)) {
|
|
|
|
config.url = scripts[i].src.substr(0, scripts[i].src.indexOf('/js/keycloak.js'));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!config.realm) {
|
|
|
|
throw 'realm missing';
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.authServerUrl = config.url;
|
|
|
|
kc.realm = config.realm;
|
|
|
|
setupOidcEndoints(null);
|
|
|
|
promise.setSuccess();
|
|
|
|
} else {
|
|
|
|
if (typeof oidcProvider === 'string') {
|
|
|
|
var oidcProviderConfigUrl;
|
|
|
|
if (oidcProvider.charAt(oidcProvider.length - 1) == '/') {
|
|
|
|
oidcProviderConfigUrl = oidcProvider + '.well-known/openid-configuration';
|
|
|
|
} else {
|
|
|
|
oidcProviderConfigUrl = oidcProvider + '/.well-known/openid-configuration';
|
|
|
|
}
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
req.open('GET', oidcProviderConfigUrl, true);
|
|
|
|
req.setRequestHeader('Accept', 'application/json');
|
|
|
|
|
|
|
|
req.onreadystatechange = function () {
|
|
|
|
if (req.readyState == 4) {
|
|
|
|
if (req.status == 200 || fileLoaded(req)) {
|
|
|
|
var oidcProviderConfig = JSON.parse(req.responseText);
|
|
|
|
setupOidcEndoints(oidcProviderConfig);
|
|
|
|
promise.setSuccess();
|
|
|
|
} else {
|
|
|
|
promise.setError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
req.send();
|
|
|
|
} else {
|
|
|
|
setupOidcEndoints(oidcProvider);
|
|
|
|
promise.setSuccess();
|
|
|
|
}
|
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return promise.promise;
|
|
|
|
}
|
|
|
|
|
2017-05-01 19:19:24 +00:00
|
|
|
function fileLoaded(xhr) {
|
|
|
|
return xhr.status == 0 && xhr.responseText && xhr.responseURL.startsWith('file:');
|
|
|
|
}
|
|
|
|
|
2016-09-21 07:13:05 +00:00
|
|
|
function setToken(token, refreshToken, idToken, timeLocal) {
|
2015-11-27 07:29:50 +00:00
|
|
|
if (kc.tokenTimeoutHandle) {
|
|
|
|
clearTimeout(kc.tokenTimeoutHandle);
|
|
|
|
kc.tokenTimeoutHandle = null;
|
|
|
|
}
|
|
|
|
|
2017-01-10 08:09:50 +00:00
|
|
|
if (refreshToken) {
|
|
|
|
kc.refreshToken = refreshToken;
|
|
|
|
kc.refreshTokenParsed = decodeToken(refreshToken);
|
|
|
|
} else {
|
|
|
|
delete kc.refreshToken;
|
|
|
|
delete kc.refreshTokenParsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (idToken) {
|
|
|
|
kc.idToken = idToken;
|
|
|
|
kc.idTokenParsed = decodeToken(idToken);
|
|
|
|
} else {
|
|
|
|
delete kc.idToken;
|
|
|
|
delete kc.idTokenParsed;
|
|
|
|
}
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
if (token) {
|
|
|
|
kc.token = token;
|
|
|
|
kc.tokenParsed = decodeToken(token);
|
2017-02-01 13:01:10 +00:00
|
|
|
kc.sessionId = kc.tokenParsed.session_state;
|
2015-07-17 11:45:43 +00:00
|
|
|
kc.authenticated = true;
|
|
|
|
kc.subject = kc.tokenParsed.sub;
|
|
|
|
kc.realmAccess = kc.tokenParsed.realm_access;
|
|
|
|
kc.resourceAccess = kc.tokenParsed.resource_access;
|
2015-11-27 07:29:50 +00:00
|
|
|
|
2016-09-21 07:13:05 +00:00
|
|
|
if (timeLocal) {
|
|
|
|
kc.timeSkew = Math.floor(timeLocal / 1000) - kc.tokenParsed.iat;
|
2017-02-02 09:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (kc.timeSkew != null) {
|
2016-09-21 07:13:05 +00:00
|
|
|
console.info('[KEYCLOAK] Estimated time difference between browser and server is ' + kc.timeSkew + ' seconds');
|
|
|
|
|
2017-01-10 08:09:50 +00:00
|
|
|
if (kc.onTokenExpired) {
|
2016-09-21 07:13:05 +00:00
|
|
|
var expiresIn = (kc.tokenParsed['exp'] - (new Date().getTime() / 1000) + kc.timeSkew) * 1000;
|
2017-01-10 08:09:50 +00:00
|
|
|
console.info('[KEYCLOAK] Token expires in ' + Math.round(expiresIn / 1000) + ' s');
|
2016-09-21 07:13:05 +00:00
|
|
|
if (expiresIn <= 0) {
|
|
|
|
kc.onTokenExpired();
|
|
|
|
} else {
|
|
|
|
kc.tokenTimeoutHandle = setTimeout(kc.onTokenExpired, expiresIn);
|
|
|
|
}
|
2016-09-06 11:00:37 +00:00
|
|
|
}
|
2015-11-27 07:29:50 +00:00
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
} else {
|
|
|
|
delete kc.token;
|
|
|
|
delete kc.tokenParsed;
|
|
|
|
delete kc.subject;
|
|
|
|
delete kc.realmAccess;
|
|
|
|
delete kc.resourceAccess;
|
|
|
|
|
|
|
|
kc.authenticated = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function decodeToken(str) {
|
|
|
|
str = str.split('.')[1];
|
|
|
|
|
|
|
|
str = str.replace('/-/g', '+');
|
|
|
|
str = str.replace('/_/g', '/');
|
|
|
|
switch (str.length % 4)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
str += '==';
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
str += '=';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw 'Invalid token';
|
|
|
|
}
|
|
|
|
|
|
|
|
str = (str + '===').slice(0, str.length + (str.length % 4));
|
|
|
|
str = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
|
|
|
|
|
|
str = decodeURIComponent(escape(atob(str)));
|
|
|
|
|
|
|
|
str = JSON.parse(str);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createUUID() {
|
|
|
|
var s = [];
|
|
|
|
var hexDigits = '0123456789abcdef';
|
|
|
|
for (var i = 0; i < 36; i++) {
|
|
|
|
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
|
|
|
}
|
|
|
|
s[14] = '4';
|
|
|
|
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
|
|
|
|
s[8] = s[13] = s[18] = s[23] = '-';
|
|
|
|
var uuid = s.join('');
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
kc.callback_id = 0;
|
|
|
|
|
|
|
|
function createCallbackId() {
|
|
|
|
var id = '<id: ' + (kc.callback_id++) + (Math.random()) + '>';
|
|
|
|
return id;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseCallback(url) {
|
2018-02-12 13:48:46 +00:00
|
|
|
var oauth = parseCallbackUrl(url);
|
|
|
|
if (!oauth) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-04 18:58:15 +00:00
|
|
|
var oauthState = callbackStorage.get(oauth.state);
|
2015-07-17 11:45:43 +00:00
|
|
|
|
2018-02-12 13:48:46 +00:00
|
|
|
if (oauthState) {
|
|
|
|
oauth.valid = true;
|
2016-07-04 18:58:15 +00:00
|
|
|
oauth.redirectUri = oauthState.redirectUri;
|
|
|
|
oauth.storedNonce = oauthState.nonce;
|
2016-10-20 14:06:51 +00:00
|
|
|
oauth.prompt = oauthState.prompt;
|
2018-02-12 13:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return oauth;
|
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
|
2018-02-12 13:48:46 +00:00
|
|
|
function parseCallbackUrl(url) {
|
|
|
|
var supportedParams;
|
|
|
|
switch (kc.flow) {
|
|
|
|
case 'standard':
|
|
|
|
supportedParams = ['code', 'state', 'session_state'];
|
|
|
|
break;
|
|
|
|
case 'implicit':
|
2018-02-27 13:45:26 +00:00
|
|
|
supportedParams = ['access_token', 'id_token', 'state', 'session_state'];
|
2018-02-12 13:48:46 +00:00
|
|
|
break;
|
|
|
|
case 'hybrid':
|
2018-02-27 13:45:26 +00:00
|
|
|
supportedParams = ['access_token', 'id_token', 'code', 'state', 'session_state'];
|
2018-02-12 13:48:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
supportedParams.push('error');
|
|
|
|
supportedParams.push('error_description');
|
|
|
|
supportedParams.push('error_uri');
|
|
|
|
|
|
|
|
var queryIndex = url.indexOf('?');
|
|
|
|
var fragmentIndex = url.indexOf('#');
|
|
|
|
|
|
|
|
var newUrl;
|
|
|
|
var parsed;
|
|
|
|
|
|
|
|
if (kc.responseMode === 'query' && queryIndex !== -1) {
|
|
|
|
newUrl = url.substring(0, queryIndex);
|
|
|
|
parsed = parseCallbackParams(url.substring(queryIndex + 1, fragmentIndex !== -1 ? fragmentIndex : url.length), supportedParams);
|
|
|
|
if (parsed.paramsString !== '') {
|
|
|
|
newUrl += '?' + parsed.paramsString;
|
|
|
|
}
|
|
|
|
if (fragmentIndex !== -1) {
|
|
|
|
newUrl += url.substring(fragmentIndex);
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
2018-02-12 13:48:46 +00:00
|
|
|
} else if (kc.responseMode === 'fragment' && fragmentIndex !== -1) {
|
|
|
|
newUrl = url.substring(0, fragmentIndex);
|
|
|
|
parsed = parseCallbackParams(url.substring(fragmentIndex + 1), supportedParams);
|
|
|
|
if (parsed.paramsString !== '') {
|
|
|
|
newUrl += '#' + parsed.paramsString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parsed && parsed.oauthParams) {
|
|
|
|
if (kc.flow === 'standard' || kc.flow === 'hybrid') {
|
|
|
|
if ((parsed.oauthParams.code || parsed.oauthParams.error) && parsed.oauthParams.state) {
|
|
|
|
parsed.oauthParams.newUrl = newUrl;
|
|
|
|
return parsed.oauthParams;
|
|
|
|
}
|
|
|
|
} else if (kc.flow === 'implicit') {
|
|
|
|
if ((parsed.oauthParams.access_token || parsed.oauthParams.error) && parsed.oauthParams.state) {
|
|
|
|
parsed.oauthParams.newUrl = newUrl;
|
|
|
|
return parsed.oauthParams;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-24 13:26:41 +00:00
|
|
|
|
2018-02-12 13:48:46 +00:00
|
|
|
function parseCallbackParams(paramsString, supportedParams) {
|
|
|
|
var p = paramsString.split('&');
|
|
|
|
var result = {
|
|
|
|
paramsString: '',
|
|
|
|
oauthParams: {}
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
2018-02-12 13:48:46 +00:00
|
|
|
for (var i = 0; i < p.length; i++) {
|
|
|
|
var t = p[i].split('=');
|
|
|
|
if (supportedParams.indexOf(t[0]) !== -1) {
|
|
|
|
result.oauthParams[t[0]] = t[1];
|
|
|
|
} else {
|
|
|
|
if (result.paramsString !== '') {
|
|
|
|
result.paramsString += '&';
|
|
|
|
}
|
|
|
|
result.paramsString += p[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function createPromise() {
|
2017-12-24 16:35:11 +00:00
|
|
|
if (typeof Promise === "function") {
|
|
|
|
return createNativePromise();
|
|
|
|
} else {
|
|
|
|
return createLegacyPromise();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createNativePromise() {
|
|
|
|
// Need to create a native Promise which also preserves the
|
|
|
|
// interface of the custom promise type previously used by the API
|
|
|
|
var p = {
|
|
|
|
setSuccess: function(result) {
|
|
|
|
p.success = true;
|
|
|
|
p.resolve(result);
|
|
|
|
},
|
|
|
|
|
|
|
|
setError: function(result) {
|
|
|
|
p.success = false;
|
|
|
|
p.reject(result);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
p.promise = new Promise(function(resolve, reject) {
|
|
|
|
p.resolve = resolve;
|
|
|
|
p.reject = reject;
|
|
|
|
});
|
|
|
|
p.promise.success = function(callback) {
|
|
|
|
p.promise.then(callback);
|
|
|
|
return p.promise;
|
|
|
|
}
|
|
|
|
p.promise.error = function(callback) {
|
|
|
|
p.promise.catch(callback);
|
|
|
|
return p.promise;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createLegacyPromise() {
|
2015-07-17 11:45:43 +00:00
|
|
|
var p = {
|
|
|
|
setSuccess: function(result) {
|
|
|
|
p.success = true;
|
|
|
|
p.result = result;
|
|
|
|
if (p.successCallback) {
|
|
|
|
p.successCallback(result);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setError: function(result) {
|
|
|
|
p.error = true;
|
|
|
|
p.result = result;
|
|
|
|
if (p.errorCallback) {
|
|
|
|
p.errorCallback(result);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
promise: {
|
|
|
|
success: function(callback) {
|
|
|
|
if (p.success) {
|
|
|
|
callback(p.result);
|
|
|
|
} else if (!p.error) {
|
|
|
|
p.successCallback = callback;
|
|
|
|
}
|
|
|
|
return p.promise;
|
|
|
|
},
|
|
|
|
error: function(callback) {
|
|
|
|
if (p.error) {
|
|
|
|
callback(p.result);
|
|
|
|
} else if (!p.success) {
|
|
|
|
p.errorCallback = callback;
|
|
|
|
}
|
|
|
|
return p.promise;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupCheckLoginIframe() {
|
|
|
|
var promise = createPromise();
|
|
|
|
|
|
|
|
if (!loginIframe.enable) {
|
|
|
|
promise.setSuccess();
|
|
|
|
return promise.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loginIframe.iframe) {
|
|
|
|
promise.setSuccess();
|
|
|
|
return promise.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
var iframe = document.createElement('iframe');
|
|
|
|
loginIframe.iframe = iframe;
|
|
|
|
|
|
|
|
iframe.onload = function() {
|
2018-02-12 10:00:02 +00:00
|
|
|
var authUrl = kc.endpoints.authorize();
|
|
|
|
if (authUrl.charAt(0) === '/') {
|
2015-07-17 11:45:43 +00:00
|
|
|
loginIframe.iframeOrigin = getOrigin();
|
|
|
|
} else {
|
2018-02-12 10:00:02 +00:00
|
|
|
loginIframe.iframeOrigin = authUrl.substring(0, authUrl.indexOf('/', 8));
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
promise.setSuccess();
|
|
|
|
|
|
|
|
setTimeout(check, loginIframe.interval * 1000);
|
|
|
|
}
|
|
|
|
|
2018-02-12 10:00:02 +00:00
|
|
|
var src = kc.endpoints.checkSessionIframe();
|
2015-07-17 11:45:43 +00:00
|
|
|
iframe.setAttribute('src', src );
|
2017-08-22 06:07:04 +00:00
|
|
|
iframe.setAttribute('title', 'keycloak-session-iframe' );
|
2015-07-17 11:45:43 +00:00
|
|
|
iframe.style.display = 'none';
|
|
|
|
document.body.appendChild(iframe);
|
|
|
|
|
|
|
|
var messageCallback = function(event) {
|
2017-04-07 13:30:54 +00:00
|
|
|
if ((event.origin !== loginIframe.iframeOrigin) || (loginIframe.iframe.contentWindow !== event.source)) {
|
2016-07-04 11:07:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-06 06:49:32 +00:00
|
|
|
if (!(event.data == 'unchanged' || event.data == 'changed' || event.data == 'error')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (event.data != 'unchanged') {
|
2016-10-19 10:07:31 +00:00
|
|
|
kc.clearToken();
|
|
|
|
}
|
2016-10-17 12:05:36 +00:00
|
|
|
|
2016-12-02 12:30:53 +00:00
|
|
|
var callbacks = loginIframe.callbackList.splice(0, loginIframe.callbackList.length);
|
|
|
|
|
|
|
|
for (var i = callbacks.length - 1; i >= 0; --i) {
|
|
|
|
var promise = callbacks[i];
|
2017-04-06 06:49:32 +00:00
|
|
|
if (event.data == 'unchanged') {
|
2016-10-17 12:05:36 +00:00
|
|
|
promise.setSuccess();
|
|
|
|
} else {
|
|
|
|
promise.setError();
|
|
|
|
}
|
2016-07-04 11:07:17 +00:00
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
};
|
2016-10-19 10:07:31 +00:00
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
window.addEventListener('message', messageCallback, false);
|
|
|
|
|
|
|
|
var check = function() {
|
|
|
|
checkLoginIframe();
|
|
|
|
if (kc.token) {
|
|
|
|
setTimeout(check, loginIframe.interval * 1000);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return promise.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkLoginIframe() {
|
|
|
|
var promise = createPromise();
|
|
|
|
|
2016-10-18 09:50:51 +00:00
|
|
|
if (loginIframe.iframe && loginIframe.iframeOrigin ) {
|
2016-10-19 10:07:31 +00:00
|
|
|
var msg = kc.clientId + ' ' + kc.sessionId;
|
2016-10-17 12:05:36 +00:00
|
|
|
loginIframe.callbackList.push(promise);
|
2015-07-17 11:45:43 +00:00
|
|
|
var origin = loginIframe.iframeOrigin;
|
2016-10-19 10:07:31 +00:00
|
|
|
if (loginIframe.callbackList.length == 1) {
|
|
|
|
loginIframe.iframe.contentWindow.postMessage(msg, origin);
|
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
} else {
|
|
|
|
promise.setSuccess();
|
|
|
|
}
|
|
|
|
|
|
|
|
return promise.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadAdapter(type) {
|
|
|
|
if (!type || type == 'default') {
|
|
|
|
return {
|
|
|
|
login: function(options) {
|
|
|
|
window.location.href = kc.createLoginUrl(options);
|
|
|
|
return createPromise().promise;
|
|
|
|
},
|
|
|
|
|
|
|
|
logout: function(options) {
|
|
|
|
window.location.href = kc.createLogoutUrl(options);
|
|
|
|
return createPromise().promise;
|
|
|
|
},
|
|
|
|
|
2015-10-07 11:53:25 +00:00
|
|
|
register: function(options) {
|
|
|
|
window.location.href = kc.createRegisterUrl(options);
|
|
|
|
return createPromise().promise;
|
|
|
|
},
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
accountManagement : function() {
|
2018-02-12 10:00:02 +00:00
|
|
|
var accountUrl = kc.createAccountUrl();
|
|
|
|
if (typeof accountUrl !== 'undefined') {
|
|
|
|
window.location.href = accountUrl;
|
|
|
|
} else {
|
|
|
|
throw "Not supported by the OIDC server";
|
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
return createPromise().promise;
|
|
|
|
},
|
|
|
|
|
2016-02-06 16:43:38 +00:00
|
|
|
redirectUri: function(options, encodeHash) {
|
|
|
|
if (arguments.length == 1) {
|
|
|
|
encodeHash = true;
|
|
|
|
}
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
if (options && options.redirectUri) {
|
|
|
|
return options.redirectUri;
|
|
|
|
} else if (kc.redirectUri) {
|
|
|
|
return kc.redirectUri;
|
|
|
|
} else {
|
2018-02-12 13:48:46 +00:00
|
|
|
return location.href;
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == 'cordova') {
|
|
|
|
loginIframe.enable = false;
|
2017-10-06 04:24:07 +00:00
|
|
|
var cordovaOpenWindowWrapper = function(loginUrl, target, options) {
|
|
|
|
if (window.cordova && window.cordova.InAppBrowser) {
|
|
|
|
// Use inappbrowser for IOS and Android if available
|
|
|
|
return window.cordova.InAppBrowser.open(loginUrl, target, options);
|
|
|
|
} else {
|
|
|
|
return window.open(loginUrl, target, options);
|
|
|
|
}
|
|
|
|
};
|
2015-07-17 11:45:43 +00:00
|
|
|
return {
|
|
|
|
login: function(options) {
|
|
|
|
var promise = createPromise();
|
|
|
|
|
|
|
|
var o = 'location=no';
|
|
|
|
if (options && options.prompt == 'none') {
|
|
|
|
o += ',hidden=yes';
|
|
|
|
}
|
|
|
|
|
|
|
|
var loginUrl = kc.createLoginUrl(options);
|
2017-10-06 04:24:07 +00:00
|
|
|
var ref = cordovaOpenWindowWrapper(loginUrl, '_blank', o);
|
2016-02-23 12:31:31 +00:00
|
|
|
var completed = false;
|
2015-07-17 11:45:43 +00:00
|
|
|
|
|
|
|
ref.addEventListener('loadstart', function(event) {
|
|
|
|
if (event.url.indexOf('http://localhost') == 0) {
|
2016-02-23 12:31:31 +00:00
|
|
|
var callback = parseCallback(event.url);
|
|
|
|
processCallback(callback, promise);
|
2015-07-17 11:45:43 +00:00
|
|
|
ref.close();
|
2016-02-23 12:31:31 +00:00
|
|
|
completed = true;
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ref.addEventListener('loaderror', function(event) {
|
2016-02-23 12:31:31 +00:00
|
|
|
if (!completed) {
|
|
|
|
if (event.url.indexOf('http://localhost') == 0) {
|
|
|
|
var callback = parseCallback(event.url);
|
|
|
|
processCallback(callback, promise);
|
|
|
|
ref.close();
|
|
|
|
completed = true;
|
|
|
|
} else {
|
|
|
|
promise.setError();
|
|
|
|
ref.close();
|
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise.promise;
|
|
|
|
},
|
|
|
|
|
|
|
|
logout: function(options) {
|
|
|
|
var promise = createPromise();
|
|
|
|
|
|
|
|
var logoutUrl = kc.createLogoutUrl(options);
|
2017-10-06 04:24:07 +00:00
|
|
|
var ref = cordovaOpenWindowWrapper(logoutUrl, '_blank', 'location=no,hidden=yes');
|
2015-07-17 11:45:43 +00:00
|
|
|
|
|
|
|
var error;
|
|
|
|
|
|
|
|
ref.addEventListener('loadstart', function(event) {
|
|
|
|
if (event.url.indexOf('http://localhost') == 0) {
|
|
|
|
ref.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ref.addEventListener('loaderror', function(event) {
|
2016-02-04 08:47:25 +00:00
|
|
|
if (event.url.indexOf('http://localhost') == 0) {
|
|
|
|
ref.close();
|
|
|
|
} else {
|
2015-07-17 11:45:43 +00:00
|
|
|
error = true;
|
|
|
|
ref.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ref.addEventListener('exit', function(event) {
|
|
|
|
if (error) {
|
|
|
|
promise.setError();
|
|
|
|
} else {
|
|
|
|
kc.clearToken();
|
|
|
|
promise.setSuccess();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise.promise;
|
|
|
|
},
|
|
|
|
|
2015-10-07 11:53:25 +00:00
|
|
|
register : function() {
|
|
|
|
var registerUrl = kc.createRegisterUrl();
|
2017-10-06 04:24:07 +00:00
|
|
|
var ref = cordovaOpenWindowWrapper(registerUrl, '_blank', 'location=no');
|
2015-10-07 11:53:25 +00:00
|
|
|
ref.addEventListener('loadstart', function(event) {
|
|
|
|
if (event.url.indexOf('http://localhost') == 0) {
|
|
|
|
ref.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
accountManagement : function() {
|
|
|
|
var accountUrl = kc.createAccountUrl();
|
2018-02-12 10:00:02 +00:00
|
|
|
if (typeof accountUrl !== 'undefined') {
|
|
|
|
var ref = cordovaOpenWindowWrapper(accountUrl, '_blank', 'location=no');
|
|
|
|
ref.addEventListener('loadstart', function(event) {
|
|
|
|
if (event.url.indexOf('http://localhost') == 0) {
|
|
|
|
ref.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
throw "Not supported by the OIDC server";
|
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
redirectUri: function(options) {
|
|
|
|
return 'http://localhost';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw 'invalid adapter type: ' + type;
|
|
|
|
}
|
2015-11-24 13:26:41 +00:00
|
|
|
|
2016-07-04 18:58:15 +00:00
|
|
|
var LocalStorage = function() {
|
|
|
|
if (!(this instanceof LocalStorage)) {
|
|
|
|
return new LocalStorage();
|
|
|
|
}
|
2015-11-24 13:26:41 +00:00
|
|
|
|
2016-07-04 18:58:15 +00:00
|
|
|
localStorage.setItem('kc-test', 'test');
|
|
|
|
localStorage.removeItem('kc-test');
|
|
|
|
|
|
|
|
var cs = this;
|
|
|
|
|
|
|
|
function clearExpired() {
|
|
|
|
var time = new Date().getTime();
|
2016-10-28 08:02:11 +00:00
|
|
|
for (var i = 0; i < localStorage.length; i++) {
|
2016-07-04 18:58:15 +00:00
|
|
|
var key = localStorage.key(i);
|
|
|
|
if (key && key.indexOf('kc-callback-') == 0) {
|
|
|
|
var value = localStorage.getItem(key);
|
|
|
|
if (value) {
|
|
|
|
try {
|
|
|
|
var expires = JSON.parse(value).expires;
|
|
|
|
if (!expires || expires < time) {
|
|
|
|
localStorage.removeItem(key);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
localStorage.removeItem(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-15 12:09:07 +00:00
|
|
|
}
|
2016-07-04 18:58:15 +00:00
|
|
|
|
|
|
|
cs.get = function(state) {
|
|
|
|
if (!state) {
|
|
|
|
return;
|
2016-04-15 12:09:07 +00:00
|
|
|
}
|
2016-07-04 18:58:15 +00:00
|
|
|
|
|
|
|
var key = 'kc-callback-' + state;
|
|
|
|
var value = localStorage.getItem(key);
|
|
|
|
if (value) {
|
2016-04-15 12:09:07 +00:00
|
|
|
localStorage.removeItem(key);
|
2016-07-04 18:58:15 +00:00
|
|
|
value = JSON.parse(value);
|
2016-04-15 12:09:07 +00:00
|
|
|
}
|
|
|
|
|
2016-07-04 18:58:15 +00:00
|
|
|
clearExpired();
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
|
|
|
|
cs.add = function(state) {
|
|
|
|
clearExpired();
|
|
|
|
|
|
|
|
var key = 'kc-callback-' + state.state;
|
|
|
|
state.expires = new Date().getTime() + (60 * 60 * 1000);
|
|
|
|
localStorage.setItem(key, JSON.stringify(state));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
var CookieStorage = function() {
|
|
|
|
if (!(this instanceof CookieStorage)) {
|
|
|
|
return new CookieStorage();
|
2016-04-15 12:09:07 +00:00
|
|
|
}
|
2016-09-06 06:59:58 +00:00
|
|
|
|
2016-07-04 18:58:15 +00:00
|
|
|
var cs = this;
|
2016-04-15 12:09:07 +00:00
|
|
|
|
2016-07-04 18:58:15 +00:00
|
|
|
cs.get = function(state) {
|
|
|
|
if (!state) {
|
|
|
|
return;
|
2016-04-15 12:09:07 +00:00
|
|
|
}
|
|
|
|
|
2016-07-04 18:58:15 +00:00
|
|
|
var value = getCookie('kc-callback-' + state);
|
|
|
|
setCookie('kc-callback-' + state, '', cookieExpiration(-100));
|
|
|
|
if (value) {
|
|
|
|
return JSON.parse(value);
|
2016-04-15 12:09:07 +00:00
|
|
|
}
|
2016-07-04 18:58:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cs.add = function(state) {
|
|
|
|
setCookie('kc-callback-' + state.state, JSON.stringify(state), cookieExpiration(60));
|
|
|
|
};
|
|
|
|
|
|
|
|
cs.removeItem = function(key) {
|
2016-04-15 12:09:07 +00:00
|
|
|
setCookie(key, '', cookieExpiration(-100));
|
2016-07-04 18:58:15 +00:00
|
|
|
};
|
2016-04-15 12:09:07 +00:00
|
|
|
|
|
|
|
var cookieExpiration = function (minutes) {
|
|
|
|
var exp = new Date();
|
|
|
|
exp.setTime(exp.getTime() + (minutes*60*1000));
|
|
|
|
return exp;
|
2016-07-04 18:58:15 +00:00
|
|
|
};
|
2016-04-15 12:09:07 +00:00
|
|
|
|
|
|
|
var getCookie = function (key) {
|
|
|
|
var name = key + '=';
|
|
|
|
var ca = document.cookie.split(';');
|
|
|
|
for (var i = 0; i < ca.length; i++) {
|
|
|
|
var c = ca[i];
|
|
|
|
while (c.charAt(0) == ' ') {
|
|
|
|
c = c.substring(1);
|
|
|
|
}
|
|
|
|
if (c.indexOf(name) == 0) {
|
|
|
|
return c.substring(name.length, c.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '';
|
2016-07-04 18:58:15 +00:00
|
|
|
};
|
2016-04-15 12:09:07 +00:00
|
|
|
|
|
|
|
var setCookie = function (key, value, expirationDate) {
|
|
|
|
var cookie = key + '=' + value + '; '
|
|
|
|
+ 'expires=' + expirationDate.toUTCString() + '; ';
|
|
|
|
document.cookie = cookie;
|
|
|
|
}
|
2016-07-04 18:58:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function createCallbackStorage() {
|
|
|
|
try {
|
|
|
|
return new LocalStorage();
|
|
|
|
} catch (err) {
|
|
|
|
}
|
|
|
|
|
|
|
|
return new CookieStorage();
|
2016-04-15 12:09:07 +00:00
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( typeof module === "object" && module && typeof module.exports === "object" ) {
|
|
|
|
module.exports = Keycloak;
|
|
|
|
} else {
|
|
|
|
window.Keycloak = Keycloak;
|
|
|
|
|
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
define( "keycloak", [], function () { return Keycloak; } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})( window );
|