keycloak-js
Advanced tools
Comparing version 4.1.0 to 4.2.0
{ | ||
"name": "keycloak", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"main": "dist/keycloak.js", | ||
@@ -5,0 +5,0 @@ "ignore": [ |
@@ -32,3 +32,3 @@ /* | ||
declare namespace Keycloak { | ||
type KeycloakAdapterName = 'cordova'|'default' | any; | ||
type KeycloakAdapterName = 'cordova' | 'cordova-native' |'default' | any; | ||
type KeycloakOnLoad = 'login-required'|'check-sso'; | ||
@@ -103,2 +103,8 @@ type KeycloakResponseMode = 'query'|'fragment'; | ||
/** | ||
* Specifies a default uri to redirect to after login or logout. | ||
* This is currently supported for adapter 'cordova-native' and 'default' | ||
*/ | ||
redirectUri?: string; | ||
/** | ||
* Set the OpenID Connect flow. | ||
@@ -105,0 +111,0 @@ * @default standard |
@@ -49,7 +49,6 @@ /* | ||
callbackStorage = createCallbackStorage(); | ||
var adapters = ['default', 'cordova', 'cordova-native']; | ||
if (initOptions && initOptions.adapter === 'cordova') { | ||
adapter = loadAdapter('cordova'); | ||
} else if (initOptions && initOptions.adapter === 'default') { | ||
adapter = loadAdapter(); | ||
if (initOptions && adapters.indexOf(initOptions.adapter) > -1) { | ||
adapter = loadAdapter(initOptions.adapter); | ||
} else if (initOptions && typeof initOptions.adapter === "object") { | ||
@@ -110,2 +109,6 @@ adapter = initOptions.adapter; | ||
} | ||
if(initOptions.redirectUri) { | ||
kc.redirectUri = initOptions.redirectUri; | ||
} | ||
} | ||
@@ -1344,2 +1347,71 @@ | ||
if (type == 'cordova-native') { | ||
loginIframe.enable = false; | ||
return { | ||
login: function(options) { | ||
var promise = createPromise(); | ||
var loginUrl = kc.createLoginUrl(options); | ||
universalLinks.subscribe('keycloak', function(event) { | ||
universalLinks.unsubscribe('keycloak'); | ||
window.cordova.plugins.browsertab.close(); | ||
var oauth = parseCallback(event.url); | ||
processCallback(oauth, promise); | ||
}); | ||
window.cordova.plugins.browsertab.openUrl(loginUrl); | ||
return promise.promise; | ||
}, | ||
logout: function(options) { | ||
var promise = createPromise(); | ||
var logoutUrl = kc.createLogoutUrl(options); | ||
universalLinks.subscribe('keycloak', function(event) { | ||
universalLinks.unsubscribe('keycloak'); | ||
window.cordova.plugins.browsertab.close(); | ||
kc.clearToken(); | ||
promise.setSuccess(); | ||
}); | ||
window.cordova.plugins.browsertab.openUrl(logoutUrl); | ||
return promise.promise; | ||
}, | ||
register : function(options) { | ||
var promise = createPromise(); | ||
var registerUrl = kc.createRegisterUrl(options); | ||
universalLinks.subscribe('keycloak' , function(event) { | ||
universalLinks.unsubscribe('keycloak'); | ||
window.cordova.plugins.browsertab.close(); | ||
var oauth = parseCallback(event.url); | ||
processCallback(oauth, promise); | ||
}); | ||
window.cordova.plugins.browsertab.openUrl(registerUrl); | ||
return promise.promise; | ||
}, | ||
accountManagement : function() { | ||
var accountUrl = kc.createAccountUrl(); | ||
if (typeof accountUrl !== 'undefined') { | ||
window.cordova.plugins.browsertab.openUrl(accountUrl); | ||
} else { | ||
throw "Not supported by the OIDC server"; | ||
} | ||
}, | ||
redirectUri: function(options) { | ||
if (options && options.redirectUri) { | ||
return options.redirectUri; | ||
} else if (kc.redirectUri) { | ||
return kc.redirectUri; | ||
} else { | ||
return "http://localhost"; | ||
} | ||
} | ||
} | ||
} | ||
throw 'invalid adapter type: ' + type; | ||
@@ -1346,0 +1418,0 @@ } |
@@ -1,40 +0,42 @@ | ||
(function(k,I){var w=function(l){function p(){return"undefined"!==typeof b.authServerUrl?"/"==b.authServerUrl.charAt(b.authServerUrl.length-1)?b.authServerUrl+"realms/"+encodeURIComponent(b.realm):b.authServerUrl+"/realms/"+encodeURIComponent(b.realm):I}function B(a,c){function e(g,d,e,f){x=(x+(new Date).getTime())/2;v(g,d,e,x);C&&(b.tokenParsed&&b.tokenParsed.nonce!=a.storedNonce||b.refreshTokenParsed&&b.refreshTokenParsed.nonce!=a.storedNonce||b.idTokenParsed&&b.idTokenParsed.nonce!=a.storedNonce)? | ||
(console.info("[KEYCLOAK] Invalid nonce, clearing token"),b.clearToken(),c&&c.setError()):f&&(b.onAuthSuccess&&b.onAuthSuccess(),c&&c.setSuccess())}var d=a.code,f=a.error,g=a.prompt,x=(new Date).getTime();if(f)"none"!=g?(d={error:f,error_description:a.error_description},b.onAuthError&&b.onAuthError(d),c&&c.setError(d)):c&&c.setSuccess();else if("standard"!=b.flow&&(a.access_token||a.id_token)&&e(a.access_token,null,a.id_token,!0),"implicit"!=b.flow&&d){var d="code\x3d"+d+"\x26grant_type\x3dauthorization_code", | ||
f=b.endpoints.token(),n=new XMLHttpRequest;n.open("POST",f,!0);n.setRequestHeader("Content-type","application/x-www-form-urlencoded");b.clientId&&b.clientSecret?n.setRequestHeader("Authorization","Basic "+btoa(b.clientId+":"+b.clientSecret)):d+="\x26client_id\x3d"+encodeURIComponent(b.clientId);d+="\x26redirect_uri\x3d"+a.redirectUri;n.withCredentials=!0;n.onreadystatechange=function(){if(4==n.readyState)if(200==n.status){var a=JSON.parse(n.responseText);e(a.access_token,a.refresh_token,a.id_token, | ||
"standard"===b.flow)}else b.onAuthError&&b.onAuthError(),c&&c.setError()};n.send(d)}}function L(a){function c(a){b.endpoints=a?{authorize:function(){return a.authorization_endpoint},token:function(){return a.token_endpoint},logout:function(){if(!a.end_session_endpoint)throw"Not supported by the OIDC server";return a.end_session_endpoint},checkSessionIframe:function(){if(!a.check_session_iframe)throw"Not supported by the OIDC server";return a.check_session_iframe},register:function(){throw'Redirection to "Register user" page not supported in standard OIDC mode'; | ||
(function(h,I){var y=function(m){function p(){return"undefined"!==typeof b.authServerUrl?"/"==b.authServerUrl.charAt(b.authServerUrl.length-1)?b.authServerUrl+"realms/"+encodeURIComponent(b.realm):b.authServerUrl+"/realms/"+encodeURIComponent(b.realm):I}function v(a,c){function d(g,f,d,e){z=(z+(new Date).getTime())/2;w(g,f,d,z);C&&(b.tokenParsed&&b.tokenParsed.nonce!=a.storedNonce||b.refreshTokenParsed&&b.refreshTokenParsed.nonce!=a.storedNonce||b.idTokenParsed&&b.idTokenParsed.nonce!=a.storedNonce)? | ||
(console.info("[KEYCLOAK] Invalid nonce, clearing token"),b.clearToken(),c&&c.setError()):e&&(b.onAuthSuccess&&b.onAuthSuccess(),c&&c.setSuccess())}var e=a.code,f=a.error,g=a.prompt,z=(new Date).getTime();if(f)"none"!=g?(e={error:f,error_description:a.error_description},b.onAuthError&&b.onAuthError(e),c&&c.setError(e)):c&&c.setSuccess();else if("standard"!=b.flow&&(a.access_token||a.id_token)&&d(a.access_token,null,a.id_token,!0),"implicit"!=b.flow&&e){var e="code\x3d"+e+"\x26grant_type\x3dauthorization_code", | ||
f=b.endpoints.token(),n=new XMLHttpRequest;n.open("POST",f,!0);n.setRequestHeader("Content-type","application/x-www-form-urlencoded");b.clientId&&b.clientSecret?n.setRequestHeader("Authorization","Basic "+btoa(b.clientId+":"+b.clientSecret)):e+="\x26client_id\x3d"+encodeURIComponent(b.clientId);e+="\x26redirect_uri\x3d"+a.redirectUri;n.withCredentials=!0;n.onreadystatechange=function(){if(4==n.readyState)if(200==n.status){var a=JSON.parse(n.responseText);d(a.access_token,a.refresh_token,a.id_token, | ||
"standard"===b.flow)}else b.onAuthError&&b.onAuthError(),c&&c.setError()};n.send(e)}}function L(a){function c(a){b.endpoints=a?{authorize:function(){return a.authorization_endpoint},token:function(){return a.token_endpoint},logout:function(){if(!a.end_session_endpoint)throw"Not supported by the OIDC server";return a.end_session_endpoint},checkSessionIframe:function(){if(!a.check_session_iframe)throw"Not supported by the OIDC server";return a.check_session_iframe},register:function(){throw'Redirection to "Register user" page not supported in standard OIDC mode'; | ||
},userinfo:function(){if(!a.userinfo_endpoint)throw"Not supported by the OIDC server";return a.userinfo_endpoint}}:{authorize:function(){return p()+"/protocol/openid-connect/auth"},token:function(){return p()+"/protocol/openid-connect/token"},logout:function(){return p()+"/protocol/openid-connect/logout"},checkSessionIframe:function(){var a=p()+"/protocol/openid-connect/login-status-iframe.html";b.iframeVersion&&(a=a+"?version\x3d"+b.iframeVersion);return a},register:function(){return p()+"/protocol/openid-connect/registrations"}, | ||
userinfo:function(){return p()+"/protocol/openid-connect/userinfo"}}}var e=m(),d;l?"string"===typeof l&&(d=l):d="keycloak.json";if(d){var f=new XMLHttpRequest;f.open("GET",d,!0);f.setRequestHeader("Accept","application/json");f.onreadystatechange=function(){if(4==f.readyState)if(200==f.status||0==f.status&&f.responseText&&f.responseURL.startsWith("file:")){var a=JSON.parse(f.responseText);b.authServerUrl=a["auth-server-url"];b.realm=a.realm;b.clientId=a.resource;b.clientSecret=(a.credentials||{}).secret; | ||
c(null);e.setSuccess()}else e.setError()};f.send()}else{if(!l.clientId)throw"clientId missing";b.clientId=l.clientId;b.clientSecret=(l.credentials||{}).secret;if(a=l.oidcProvider)"string"===typeof a?(a="/"==a.charAt(a.length-1)?a+".well-known/openid-configuration":a+"/.well-known/openid-configuration",f=new XMLHttpRequest,f.open("GET",a,!0),f.setRequestHeader("Accept","application/json"),f.onreadystatechange=function(){if(4==f.readyState)if(200==f.status||0==f.status&&f.responseText&&f.responseURL.startsWith("file:")){var a= | ||
JSON.parse(f.responseText);c(a);e.setSuccess()}else e.setError()},f.send()):(c(a),e.setSuccess());else{if(!l.url)for(a=document.getElementsByTagName("script"),d=0;d<a.length;d++)if(a[d].src.match(/.*keycloak\.js/)){l.url=a[d].src.substr(0,a[d].src.indexOf("/js/keycloak.js"));break}if(!l.realm)throw"realm missing";b.authServerUrl=l.url;b.realm=l.realm;c(null);e.setSuccess()}}return e.promise}function v(a,c,e,d){b.tokenTimeoutHandle&&(clearTimeout(b.tokenTimeoutHandle),b.tokenTimeoutHandle=null);c? | ||
(b.refreshToken=c,b.refreshTokenParsed=D(c)):(delete b.refreshToken,delete b.refreshTokenParsed);e?(b.idToken=e,b.idTokenParsed=D(e)):(delete b.idToken,delete b.idTokenParsed);if(a){if(b.token=a,b.tokenParsed=D(a),b.sessionId=b.tokenParsed.session_state,b.authenticated=!0,b.subject=b.tokenParsed.sub,b.realmAccess=b.tokenParsed.realm_access,b.resourceAccess=b.tokenParsed.resource_access,d&&(b.timeSkew=Math.floor(d/1E3)-b.tokenParsed.iat),null!=b.timeSkew&&(console.info("[KEYCLOAK] Estimated time difference between browser and server is "+ | ||
userinfo:function(){return p()+"/protocol/openid-connect/userinfo"}}}var d=l(),e;m?"string"===typeof m&&(e=m):e="keycloak.json";if(e){var f=new XMLHttpRequest;f.open("GET",e,!0);f.setRequestHeader("Accept","application/json");f.onreadystatechange=function(){if(4==f.readyState)if(200==f.status||0==f.status&&f.responseText&&f.responseURL.startsWith("file:")){var a=JSON.parse(f.responseText);b.authServerUrl=a["auth-server-url"];b.realm=a.realm;b.clientId=a.resource;b.clientSecret=(a.credentials||{}).secret; | ||
c(null);d.setSuccess()}else d.setError()};f.send()}else{if(!m.clientId)throw"clientId missing";b.clientId=m.clientId;b.clientSecret=(m.credentials||{}).secret;if(a=m.oidcProvider)"string"===typeof a?(a="/"==a.charAt(a.length-1)?a+".well-known/openid-configuration":a+"/.well-known/openid-configuration",f=new XMLHttpRequest,f.open("GET",a,!0),f.setRequestHeader("Accept","application/json"),f.onreadystatechange=function(){if(4==f.readyState)if(200==f.status||0==f.status&&f.responseText&&f.responseURL.startsWith("file:")){var a= | ||
JSON.parse(f.responseText);c(a);d.setSuccess()}else d.setError()},f.send()):(c(a),d.setSuccess());else{if(!m.url)for(a=document.getElementsByTagName("script"),e=0;e<a.length;e++)if(a[e].src.match(/.*keycloak\.js/)){m.url=a[e].src.substr(0,a[e].src.indexOf("/js/keycloak.js"));break}if(!m.realm)throw"realm missing";b.authServerUrl=m.url;b.realm=m.realm;c(null);d.setSuccess()}}return d.promise}function w(a,c,d,e){b.tokenTimeoutHandle&&(clearTimeout(b.tokenTimeoutHandle),b.tokenTimeoutHandle=null);c? | ||
(b.refreshToken=c,b.refreshTokenParsed=D(c)):(delete b.refreshToken,delete b.refreshTokenParsed);d?(b.idToken=d,b.idTokenParsed=D(d)):(delete b.idToken,delete b.idTokenParsed);if(a){if(b.token=a,b.tokenParsed=D(a),b.sessionId=b.tokenParsed.session_state,b.authenticated=!0,b.subject=b.tokenParsed.sub,b.realmAccess=b.tokenParsed.realm_access,b.resourceAccess=b.tokenParsed.resource_access,e&&(b.timeSkew=Math.floor(e/1E3)-b.tokenParsed.iat),null!=b.timeSkew&&(console.info("[KEYCLOAK] Estimated time difference between browser and server is "+ | ||
b.timeSkew+" seconds"),b.onTokenExpired))if(a=1E3*(b.tokenParsed.exp-(new Date).getTime()/1E3+b.timeSkew),console.info("[KEYCLOAK] Token expires in "+Math.round(a/1E3)+" s"),0>=a)b.onTokenExpired();else b.tokenTimeoutHandle=setTimeout(b.onTokenExpired,a)}else delete b.token,delete b.tokenParsed,delete b.subject,delete b.realmAccess,delete b.resourceAccess,b.authenticated=!1}function D(a){a=a.split(".")[1];a=a.replace("/-/g","+");a=a.replace("/_/g","/");switch(a.length%4){case 0:break;case 2:a+="\x3d\x3d"; | ||
break;case 3:a+="\x3d";break;default:throw"Invalid token";}a=(a+"\x3d\x3d\x3d").slice(0,a.length+a.length%4);a=a.replace(/-/g,"+").replace(/_/g,"/");a=decodeURIComponent(escape(atob(a)));return a=JSON.parse(a)}function J(){for(var a=[],b=0;36>b;b++)a[b]="0123456789abcdef".substr(Math.floor(16*Math.random()),1);a[14]="4";a[19]="0123456789abcdef".substr(a[19]&3|8,1);a[8]=a[13]=a[18]=a[23]="-";return a.join("")}function E(a){a:{var c;switch(b.flow){case "standard":c=["code","state","session_state"]; | ||
break;case "implicit":c=["access_token","id_token","state","session_state"];break;case "hybrid":c=["access_token","id_token","code","state","session_state"]}c.push("error");c.push("error_description");c.push("error_uri");var e=a.indexOf("?"),d=a.indexOf("#"),f,g;"query"===b.responseMode&&-1!==e?(f=a.substring(0,e),g=K(a.substring(e+1,-1!==d?d:a.length),c),""!==g.paramsString&&(f+="?"+g.paramsString),-1!==d&&(f+=a.substring(d))):"fragment"===b.responseMode&&-1!==d&&(f=a.substring(0,d),g=K(a.substring(d+ | ||
1),c),""!==g.paramsString&&(f+="#"+g.paramsString));if(g&&g.oauthParams)if("standard"===b.flow||"hybrid"===b.flow){if((g.oauthParams.code||g.oauthParams.error)&&g.oauthParams.state){g.oauthParams.newUrl=f;a=g.oauthParams;break a}}else if("implicit"===b.flow&&(g.oauthParams.access_token||g.oauthParams.error)&&g.oauthParams.state){g.oauthParams.newUrl=f;a=g.oauthParams;break a}a=void 0}if(a){if(c=y.get(a.state))a.valid=!0,a.redirectUri=c.redirectUri,a.storedNonce=c.nonce,a.prompt=c.prompt;return a}} | ||
function K(a,b){a=a.split("\x26");for(var c={paramsString:"",oauthParams:{}},d=0;d<a.length;d++){var f=a[d].split("\x3d");-1!==b.indexOf(f[0])?c.oauthParams[f[0]]=f[1]:(""!==c.paramsString&&(c.paramsString+="\x26"),c.paramsString+=a[d])}return c}function m(){return"function"===typeof Promise?M():N()}function M(){var a={setSuccess:function(b){a.success=!0;a.resolve(b)},setError:function(b){a.success=!1;a.reject(b)}};a.promise=new Promise(function(b,e){a.resolve=b;a.reject=e});a.promise.success=function(b){a.promise.then(b); | ||
return a.promise};a.promise.error=function(b){a.promise.catch(b);return a.promise};return a}function N(){var a={setSuccess:function(b){a.success=!0;a.result=b;a.successCallback&&a.successCallback(b)},setError:function(b){a.error=!0;a.result=b;a.errorCallback&&a.errorCallback(b)},promise:{success:function(b){a.success?b(a.result):a.error||(a.successCallback=b);return a.promise},error:function(b){a.error?b(a.result):a.success||(a.errorCallback=b);return a.promise}}};return a}function F(){var a=m(); | ||
if(!h.enable||h.iframe)return a.setSuccess(),a.promise;var c=document.createElement("iframe");h.iframe=c;c.onload=function(){var c=b.endpoints.authorize();"/"===c.charAt(0)?(c=k.location.origin?k.location.origin:k.location.protocol+"//"+k.location.hostname+(k.location.port?":"+k.location.port:""),h.iframeOrigin=c):h.iframeOrigin=c.substring(0,c.indexOf("/",8));a.setSuccess();setTimeout(d,1E3*h.interval)};var e=b.endpoints.checkSessionIframe();c.setAttribute("src",e);c.setAttribute("title","keycloak-session-iframe"); | ||
c.style.display="none";document.body.appendChild(c);k.addEventListener("message",function(a){if(a.origin===h.iframeOrigin&&h.iframe.contentWindow===a.source&&("unchanged"==a.data||"changed"==a.data||"error"==a.data)){"unchanged"!=a.data&&b.clearToken();for(var c=h.callbackList.splice(0,h.callbackList.length),d=c.length-1;0<=d;--d){var e=c[d];"unchanged"==a.data?e.setSuccess():e.setError()}}},!1);var d=function(){z();b.token&&setTimeout(d,1E3*h.interval)};return a.promise}function z(){var a=m();if(h.iframe&& | ||
h.iframeOrigin){var c=b.clientId+" "+b.sessionId;h.callbackList.push(a);var e=h.iframeOrigin;1==h.callbackList.length&&h.iframe.contentWindow.postMessage(c,e)}else a.setSuccess();return a.promise}function A(a){if(!a||"default"==a)return{login:function(a){k.location.href=b.createLoginUrl(a);return m().promise},logout:function(a){k.location.href=b.createLogoutUrl(a);return m().promise},register:function(a){k.location.href=b.createRegisterUrl(a);return m().promise},accountManagement:function(){var a= | ||
b.createAccountUrl();if("undefined"!==typeof a)k.location.href=a;else throw"Not supported by the OIDC server";return m().promise},redirectUri:function(a,c){1==arguments.length&&(c=!0);return a&&a.redirectUri?a.redirectUri:b.redirectUri?b.redirectUri:location.href}};if("cordova"==a){h.enable=!1;var c=function(a,b,c){return k.cordova&&k.cordova.InAppBrowser?k.cordova.InAppBrowser.open(a,b,c):k.open(a,b,c)},e=function(a){return a&&a.cordovaOptions?Object.keys(a.cordovaOptions).reduce(function(b,c){b[c]= | ||
a.cordovaOptions[c];return b},{}):{}},d=function(a){return Object.keys(a).reduce(function(b,c){b.push(c+"\x3d"+a[c]);return b},[]).join(",")},f=function(a){var b=e(a);b.location="no";a&&"none"==a.prompt&&(b.hidden="yes");return d(b)};return{login:function(a){var d=m(),e=f(a);a=b.createLoginUrl(a);var g=c(a,"_blank",e),h=!1,k=!1;g.addEventListener("loadstart",function(a){0==a.url.indexOf("http://localhost")&&(a=E(a.url),B(a,d),k=!0,g.close(),h=!0)});g.addEventListener("loaderror",function(a){h||(0== | ||
a.url.indexOf("http://localhost")?(a=E(a.url),B(a,d),k=!0,g.close(),h=!0):(d.setError(),k=!0,g.close()))});g.addEventListener("exit",function(a){k||d.setError({reason:"closed_by_user"})});return d.promise},logout:function(a){var d=m();a=b.createLogoutUrl(a);var e=c(a,"_blank","location\x3dno,hidden\x3dyes"),g;e.addEventListener("loadstart",function(a){0==a.url.indexOf("http://localhost")&&e.close()});e.addEventListener("loaderror",function(a){0!=a.url.indexOf("http://localhost")&&(g=!0);e.close()}); | ||
e.addEventListener("exit",function(a){g?d.setError():(b.clearToken(),d.setSuccess())});return d.promise},register:function(){var a=b.createRegisterUrl(),d=f(options),e=c(a,"_blank",d);e.addEventListener("loadstart",function(a){0==a.url.indexOf("http://localhost")&&e.close()})},accountManagement:function(){var a=b.createAccountUrl();if("undefined"!==typeof a){var d=c(a,"_blank","location\x3dno");d.addEventListener("loadstart",function(a){0==a.url.indexOf("http://localhost")&&d.close()})}else throw"Not supported by the OIDC server"; | ||
},redirectUri:function(a){return"http://localhost"}}}throw"invalid adapter type: "+a;}if(!(this instanceof w))return new w(l);for(var b=this,q,t=[],y,h={enable:!0,callbackList:[],interval:5},u=document.getElementsByTagName("script"),r=0;r<u.length;r++)-1===u[r].src.indexOf("keycloak.js")&&-1===u[r].src.indexOf("keycloak.min.js")||-1===u[r].src.indexOf("version\x3d")||(b.iframeVersion=u[r].src.substring(u[r].src.indexOf("version\x3d")+8).split("\x26")[0]);var C=!0;b.init=function(a){function c(){var c= | ||
function(a){a||(e.prompt="none");b.login(e).success(function(){d.setSuccess()}).error(function(){d.setError()})},e={};switch(a.onLoad){case "check-sso":h.enable?F().success(function(){z().success(function(){c(!1)}).error(function(){d.setSuccess()})}):c(!1);break;case "login-required":c(!0);break;default:throw"Invalid value for onLoad";}}b.authenticated=!1;a:{try{y=new G;break a}catch(g){}y=new H}q=a&&"cordova"===a.adapter?A("cordova"):a&&"default"===a.adapter?A():a&&"object"===typeof a.adapter?a.adapter: | ||
k.Cordova||k.cordova?A("cordova"):A();if(a){"undefined"!==typeof a.useNonce&&(C=a.useNonce);"undefined"!==typeof a.checkLoginIframe&&(h.enable=a.checkLoginIframe);a.checkLoginIframeInterval&&(h.interval=a.checkLoginIframeInterval);"login-required"===a.onLoad&&(b.loginRequired=!0);if(a.responseMode)if("query"===a.responseMode||"fragment"===a.responseMode)b.responseMode=a.responseMode;else throw"Invalid value for responseMode";if(a.flow){switch(a.flow){case "standard":b.responseType="code";break;case "implicit":b.responseType= | ||
"id_token token";break;case "hybrid":b.responseType="code id_token token";break;default:throw"Invalid value for flow";}b.flow=a.flow}null!=a.timeSkew&&(b.timeSkew=a.timeSkew)}b.responseMode||(b.responseMode="fragment");b.responseType||(b.responseType="code",b.flow="standard");var e=m(),d=m();d.promise.success(function(){b.onReady&&b.onReady(b.authenticated);e.setSuccess(b.authenticated)}).error(function(a){e.setError(a)});var f=L(l);f.success(function(){var e=E(k.location.href);e&&k.history.replaceState({}, | ||
null,e.newUrl);if(e&&e.valid)return F().success(function(){B(e,d)}).error(function(a){d.setError()});a?a.token&&a.refreshToken?(v(a.token,a.refreshToken,a.idToken),h.enable?F().success(function(){z().success(function(){b.onAuthSuccess&&b.onAuthSuccess();d.setSuccess()}).error(function(){v(null,null,null);d.setSuccess()})}):b.updateToken(-1).success(function(){b.onAuthSuccess&&b.onAuthSuccess();d.setSuccess()}).error(function(){b.onAuthError&&b.onAuthError();a.onLoad?c():d.setError()})):a.onLoad?c(): | ||
d.setSuccess():d.setSuccess()});f.error(function(){e.setError()});return e.promise};b.login=function(a){return q.login(a)};b.createLoginUrl=function(a){var c=J(),e=J(),d=q.redirectUri(a),f={state:c,nonce:e,redirectUri:encodeURIComponent(d)};a&&a.prompt&&(f.prompt=a.prompt);y.add(f);var f=a&&"register"==a.action?b.endpoints.register():b.endpoints.authorize(),g;g=a&&a.scope?-1!=a.scope.indexOf("openid")?a.scope:"openid "+a.scope:"openid";c=f+"?client_id\x3d"+encodeURIComponent(b.clientId)+"\x26redirect_uri\x3d"+ | ||
encodeURIComponent(d)+"\x26state\x3d"+encodeURIComponent(c)+"\x26response_mode\x3d"+encodeURIComponent(b.responseMode)+"\x26response_type\x3d"+encodeURIComponent(b.responseType)+"\x26scope\x3d"+encodeURIComponent(g);C&&(c=c+"\x26nonce\x3d"+encodeURIComponent(e));a&&a.prompt&&(c+="\x26prompt\x3d"+encodeURIComponent(a.prompt));a&&a.maxAge&&(c+="\x26max_age\x3d"+encodeURIComponent(a.maxAge));a&&a.loginHint&&(c+="\x26login_hint\x3d"+encodeURIComponent(a.loginHint));a&&a.idpHint&&(c+="\x26kc_idp_hint\x3d"+ | ||
encodeURIComponent(a.idpHint));a&&a.locale&&(c+="\x26ui_locales\x3d"+encodeURIComponent(a.locale));a&&a.kcLocale&&(c+="\x26kc_locale\x3d"+encodeURIComponent(a.kcLocale));return c};b.logout=function(a){return q.logout(a)};b.createLogoutUrl=function(a){return b.endpoints.logout()+"?redirect_uri\x3d"+encodeURIComponent(q.redirectUri(a,!1))};b.register=function(a){return q.register(a)};b.createRegisterUrl=function(a){a||(a={});a.action="register";return b.createLoginUrl(a)};b.createAccountUrl=function(a){var c= | ||
p(),e=I;"undefined"!==typeof c&&(e=c+"/account?referrer\x3d"+encodeURIComponent(b.clientId)+"\x26referrer_uri\x3d"+encodeURIComponent(q.redirectUri(a)));return e};b.accountManagement=function(){return q.accountManagement()};b.hasRealmRole=function(a){var c=b.realmAccess;return!!c&&0<=c.roles.indexOf(a)};b.hasResourceRole=function(a,c){if(!b.resourceAccess)return!1;c=b.resourceAccess[c||b.clientId];return!!c&&0<=c.roles.indexOf(a)};b.loadUserProfile=function(){var a=p()+"/account",c=new XMLHttpRequest; | ||
c.open("GET",a,!0);c.setRequestHeader("Accept","application/json");c.setRequestHeader("Authorization","bearer "+b.token);var e=m();c.onreadystatechange=function(){4==c.readyState&&(200==c.status?(b.profile=JSON.parse(c.responseText),e.setSuccess(b.profile)):e.setError())};c.send();return e.promise};b.loadUserInfo=function(){var a=b.endpoints.userinfo(),c=new XMLHttpRequest;c.open("GET",a,!0);c.setRequestHeader("Accept","application/json");c.setRequestHeader("Authorization","bearer "+b.token);var e= | ||
m();c.onreadystatechange=function(){4==c.readyState&&(200==c.status?(b.userInfo=JSON.parse(c.responseText),e.setSuccess(b.userInfo)):e.setError())};c.send();return e.promise};b.isTokenExpired=function(a){if(!b.tokenParsed||!b.refreshToken&&"implicit"!=b.flow)throw"Not authenticated";if(null==b.timeSkew)return console.info("[KEYCLOAK] Unable to determine if token is expired as timeskew is not set"),!0;var c=b.tokenParsed.exp-Math.ceil((new Date).getTime()/1E3)+b.timeSkew;a&&(c-=a);return 0>c};b.updateToken= | ||
function(a){var c=m();if(!b.refreshToken)return c.setError(),c.promise;a=a||5;var e=function(){var d=!1;if(-1==a)d=!0,console.info("[KEYCLOAK] Refreshing token: forced refresh");else if(!b.tokenParsed||b.isTokenExpired(a))d=!0,console.info("[KEYCLOAK] Refreshing token: token expired");if(d){var d="grant_type\x3drefresh_token\x26refresh_token\x3d"+b.refreshToken,e=b.endpoints.token();t.push(c);if(1==t.length){var g=new XMLHttpRequest;g.open("POST",e,!0);g.setRequestHeader("Content-type","application/x-www-form-urlencoded"); | ||
g.withCredentials=!0;b.clientId&&b.clientSecret?g.setRequestHeader("Authorization","Basic "+btoa(b.clientId+":"+b.clientSecret)):d+="\x26client_id\x3d"+encodeURIComponent(b.clientId);var h=(new Date).getTime();g.onreadystatechange=function(){if(4==g.readyState)if(200==g.status){console.info("[KEYCLOAK] Token refreshed");h=(h+(new Date).getTime())/2;var a=JSON.parse(g.responseText);v(a.access_token,a.refresh_token,a.id_token,h);b.onAuthRefreshSuccess&&b.onAuthRefreshSuccess();for(a=t.pop();null!=a;a= | ||
t.pop())a.setSuccess(!0)}else for(console.warn("[KEYCLOAK] Failed to refresh token"),400==g.status&&b.clearToken(),b.onAuthRefreshError&&b.onAuthRefreshError(),a=t.pop();null!=a;a=t.pop())a.setError(!0)};g.send(d)}}else c.setSuccess(!1)};h.enable?z().success(function(){e()}).error(function(){c.setError()}):e();return c.promise};b.clearToken=function(){b.token&&(v(null,null,null),b.onAuthLogout&&b.onAuthLogout(),b.loginRequired&&b.login())};b.callback_id=0;var G=function(){function a(){for(var a=(new Date).getTime(), | ||
b=0;b<localStorage.length;b++){var d=localStorage.key(b);if(d&&0==d.indexOf("kc-callback-")){var f=localStorage.getItem(d);if(f)try{var g=JSON.parse(f).expires;(!g||g<a)&&localStorage.removeItem(d)}catch(x){localStorage.removeItem(d)}}}}if(!(this instanceof G))return new G;localStorage.setItem("kc-test","test");localStorage.removeItem("kc-test");this.get=function(b){if(b){b="kc-callback-"+b;var c=localStorage.getItem(b);c&&(localStorage.removeItem(b),c=JSON.parse(c));a();return c}};this.add=function(b){a(); | ||
var c="kc-callback-"+b.state;b.expires=(new Date).getTime()+36E5;localStorage.setItem(c,JSON.stringify(b))}},H=function(){if(!(this instanceof H))return new H;this.get=function(c){if(c){var d;a:{d="kc-callback-"+c+"\x3d";for(var e=document.cookie.split(";"),g=0;g<e.length;g++){for(var h=e[g];" "==h.charAt(0);)h=h.substring(1);if(0==h.indexOf(d)){d=h.substring(d.length,h.length);break a}}d=""}b("kc-callback-"+c,"",a(-100));if(d)return JSON.parse(d)}};this.add=function(c){b("kc-callback-"+c.state,JSON.stringify(c), | ||
a(60))};this.removeItem=function(c){b(c,"",a(-100))};var a=function(a){var b=new Date;b.setTime(b.getTime()+6E4*a);return b},b=function(a,b,c){a=a+"\x3d"+b+"; expires\x3d"+c.toUTCString()+"; ";document.cookie=a}}};"object"===typeof module&&module&&"object"===typeof module.exports?module.exports=w:(k.Keycloak=w,"function"===typeof define&&define.amd&&define("keycloak",[],function(){return w}))})(window); | ||
break;case 3:a+="\x3d";break;default:throw"Invalid token";}a=(a+"\x3d\x3d\x3d").slice(0,a.length+a.length%4);a=a.replace(/-/g,"+").replace(/_/g,"/");a=decodeURIComponent(escape(atob(a)));return a=JSON.parse(a)}function J(){for(var a=[],b=0;36>b;b++)a[b]="0123456789abcdef".substr(Math.floor(16*Math.random()),1);a[14]="4";a[19]="0123456789abcdef".substr(a[19]&3|8,1);a[8]=a[13]=a[18]=a[23]="-";return a.join("")}function x(a){a:{var c;switch(b.flow){case "standard":c=["code","state","session_state"]; | ||
break;case "implicit":c=["access_token","id_token","state","session_state"];break;case "hybrid":c=["access_token","id_token","code","state","session_state"]}c.push("error");c.push("error_description");c.push("error_uri");var d=a.indexOf("?"),e=a.indexOf("#"),f,g;"query"===b.responseMode&&-1!==d?(f=a.substring(0,d),g=K(a.substring(d+1,-1!==e?e:a.length),c),""!==g.paramsString&&(f+="?"+g.paramsString),-1!==e&&(f+=a.substring(e))):"fragment"===b.responseMode&&-1!==e&&(f=a.substring(0,e),g=K(a.substring(e+ | ||
1),c),""!==g.paramsString&&(f+="#"+g.paramsString));if(g&&g.oauthParams)if("standard"===b.flow||"hybrid"===b.flow){if((g.oauthParams.code||g.oauthParams.error)&&g.oauthParams.state){g.oauthParams.newUrl=f;a=g.oauthParams;break a}}else if("implicit"===b.flow&&(g.oauthParams.access_token||g.oauthParams.error)&&g.oauthParams.state){g.oauthParams.newUrl=f;a=g.oauthParams;break a}a=void 0}if(a){if(c=A.get(a.state))a.valid=!0,a.redirectUri=c.redirectUri,a.storedNonce=c.nonce,a.prompt=c.prompt;return a}} | ||
function K(a,b){a=a.split("\x26");for(var c={paramsString:"",oauthParams:{}},e=0;e<a.length;e++){var f=a[e].split("\x3d");-1!==b.indexOf(f[0])?c.oauthParams[f[0]]=f[1]:(""!==c.paramsString&&(c.paramsString+="\x26"),c.paramsString+=a[e])}return c}function l(){return"function"===typeof Promise?M():N()}function M(){var a={setSuccess:function(b){a.success=!0;a.resolve(b)},setError:function(b){a.success=!1;a.reject(b)}};a.promise=new Promise(function(b,d){a.resolve=b;a.reject=d});a.promise.success=function(b){a.promise.then(b); | ||
return a.promise};a.promise.error=function(b){a.promise.catch(b);return a.promise};return a}function N(){var a={setSuccess:function(b){a.success=!0;a.result=b;a.successCallback&&a.successCallback(b)},setError:function(b){a.error=!0;a.result=b;a.errorCallback&&a.errorCallback(b)},promise:{success:function(b){a.success?b(a.result):a.error||(a.successCallback=b);return a.promise},error:function(b){a.error?b(a.result):a.success||(a.errorCallback=b);return a.promise}}};return a}function E(){var a=l(); | ||
if(!k.enable||k.iframe)return a.setSuccess(),a.promise;var c=document.createElement("iframe");k.iframe=c;c.onload=function(){var c=b.endpoints.authorize();"/"===c.charAt(0)?(c=h.location.origin?h.location.origin:h.location.protocol+"//"+h.location.hostname+(h.location.port?":"+h.location.port:""),k.iframeOrigin=c):k.iframeOrigin=c.substring(0,c.indexOf("/",8));a.setSuccess();setTimeout(e,1E3*k.interval)};var d=b.endpoints.checkSessionIframe();c.setAttribute("src",d);c.setAttribute("title","keycloak-session-iframe"); | ||
c.style.display="none";document.body.appendChild(c);h.addEventListener("message",function(a){if(a.origin===k.iframeOrigin&&k.iframe.contentWindow===a.source&&("unchanged"==a.data||"changed"==a.data||"error"==a.data)){"unchanged"!=a.data&&b.clearToken();for(var c=k.callbackList.splice(0,k.callbackList.length),e=c.length-1;0<=e;--e){var d=c[e];"unchanged"==a.data?d.setSuccess():d.setError()}}},!1);var e=function(){B();b.token&&setTimeout(e,1E3*k.interval)};return a.promise}function B(){var a=l();if(k.iframe&& | ||
k.iframeOrigin){var c=b.clientId+" "+b.sessionId;k.callbackList.push(a);var d=k.iframeOrigin;1==k.callbackList.length&&k.iframe.contentWindow.postMessage(c,d)}else a.setSuccess();return a.promise}function F(a){if(!a||"default"==a)return{login:function(a){h.location.href=b.createLoginUrl(a);return l().promise},logout:function(a){h.location.href=b.createLogoutUrl(a);return l().promise},register:function(a){h.location.href=b.createRegisterUrl(a);return l().promise},accountManagement:function(){var a= | ||
b.createAccountUrl();if("undefined"!==typeof a)h.location.href=a;else throw"Not supported by the OIDC server";return l().promise},redirectUri:function(a,c){1==arguments.length&&(c=!0);return a&&a.redirectUri?a.redirectUri:b.redirectUri?b.redirectUri:location.href}};if("cordova"==a){k.enable=!1;var c=function(a,b,c){return h.cordova&&h.cordova.InAppBrowser?h.cordova.InAppBrowser.open(a,b,c):h.open(a,b,c)},d=function(a){return a&&a.cordovaOptions?Object.keys(a.cordovaOptions).reduce(function(b,c){b[c]= | ||
a.cordovaOptions[c];return b},{}):{}},e=function(a){return Object.keys(a).reduce(function(b,c){b.push(c+"\x3d"+a[c]);return b},[]).join(",")},f=function(a){var b=d(a);b.location="no";a&&"none"==a.prompt&&(b.hidden="yes");return e(b)};return{login:function(a){var g=l(),e=f(a);a=b.createLoginUrl(a);var d=c(a,"_blank",e),h=!1,k=!1;d.addEventListener("loadstart",function(a){0==a.url.indexOf("http://localhost")&&(a=x(a.url),v(a,g),k=!0,d.close(),h=!0)});d.addEventListener("loaderror",function(a){h||(0== | ||
a.url.indexOf("http://localhost")?(a=x(a.url),v(a,g),k=!0,d.close(),h=!0):(g.setError(),k=!0,d.close()))});d.addEventListener("exit",function(a){k||g.setError({reason:"closed_by_user"})});return g.promise},logout:function(a){var g=l();a=b.createLogoutUrl(a);var d=c(a,"_blank","location\x3dno,hidden\x3dyes"),e;d.addEventListener("loadstart",function(a){0==a.url.indexOf("http://localhost")&&d.close()});d.addEventListener("loaderror",function(a){0!=a.url.indexOf("http://localhost")&&(e=!0);d.close()}); | ||
d.addEventListener("exit",function(a){e?g.setError():(b.clearToken(),g.setSuccess())});return g.promise},register:function(){var a=b.createRegisterUrl(),d=f(options),e=c(a,"_blank",d);e.addEventListener("loadstart",function(a){0==a.url.indexOf("http://localhost")&&e.close()})},accountManagement:function(){var a=b.createAccountUrl();if("undefined"!==typeof a){var d=c(a,"_blank","location\x3dno");d.addEventListener("loadstart",function(a){0==a.url.indexOf("http://localhost")&&d.close()})}else throw"Not supported by the OIDC server"; | ||
},redirectUri:function(a){return"http://localhost"}}}if("cordova-native"==a)return k.enable=!1,{login:function(a){var c=l();a=b.createLoginUrl(a);universalLinks.subscribe("keycloak",function(a){universalLinks.unsubscribe("keycloak");h.cordova.plugins.browsertab.close();a=x(a.url);v(a,c)});h.cordova.plugins.browsertab.openUrl(a);return c.promise},logout:function(a){var c=l();a=b.createLogoutUrl(a);universalLinks.subscribe("keycloak",function(a){universalLinks.unsubscribe("keycloak");h.cordova.plugins.browsertab.close(); | ||
b.clearToken();c.setSuccess()});h.cordova.plugins.browsertab.openUrl(a);return c.promise},register:function(a){var c=l();a=b.createRegisterUrl(a);universalLinks.subscribe("keycloak",function(a){universalLinks.unsubscribe("keycloak");h.cordova.plugins.browsertab.close();a=x(a.url);v(a,c)});h.cordova.plugins.browsertab.openUrl(a);return c.promise},accountManagement:function(){var a=b.createAccountUrl();if("undefined"!==typeof a)h.cordova.plugins.browsertab.openUrl(a);else throw"Not supported by the OIDC server"; | ||
},redirectUri:function(a){return a&&a.redirectUri?a.redirectUri:b.redirectUri?b.redirectUri:"http://localhost"}};throw"invalid adapter type: "+a;}if(!(this instanceof y))return new y(m);for(var b=this,q,t=[],A,k={enable:!0,callbackList:[],interval:5},u=document.getElementsByTagName("script"),r=0;r<u.length;r++)-1===u[r].src.indexOf("keycloak.js")&&-1===u[r].src.indexOf("keycloak.min.js")||-1===u[r].src.indexOf("version\x3d")||(b.iframeVersion=u[r].src.substring(u[r].src.indexOf("version\x3d")+8).split("\x26")[0]); | ||
var C=!0;b.init=function(a){function c(){var c=function(a){a||(d.prompt="none");b.login(d).success(function(){f.setSuccess()}).error(function(){f.setError()})},d={};switch(a.onLoad){case "check-sso":k.enable?E().success(function(){B().success(function(){c(!1)}).error(function(){f.setSuccess()})}):c(!1);break;case "login-required":c(!0);break;default:throw"Invalid value for onLoad";}}b.authenticated=!1;a:{try{A=new G;break a}catch(g){}A=new H}var d=["default","cordova","cordova-native"];q=a&&-1<d.indexOf(a.adapter)? | ||
F(a.adapter):a&&"object"===typeof a.adapter?a.adapter:h.Cordova||h.cordova?F("cordova"):F();if(a){"undefined"!==typeof a.useNonce&&(C=a.useNonce);"undefined"!==typeof a.checkLoginIframe&&(k.enable=a.checkLoginIframe);a.checkLoginIframeInterval&&(k.interval=a.checkLoginIframeInterval);"login-required"===a.onLoad&&(b.loginRequired=!0);if(a.responseMode)if("query"===a.responseMode||"fragment"===a.responseMode)b.responseMode=a.responseMode;else throw"Invalid value for responseMode";if(a.flow){switch(a.flow){case "standard":b.responseType= | ||
"code";break;case "implicit":b.responseType="id_token token";break;case "hybrid":b.responseType="code id_token token";break;default:throw"Invalid value for flow";}b.flow=a.flow}null!=a.timeSkew&&(b.timeSkew=a.timeSkew);a.redirectUri&&(b.redirectUri=a.redirectUri)}b.responseMode||(b.responseMode="fragment");b.responseType||(b.responseType="code",b.flow="standard");var e=l(),f=l();f.promise.success(function(){b.onReady&&b.onReady(b.authenticated);e.setSuccess(b.authenticated)}).error(function(a){e.setError(a)}); | ||
d=L(m);d.success(function(){var d=x(h.location.href);d&&h.history.replaceState({},null,d.newUrl);if(d&&d.valid)return E().success(function(){v(d,f)}).error(function(a){f.setError()});a?a.token&&a.refreshToken?(w(a.token,a.refreshToken,a.idToken),k.enable?E().success(function(){B().success(function(){b.onAuthSuccess&&b.onAuthSuccess();f.setSuccess()}).error(function(){w(null,null,null);f.setSuccess()})}):b.updateToken(-1).success(function(){b.onAuthSuccess&&b.onAuthSuccess();f.setSuccess()}).error(function(){b.onAuthError&& | ||
b.onAuthError();a.onLoad?c():f.setError()})):a.onLoad?c():f.setSuccess():f.setSuccess()});d.error(function(){e.setError()});return e.promise};b.login=function(a){return q.login(a)};b.createLoginUrl=function(a){var c=J(),d=J(),e=q.redirectUri(a),f={state:c,nonce:d,redirectUri:encodeURIComponent(e)};a&&a.prompt&&(f.prompt=a.prompt);A.add(f);var f=a&&"register"==a.action?b.endpoints.register():b.endpoints.authorize(),g;g=a&&a.scope?-1!=a.scope.indexOf("openid")?a.scope:"openid "+a.scope:"openid";c=f+ | ||
"?client_id\x3d"+encodeURIComponent(b.clientId)+"\x26redirect_uri\x3d"+encodeURIComponent(e)+"\x26state\x3d"+encodeURIComponent(c)+"\x26response_mode\x3d"+encodeURIComponent(b.responseMode)+"\x26response_type\x3d"+encodeURIComponent(b.responseType)+"\x26scope\x3d"+encodeURIComponent(g);C&&(c=c+"\x26nonce\x3d"+encodeURIComponent(d));a&&a.prompt&&(c+="\x26prompt\x3d"+encodeURIComponent(a.prompt));a&&a.maxAge&&(c+="\x26max_age\x3d"+encodeURIComponent(a.maxAge));a&&a.loginHint&&(c+="\x26login_hint\x3d"+ | ||
encodeURIComponent(a.loginHint));a&&a.idpHint&&(c+="\x26kc_idp_hint\x3d"+encodeURIComponent(a.idpHint));a&&a.locale&&(c+="\x26ui_locales\x3d"+encodeURIComponent(a.locale));a&&a.kcLocale&&(c+="\x26kc_locale\x3d"+encodeURIComponent(a.kcLocale));return c};b.logout=function(a){return q.logout(a)};b.createLogoutUrl=function(a){return b.endpoints.logout()+"?redirect_uri\x3d"+encodeURIComponent(q.redirectUri(a,!1))};b.register=function(a){return q.register(a)};b.createRegisterUrl=function(a){a||(a={});a.action= | ||
"register";return b.createLoginUrl(a)};b.createAccountUrl=function(a){var c=p(),d=I;"undefined"!==typeof c&&(d=c+"/account?referrer\x3d"+encodeURIComponent(b.clientId)+"\x26referrer_uri\x3d"+encodeURIComponent(q.redirectUri(a)));return d};b.accountManagement=function(){return q.accountManagement()};b.hasRealmRole=function(a){var c=b.realmAccess;return!!c&&0<=c.roles.indexOf(a)};b.hasResourceRole=function(a,c){if(!b.resourceAccess)return!1;c=b.resourceAccess[c||b.clientId];return!!c&&0<=c.roles.indexOf(a)}; | ||
b.loadUserProfile=function(){var a=p()+"/account",c=new XMLHttpRequest;c.open("GET",a,!0);c.setRequestHeader("Accept","application/json");c.setRequestHeader("Authorization","bearer "+b.token);var d=l();c.onreadystatechange=function(){4==c.readyState&&(200==c.status?(b.profile=JSON.parse(c.responseText),d.setSuccess(b.profile)):d.setError())};c.send();return d.promise};b.loadUserInfo=function(){var a=b.endpoints.userinfo(),c=new XMLHttpRequest;c.open("GET",a,!0);c.setRequestHeader("Accept","application/json"); | ||
c.setRequestHeader("Authorization","bearer "+b.token);var d=l();c.onreadystatechange=function(){4==c.readyState&&(200==c.status?(b.userInfo=JSON.parse(c.responseText),d.setSuccess(b.userInfo)):d.setError())};c.send();return d.promise};b.isTokenExpired=function(a){if(!b.tokenParsed||!b.refreshToken&&"implicit"!=b.flow)throw"Not authenticated";if(null==b.timeSkew)return console.info("[KEYCLOAK] Unable to determine if token is expired as timeskew is not set"),!0;var c=b.tokenParsed.exp-Math.ceil((new Date).getTime()/ | ||
1E3)+b.timeSkew;a&&(c-=a);return 0>c};b.updateToken=function(a){var c=l();if(!b.refreshToken)return c.setError(),c.promise;a=a||5;var d=function(){var d=!1;if(-1==a)d=!0,console.info("[KEYCLOAK] Refreshing token: forced refresh");else if(!b.tokenParsed||b.isTokenExpired(a))d=!0,console.info("[KEYCLOAK] Refreshing token: token expired");if(d){var d="grant_type\x3drefresh_token\x26refresh_token\x3d"+b.refreshToken,f=b.endpoints.token();t.push(c);if(1==t.length){var g=new XMLHttpRequest;g.open("POST", | ||
f,!0);g.setRequestHeader("Content-type","application/x-www-form-urlencoded");g.withCredentials=!0;b.clientId&&b.clientSecret?g.setRequestHeader("Authorization","Basic "+btoa(b.clientId+":"+b.clientSecret)):d+="\x26client_id\x3d"+encodeURIComponent(b.clientId);var h=(new Date).getTime();g.onreadystatechange=function(){if(4==g.readyState)if(200==g.status){console.info("[KEYCLOAK] Token refreshed");h=(h+(new Date).getTime())/2;var a=JSON.parse(g.responseText);w(a.access_token,a.refresh_token,a.id_token, | ||
h);b.onAuthRefreshSuccess&&b.onAuthRefreshSuccess();for(a=t.pop();null!=a;a=t.pop())a.setSuccess(!0)}else for(console.warn("[KEYCLOAK] Failed to refresh token"),400==g.status&&b.clearToken(),b.onAuthRefreshError&&b.onAuthRefreshError(),a=t.pop();null!=a;a=t.pop())a.setError(!0)};g.send(d)}}else c.setSuccess(!1)};k.enable?B().success(function(){d()}).error(function(){c.setError()}):d();return c.promise};b.clearToken=function(){b.token&&(w(null,null,null),b.onAuthLogout&&b.onAuthLogout(),b.loginRequired&& | ||
b.login())};b.callback_id=0;var G=function(){function a(){for(var a=(new Date).getTime(),b=0;b<localStorage.length;b++){var e=localStorage.key(b);if(e&&0==e.indexOf("kc-callback-")){var f=localStorage.getItem(e);if(f)try{var g=JSON.parse(f).expires;(!g||g<a)&&localStorage.removeItem(e)}catch(z){localStorage.removeItem(e)}}}}if(!(this instanceof G))return new G;localStorage.setItem("kc-test","test");localStorage.removeItem("kc-test");this.get=function(b){if(b){b="kc-callback-"+b;var c=localStorage.getItem(b); | ||
c&&(localStorage.removeItem(b),c=JSON.parse(c));a();return c}};this.add=function(b){a();var c="kc-callback-"+b.state;b.expires=(new Date).getTime()+36E5;localStorage.setItem(c,JSON.stringify(b))}},H=function(){if(!(this instanceof H))return new H;this.get=function(c){if(c){var d;a:{d="kc-callback-"+c+"\x3d";for(var f=document.cookie.split(";"),g=0;g<f.length;g++){for(var h=f[g];" "==h.charAt(0);)h=h.substring(1);if(0==h.indexOf(d)){d=h.substring(d.length,h.length);break a}}d=""}b("kc-callback-"+c, | ||
"",a(-100));if(d)return JSON.parse(d)}};this.add=function(c){b("kc-callback-"+c.state,JSON.stringify(c),a(60))};this.removeItem=function(c){b(c,"",a(-100))};var a=function(a){var b=new Date;b.setTime(b.getTime()+6E4*a);return b},b=function(a,b,c){a=a+"\x3d"+b+"; expires\x3d"+c.toUTCString()+"; ";document.cookie=a}}};"object"===typeof module&&module&&"object"===typeof module.exports?module.exports=y:(h.Keycloak=y,"function"===typeof define&&define.amd&&define("keycloak",[],function(){return y}))})(window); | ||
//# sourceMappingURL=keycloak.min.js.map |
{ | ||
"name": "keycloak-js", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "Keycloak Adapter", | ||
@@ -5,0 +5,0 @@ "main": "dist/keycloak.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
250006
2195
1