keycloak-js
Advanced tools
Comparing version 4.0.0-beta.2 to 4.0.0-beta.3
{ | ||
"name": "keycloak", | ||
"version": "4.0.0-beta.2", | ||
"version": "4.0.0-beta.3", | ||
"main": "dist/keycloak.js", | ||
@@ -5,0 +5,0 @@ "ignore": [ |
@@ -21,3 +21,3 @@ /* | ||
*/ | ||
import * as Keycloak from 'keycloak'; | ||
import * as Keycloak from './keycloak'; | ||
@@ -39,2 +39,60 @@ export as namespace KeycloakAuthorization; | ||
interface AuthorizationRequest { | ||
/** | ||
* An array of objects representing the resource and scopes. | ||
*/ | ||
permissions?:ResourcePermission[], | ||
/** | ||
* A permission ticket obtained from a resource server when using UMA authorization protocol. | ||
*/ | ||
ticket?:string, | ||
/** | ||
* A boolean value indicating whether the server should create permission requests to the resources | ||
* and scopes referenced by a permission ticket. This parameter will only take effect when used together | ||
* with the ticket parameter as part of a UMA authorization process. | ||
*/ | ||
submitRequest?:boolean, | ||
/** | ||
* Defines additional information about this authorization request in order to specify how it should be processed | ||
* by the server. | ||
*/ | ||
metadata?:AuthorizationRequestMetadata, | ||
/** | ||
* Defines whether or not this authorization request should include the current RPT. If set to true, the RPT will | ||
* be sent and permissions in the current RPT will be included in the new RPT. Otherwise, only the permissions referenced in this | ||
* authorization request will be granted in the new RPT. | ||
*/ | ||
incrementalAuthorization?:boolean | ||
} | ||
interface AuthorizationRequestMetadata { | ||
/** | ||
* A boolean value indicating to the server if resource names should be included in the RPT’s permissions. | ||
* If false, only the resource identifier is included. | ||
*/ | ||
responseIncludeResourceName?:any, | ||
/** | ||
* An integer N that defines a limit for the amount of permissions an RPT can have. When used together with | ||
* rpt parameter, only the last N requested permissions will be kept in the RPT. | ||
*/ | ||
response_permissions_limit?:number | ||
} | ||
interface ResourcePermission { | ||
/** | ||
* The id or name of a resource. | ||
*/ | ||
id:string, | ||
/** | ||
* An array of strings where each value is the name of a scope associated with the resource. | ||
*/ | ||
scopes?:string[] | ||
} | ||
interface KeycloakAuthorizationInstance { | ||
@@ -47,16 +105,21 @@ rpt: any; | ||
/** | ||
* This method enables client applications to better integrate with resource servers protected by a Keycloak | ||
* policy enforcer. | ||
* | ||
* In this case, the resource server will respond with a 401 status code and a WWW-Authenticate header holding the | ||
* necessary information to ask a Keycloak server for authorization data using both UMA and Entitlement protocol, | ||
* depending on how the policy enforcer at the resource server was configured. | ||
*/ | ||
authorize(wwwAuthenticateHeader: string): KeycloakAuthorizationPromise; | ||
* This method enables client applications to better integrate with resource servers protected by a Keycloak | ||
* policy enforcer using UMA protocol. | ||
* | ||
* The authorization request must be provided with a ticket. | ||
* | ||
* @param authorizationRequest An AuthorizationRequest instance with a valid permission ticket set. | ||
* @returns A promise to set functions to be invoked on grant, deny or error. | ||
*/ | ||
authorize(authorizationRequest: AuthorizationRequest): KeycloakAuthorizationPromise; | ||
/** | ||
* Obtains all entitlements from a Keycloak server based on a given resourceServerId. | ||
* | ||
* @param resourceServerId The id (client id) of the resource server to obtain permissions from. | ||
* @param authorizationRequest An AuthorizationRequest instance. | ||
* @returns A promise to set functions to be invoked on grant, deny or error. | ||
*/ | ||
entitlement(resourceServerId: string, entitlementRequest: {}): KeycloakAuthorizationPromise; | ||
entitlement(resourceServerId: string, authorizationRequest?: AuthorizationRequest): KeycloakAuthorizationPromise; | ||
} | ||
} |
@@ -44,7 +44,5 @@ /* | ||
* This method enables client applications to better integrate with resource servers protected by a Keycloak | ||
* policy enforcer. | ||
* policy enforcer using UMA protocol. | ||
* | ||
* In this case, the resource server will respond with a 401 status code and a WWW-Authenticate header holding the | ||
* necessary information to ask a Keycloak server for authorization data using both UMA and Entitlement protocol, | ||
* depending on how the policy enforcer at the resource server was configured. | ||
* The authorization request must be provided with a ticket. | ||
*/ | ||
@@ -209,2 +207,4 @@ this.authorize = function (authorizationRequest) { | ||
this.init(this); | ||
return this; | ||
}; | ||
@@ -211,0 +211,0 @@ |
@@ -6,3 +6,3 @@ (function(q,p){var h=function(k,h){var f=this;this.rpt=null;this.init=function(){var a=new XMLHttpRequest;a.open("GET",k.authServerUrl+"/realms/"+k.realm+"/.well-known/uma2-configuration");a.onreadystatechange=function(){4==a.readyState&&(200==a.status?f.config=JSON.parse(a.responseText):console.error("Could not obtain configuration from server."))};a.send(null)};this.authorize=function(a){this.then=function(e,h,m){if(a&&a.ticket){var d=new XMLHttpRequest;d.open("POST",f.config.token_endpoint,!0); | ||
k.clientId;e.claimToken&&(b+="\x26claim_token\x3d"+e.claimToken,e.claimTokenFormat&&(b+="\x26claim_token_format\x3d"+e.claimTokenFormat));var b=b+("\x26audience\x3d"+a),g=e.permissions;g||(g=[]);for(i=0;i<g.length;i++){var n=g[i],l=n.id;if(n.scopes&&0<n.scopes.length)for(l+="#",j=0;j<n.scopes.length;j++){var p=n.scopes[j];l.indexOf("#")!=l.length-1&&(l+=",");l+=p}b+="\x26permission\x3d"+l}if(g=e.metadata)g.responseIncludeResourceName&&(b+="\x26response_include_resource_name\x3d"+g.responseIncludeResourceName), | ||
g.responsePermissionsLimit&&(b+="\x26response_permissions_limit\x3d"+g.responsePermissionsLimit);f.rpt&&(b+="\x26rpt\x3d"+f.rpt);c.send(b)};return this};this.init(this)};"object"===typeof module&&module&&"object"===typeof module.exports?module.exports=h:(q.KeycloakAuthorization=h,"function"===typeof define&&define.amd&&define("keycloak-authorization",[],function(){return h}))})(window); | ||
g.responsePermissionsLimit&&(b+="\x26response_permissions_limit\x3d"+g.responsePermissionsLimit);f.rpt&&(b+="\x26rpt\x3d"+f.rpt);c.send(b)};return this};this.init(this);return this};"object"===typeof module&&module&&"object"===typeof module.exports?module.exports=h:(q.KeycloakAuthorization=h,"function"===typeof define&&define.amd&&define("keycloak-authorization",[],function(){return h}))})(window); | ||
//# sourceMappingURL=keycloak-authz.min.js.map |
@@ -1190,2 +1190,30 @@ /* | ||
}; | ||
var shallowCloneCordovaOptions = function (userOptions) { | ||
if (userOptions && userOptions.cordovaOptions) { | ||
return Object.keys(userOptions.cordovaOptions).reduce(function (options, optionName) { | ||
options[optionName] = userOptions.cordovaOptions[optionName]; | ||
return options; | ||
}, {}); | ||
} else { | ||
return {}; | ||
} | ||
}; | ||
var formatCordovaOptions = function (cordovaOptions) { | ||
return Object.keys(cordovaOptions).reduce(function (options, optionName) { | ||
options.push(optionName+"="+cordovaOptions[optionName]); | ||
return options; | ||
}, []).join(","); | ||
}; | ||
var createCordovaOptions = function (userOptions) { | ||
var cordovaOptions = shallowCloneCordovaOptions(userOptions); | ||
cordovaOptions.location = 'no'; | ||
if (userOptions && userOptions.prompt == 'none') { | ||
cordovaOptions.hidden = 'yes'; | ||
} | ||
return formatCordovaOptions(cordovaOptions); | ||
}; | ||
return { | ||
@@ -1195,10 +1223,12 @@ login: function(options) { | ||
var o = 'location=no'; | ||
if (options && options.prompt == 'none') { | ||
o += ',hidden=yes'; | ||
} | ||
var cordovaOptions = createCordovaOptions(options); | ||
var loginUrl = kc.createLoginUrl(options); | ||
var ref = cordovaOpenWindowWrapper(loginUrl, '_blank', o); | ||
var ref = cordovaOpenWindowWrapper(loginUrl, '_blank', cordovaOptions); | ||
var completed = false; | ||
var closed = false; | ||
var closeBrowser = function() { | ||
closed = true; | ||
ref.close(); | ||
}; | ||
@@ -1209,3 +1239,3 @@ ref.addEventListener('loadstart', function(event) { | ||
processCallback(callback, promise); | ||
ref.close(); | ||
closeBrowser(); | ||
completed = true; | ||
@@ -1220,7 +1250,7 @@ } | ||
processCallback(callback, promise); | ||
ref.close(); | ||
closeBrowser(); | ||
completed = true; | ||
} else { | ||
promise.setError(); | ||
ref.close(); | ||
closeBrowser(); | ||
} | ||
@@ -1230,2 +1260,10 @@ } | ||
ref.addEventListener('exit', function(event) { | ||
if (!closed) { | ||
promise.setError({ | ||
reason: "closed_by_user" | ||
}); | ||
} | ||
}); | ||
return promise.promise; | ||
@@ -1236,3 +1274,3 @@ }, | ||
var promise = createPromise(); | ||
var logoutUrl = kc.createLogoutUrl(options); | ||
@@ -1272,3 +1310,4 @@ var ref = cordovaOpenWindowWrapper(logoutUrl, '_blank', 'location=no,hidden=yes'); | ||
var registerUrl = kc.createRegisterUrl(); | ||
var ref = cordovaOpenWindowWrapper(registerUrl, '_blank', 'location=no'); | ||
var cordovaOptions = createCordovaOptions(options); | ||
var ref = cordovaOpenWindowWrapper(registerUrl, '_blank', cordovaOptions); | ||
ref.addEventListener('loadstart', function(event) { | ||
@@ -1275,0 +1314,0 @@ if (event.url.indexOf('http://localhost') == 0) { |
@@ -1,40 +0,40 @@ | ||
(function(k,I){var x=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(e,d,g,f){q=(q+(new Date).getTime())/2;w(e,d,g,q);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,g=a.error,f=a.prompt,q=(new Date).getTime();if(g)"none"!=f?(d={error:g,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", | ||
g=b.endpoints.token(),n=new XMLHttpRequest;n.open("POST",g,!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, | ||
(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'; | ||
},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 g=new XMLHttpRequest;g.open("GET",d,!0);g.setRequestHeader("Accept","application/json");g.onreadystatechange=function(){if(4==g.readyState)if(200==g.status||0==g.status&&g.responseText&&g.responseURL.startsWith("file:")){var a=JSON.parse(g.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()};g.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",g=new XMLHttpRequest,g.open("GET",a,!0),g.setRequestHeader("Accept","application/json"),g.onreadystatechange=function(){if(4==g.readyState)if(200==g.status||0==g.status&&g.responseText&&g.responseURL.startsWith("file:")){var a= | ||
JSON.parse(g.responseText);c(a);e.setSuccess()}else e.setError()},g.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 w(a,c,e,d){b.tokenTimeoutHandle&&(clearTimeout(b.tokenTimeoutHandle),b.tokenTimeoutHandle=null);c? | ||
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 "+ | ||
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("#"),g,f;"query"===b.responseMode&&-1!==e?(g=a.substring(0,e),f=K(a.substring(e+1,-1!==d?d:a.length),c),""!==f.paramsString&&(g+="?"+f.paramsString),-1!==d&&(g+=a.substring(d))):"fragment"===b.responseMode&&-1!==d&&(g=a.substring(0,d),f=K(a.substring(d+ | ||
1),c),""!==f.paramsString&&(g+="#"+f.paramsString));if(f&&f.oauthParams)if("standard"===b.flow||"hybrid"===b.flow){if((f.oauthParams.code||f.oauthParams.error)&&f.oauthParams.state){f.oauthParams.newUrl=g;a=f.oauthParams;break a}}else if("implicit"===b.flow&&(f.oauthParams.access_token||f.oauthParams.error)&&f.oauthParams.state){f.oauthParams.newUrl=g;a=f.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 g=a[d].split("\x3d");-1!==b.indexOf(g[0])?c.oauthParams[g[0]]=g[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); | ||
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),e=c.length-1;0<=e;--e){var d=c[e];"unchanged"==a.data?d.setSuccess():d.setError()}}},!1);var d=function(){z();b.token&&setTimeout(d,1E3*h.interval)};return a.promise}function z(){var a=m();if(h.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)};return{login:function(a){var d=m(),e="location\x3dno";a&&"none"==a.prompt&&(e+=",hidden\x3dyes"); | ||
a=b.createLoginUrl(a);var f=c(a,"_blank",e),q=!1;f.addEventListener("loadstart",function(a){0==a.url.indexOf("http://localhost")&&(a=E(a.url),B(a,d),f.close(),q=!0)});f.addEventListener("loaderror",function(a){q||(0==a.url.indexOf("http://localhost")?(a=E(a.url),B(a,d),f.close(),q=!0):(d.setError(),f.close()))});return d.promise},logout:function(a){var d=m();a=b.createLogoutUrl(a);var e=c(a,"_blank","location\x3dno,hidden\x3dyes"),f;e.addEventListener("loadstart",function(a){0==a.url.indexOf("http://localhost")&& | ||
e.close()});e.addEventListener("loaderror",function(a){0!=a.url.indexOf("http://localhost")&&(f=!0);e.close()});e.addEventListener("exit",function(a){f?d.setError():(b.clearToken(),d.setSuccess())});return d.promise},register:function(){var a=b.createRegisterUrl(),d=c(a,"_blank","location\x3dno");d.addEventListener("loadstart",function(a){0==a.url.indexOf("http://localhost")&&d.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 x))return new x(l);for(var b=this,r,u=[],y,h={enable:!0,callbackList:[],interval:5},v=document.getElementsByTagName("script"),t=0;t<v.length;t++)-1===v[t].src.indexOf("keycloak.js")&&-1===v[t].src.indexOf("keycloak.min.js")||-1===v[t].src.indexOf("version\x3d")|| | ||
(b.iframeVersion=v[t].src.substring(v[t].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(f){}y=new H}r=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 g=L(l);g.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?(w(a.token,a.refreshToken,a.idToken),h.enable?F().success(function(){z().success(function(){b.onAuthSuccess&&b.onAuthSuccess();d.setSuccess()}).error(function(){w(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()});g.error(function(){e.setError()});return e.promise};b.login=function(a){return r.login(a)};b.createLoginUrl=function(a){var c=J(),e=J(),d=r.redirectUri(a),g={state:c,nonce:e,redirectUri:encodeURIComponent(d)};a&&a.prompt&&(g.prompt=a.prompt);y.add(g);var g=a&&"register"==a.action?b.endpoints.register():b.endpoints.authorize(),f=a&&a.scope?"openid "+ | ||
a.scope:"openid",c=g+"?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(f);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 r.logout(a)};b.createLogoutUrl=function(a){return b.endpoints.logout()+"?redirect_uri\x3d"+encodeURIComponent(r.redirectUri(a,!1))};b.register=function(a){return r.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(r.redirectUri(a)));return e};b.accountManagement=function(){return r.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();u.push(c);if(1==u.length){var f= | ||
new XMLHttpRequest;f.open("POST",e,!0);f.setRequestHeader("Content-type","application/x-www-form-urlencoded");f.withCredentials=!0;b.clientId&&b.clientSecret?f.setRequestHeader("Authorization","Basic "+btoa(b.clientId+":"+b.clientSecret)):d+="\x26client_id\x3d"+encodeURIComponent(b.clientId);var h=(new Date).getTime();f.onreadystatechange=function(){if(4==f.readyState)if(200==f.status){console.info("[KEYCLOAK] Token refreshed");h=(h+(new Date).getTime())/2;var a=JSON.parse(f.responseText);w(a.access_token, | ||
a.refresh_token,a.id_token,h);b.onAuthRefreshSuccess&&b.onAuthRefreshSuccess();for(a=u.pop();null!=a;a=u.pop())a.setSuccess(!0)}else for(console.warn("[KEYCLOAK] Failed to refresh token"),400==f.status&&b.clearToken(),b.onAuthRefreshError&&b.onAuthRefreshError(),a=u.pop();null!=a;a=u.pop())a.setError(!0)};f.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&&(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 d=localStorage.key(b);if(d&&0==d.indexOf("kc-callback-")){var g=localStorage.getItem(d);if(g)try{var f=JSON.parse(g).expires;(!f||f<a)&&localStorage.removeItem(d)}catch(q){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(";"),f=0;f<e.length;f++){for(var h=e[f];" "==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=x:(k.Keycloak=x,"function"===typeof define&&define.amd&&define("keycloak", | ||
[],function(){return x}))})(window); | ||
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=a&&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); | ||
//# sourceMappingURL=keycloak.min.js.map |
{ | ||
"name": "keycloak-js", | ||
"version": "4.0.0-beta.2", | ||
"version": "4.0.0-beta.3", | ||
"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
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
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
242981
24
2110