Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

keycloak-js

Package Overview
Dependencies
Maintainers
2
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keycloak-js - npm Package Compare versions

Comparing version 1.9.8 to 2.1.0

dist/keycloak-authz.js

2

bower.json
{
"name": "keycloak",
"version": "1.9.8",
"version": "2.1.0",
"main": "dist/keycloak.js",

@@ -5,0 +5,0 @@ "ignore": [

@@ -28,3 +28,3 @@ /*

var refreshQueue = [];
var storage;
var callbackStorage;

@@ -40,8 +40,14 @@ var loginIframe = {

storage = new PersistentStorage();
callbackStorage = createCallbackStorage();
if (window.Cordova) {
if (initOptions && initOptions.adapter === 'cordova') {
adapter = loadAdapter('cordova');
} else if (initOptions && initOptions.adapter === 'default') {
adapter = loadAdapter();
} else {
adapter = loadAdapter();
if (window.Cordova) {
adapter = loadAdapter('cordova');
} else {
adapter = loadAdapter();
}
}

@@ -102,4 +108,4 @@

promise.setSuccess(kc.authenticated);
}).error(function() {
promise.setError();
}).error(function(errorData) {
promise.setError(errorData);
});

@@ -201,3 +207,3 @@

storage.setItem('oauthState', JSON.stringify({ state: state, nonce: nonce, redirectUri: encodeURIComponent(redirectUri) }));
callbackStorage.add({ state: state, nonce: nonce, redirectUri: encodeURIComponent(redirectUri) });

@@ -209,2 +215,4 @@ var action = 'auth';

var scope = (options && options.scope) ? "openid " + options.scope : "openid";
var url = getRealmUrl()

@@ -217,3 +225,4 @@ + '/protocol/openid-connect/' + action

+ '&response_mode=' + encodeURIComponent(kc.responseMode)
+ '&response_type=' + encodeURIComponent(kc.responseType);
+ '&response_type=' + encodeURIComponent(kc.responseType)
+ '&scope=' + encodeURIComponent(scope);

@@ -224,2 +233,6 @@ if (options && options.prompt) {

if (options && options.maxAge) {
url += '&max_age=' + encodeURIComponent(options.maxAge);
}
if (options && options.loginHint) {

@@ -233,6 +246,2 @@ url += '&login_hint=' + encodeURIComponent(options.loginHint);

if (options && options.scope) {
url += '&scope=' + encodeURIComponent(options.scope);
}
if (options && options.locale) {

@@ -468,4 +477,5 @@ url += '&ui_locales=' + encodeURIComponent(options.locale);

if (prompt != 'none') {
kc.onAuthError && kc.onAuthError();
promise && promise.setError();
var errorData = { error: error, error_description: oauth.error_description };
kc.onAuthError && kc.onAuthError(errorData);
promise && promise.setError(errorData);
} else {

@@ -703,12 +713,8 @@ promise && promise.setSuccess();

var oauth = new CallbackParser(url, kc.responseMode).parseUri();
var oauthState = callbackStorage.get(oauth.state);
var oauthState = storage.getItem('oauthState');
var sessionState = oauthState && JSON.parse(oauthState);
if (oauthState && (oauth.code || oauth.error || oauth.access_token || oauth.id_token)) {
oauth.redirectUri = oauthState.redirectUri;
oauth.storedNonce = oauthState.nonce;
if (sessionState && (oauth.code || oauth.error || oauth.access_token || oauth.id_token) && oauth.state && oauth.state == sessionState.state) {
storage.removeItem('oauthState');
oauth.redirectUri = sessionState.redirectUri;
oauth.storedNonce = sessionState.nonce;
if (oauth.fragment) {

@@ -799,4 +805,18 @@ oauth.newUrl += '#' + oauth.fragment;

}
var data = JSON.parse(event.data);
try {
var data = JSON.parse(event.data);
} catch (err) {
return;
}
if (!data.callbackId) {
return;
}
var promise = loginIframe.callbackMap[data.callbackId];
if (!promise) {
return;
}
delete loginIframe.callbackMap[data.callbackId];

@@ -990,50 +1010,83 @@

var LocalStorage = function() {
if (!(this instanceof LocalStorage)) {
return new LocalStorage();
}
var PersistentStorage = function() {
if (!(this instanceof PersistentStorage)) {
return new PersistentStorage();
localStorage.setItem('kc-test', 'test');
localStorage.removeItem('kc-test');
var cs = this;
function clearExpired() {
var time = new Date().getTime();
for (var i = 1; i <= localStorage.length; i++) {
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);
}
}
}
}
}
var ps = this;
var useCookieStorage = function () {
if (typeof localStorage === "undefined") {
return true;
cs.get = function(state) {
if (!state) {
return;
}
try {
var key = '@@keycloak-session-storage/test';
localStorage.setItem(key, 'test');
var key = 'kc-callback-' + state;
var value = localStorage.getItem(key);
if (value) {
localStorage.removeItem(key);
return false;
} catch (err) {
// Probably in Safari "private mode" where localStorage
// quota is 0, or quota exceeded. Switching to cookie
// storage.
return true;
value = JSON.parse(value);
}
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();
}
var cs = this;
ps.setItem = function(key, value) {
if (useCookieStorage()) {
setCookie(key, value, cookieExpiration(5));
} else {
localStorage.setItem(key, value);
cs.get = function(state) {
if (!state) {
return;
}
}
ps.getItem = function(key) {
if (useCookieStorage()) {
return getCookie(key);
var value = getCookie('kc-callback-' + state);
setCookie('kc-callback-' + state, '', cookieExpiration(-100));
if (value) {
return JSON.parse(value);
}
return localStorage.getItem(key);
}
};
ps.removeItem = function(key) {
if (typeof localStorage !== "undefined") {
try {
// Always try to delete from localStorage.
localStorage.removeItem(key);
} catch (err) { }
}
// Always remove the cookie.
cs.add = function(state) {
setCookie('kc-callback-' + state.state, JSON.stringify(state), cookieExpiration(60));
};
cs.removeItem = function(key) {
setCookie(key, '', cookieExpiration(-100));
}
};

@@ -1044,3 +1097,3 @@ var cookieExpiration = function (minutes) {

return exp;
}
};

@@ -1060,3 +1113,3 @@ var getCookie = function (key) {

return '';
}
};

@@ -1068,2 +1121,11 @@ var setCookie = function (key, value, expirationDate) {

}
};
function createCallbackStorage() {
try {
return new LocalStorage();
} catch (err) {
}
return new CookieStorage();
}

@@ -1115,3 +1177,3 @@

var handleQueryParam = function(paramName, paramValue, oauth) {
var supportedOAuthParams = [ 'code', 'error', 'state' ];
var supportedOAuthParams = [ 'code', 'state', 'error', 'error_description' ];

@@ -1118,0 +1180,0 @@ for (var i = 0 ; i< supportedOAuthParams.length ; i++) {

@@ -1,1 +0,1 @@

(function(a,c){var b=function(x){if(!(this instanceof b)){return new b(x)}var g=this;var m;var q=[];var r;var s={enable:true,callbackMap:[],interval:5};g.init=function(C){g.authenticated=false;r=new v();if(a.Cordova){m=u("cordova")}else{m=u()}if(C){if(typeof C.checkLoginIframe!=="undefined"){s.enable=C.checkLoginIframe}if(C.checkLoginIframeInterval){s.interval=C.checkLoginIframeInterval}if(C.onLoad==="login-required"){g.loginRequired=true}if(C.responseMode){if(C.responseMode==="query"||C.responseMode==="fragment"){g.responseMode=C.responseMode}else{throw"Invalid value for responseMode"}}if(C.flow){switch(C.flow){case"standard":g.responseType="code";break;case"implicit":g.responseType="id_token token";break;case"hybrid":g.responseType="code id_token token";break;default:throw"Invalid value for flow"}g.flow=C.flow}}if(!g.responseMode){g.responseMode="fragment"}if(!g.responseType){g.responseType="code";g.flow="standard"}var D=d();var z=d();z.promise.success(function(){g.onReady&&g.onReady(g.authenticated);D.setSuccess(g.authenticated)}).error(function(){D.setError()});var B=h(x);function A(){var F=function(G){if(!G){E.prompt="none"}g.login(E).success(function(){z.setSuccess()}).error(function(){z.setError()})};var E={};switch(C.onLoad){case"check-sso":if(s.enable){w().success(function(){j().success(function(){F(false)}).error(function(){z.setSuccess()})})}else{F(false)}break;case"login-required":F(true);break;default:throw"Invalid value for onLoad"}}function y(){var E=f(a.location.href);if(E){w();a.history.replaceState({},null,E.newUrl);k(E,z);return}else{if(C){if(C.token||C.refreshToken){p(C.token,C.refreshToken,C.idToken,false);g.timeSkew=C.timeSkew||0;if(s.enable){w().success(function(){j().success(function(){z.setSuccess()}).error(function(){if(C.onLoad){A()}})})}else{z.setSuccess()}}else{if(C.onLoad){A()}else{z.setSuccess()}}}else{z.setSuccess()}}}B.success(y);B.error(function(){D.setError()});return D.promise};g.login=function(y){return m.login(y)};g.createLoginUrl=function(z){var C=e();var A=e();var D=m.redirectUri(z);if(z&&z.prompt){D+=(D.indexOf("?")==-1?"?":"&")+"prompt="+z.prompt}r.setItem("oauthState",JSON.stringify({state:C,nonce:A,redirectUri:encodeURIComponent(D)}));var B="auth";if(z&&z.action=="register"){B="registrations"}var y=l()+"/protocol/openid-connect/"+B+"?client_id="+encodeURIComponent(g.clientId)+"&redirect_uri="+encodeURIComponent(D)+"&state="+encodeURIComponent(C)+"&nonce="+encodeURIComponent(A)+"&response_mode="+encodeURIComponent(g.responseMode)+"&response_type="+encodeURIComponent(g.responseType);if(z&&z.prompt){y+="&prompt="+encodeURIComponent(z.prompt)}if(z&&z.loginHint){y+="&login_hint="+encodeURIComponent(z.loginHint)}if(z&&z.idpHint){y+="&kc_idp_hint="+encodeURIComponent(z.idpHint)}if(z&&z.scope){y+="&scope="+encodeURIComponent(z.scope)}if(z&&z.locale){y+="&ui_locales="+encodeURIComponent(z.locale)}return y};g.logout=function(y){return m.logout(y)};g.createLogoutUrl=function(z){var y=l()+"/protocol/openid-connect/logout?redirect_uri="+encodeURIComponent(m.redirectUri(z,false));return y};g.register=function(y){return m.register(y)};g.createRegisterUrl=function(y){if(!y){y={}}y.action="register";return g.createLoginUrl(y)};g.createAccountUrl=function(z){var y=l()+"/account?referrer="+encodeURIComponent(g.clientId)+"&referrer_uri="+encodeURIComponent(m.redirectUri(z));return y};g.accountManagement=function(){return m.accountManagement()};g.hasRealmRole=function(z){var y=g.realmAccess;return !!y&&y.roles.indexOf(z)>=0};g.hasResourceRole=function(A,z){if(!g.resourceAccess){return false}var y=g.resourceAccess[z||g.clientId];return !!y&&y.roles.indexOf(A)>=0};g.loadUserProfile=function(){var y=l()+"/account";var z=new XMLHttpRequest();z.open("GET",y,true);z.setRequestHeader("Accept","application/json");z.setRequestHeader("Authorization","bearer "+g.token);var A=d();z.onreadystatechange=function(){if(z.readyState==4){if(z.status==200){g.profile=JSON.parse(z.responseText);A.setSuccess(g.profile)}else{A.setError()}}};z.send();return A.promise};g.loadUserInfo=function(){var y=l()+"/protocol/openid-connect/userinfo";var z=new XMLHttpRequest();z.open("GET",y,true);z.setRequestHeader("Accept","application/json");z.setRequestHeader("Authorization","bearer "+g.token);var A=d();z.onreadystatechange=function(){if(z.readyState==4){if(z.status==200){g.userInfo=JSON.parse(z.responseText);A.setSuccess(g.userInfo)}else{A.setError()}}};z.send();return A.promise};g.isTokenExpired=function(y){if(!g.tokenParsed||(!g.refreshToken&&g.flow!="implicit")){throw"Not authenticated"}var z=g.tokenParsed.exp-(new Date().getTime()/1000)+g.timeSkew;if(y){z-=y}return z<0};g.updateToken=function(y){var B=d();if(!g.tokenParsed||!g.refreshToken){B.setError();return B.promise}y=y||5;var z=function(){if(!g.isTokenExpired(y)){B.setSuccess(false)}else{var F="grant_type=refresh_token&refresh_token="+g.refreshToken;var D=l()+"/protocol/openid-connect/token";q.push(B);if(q.length==1){var E=new XMLHttpRequest();E.open("POST",D,true);E.setRequestHeader("Content-type","application/x-www-form-urlencoded");if(g.clientId&&g.clientSecret){E.setRequestHeader("Authorization","Basic "+btoa(g.clientId+":"+g.clientSecret))}else{F+="&client_id="+encodeURIComponent(g.clientId)}var C=new Date().getTime();E.onreadystatechange=function(){if(E.readyState==4){if(E.status==200){C=(C+new Date().getTime())/2;var H=JSON.parse(E.responseText);p(H.access_token,H.refresh_token,H.id_token,true);g.timeSkew=Math.floor(C/1000)-g.tokenParsed.iat;g.onAuthRefreshSuccess&&g.onAuthRefreshSuccess();for(var G=q.pop();G!=null;G=q.pop()){G.setSuccess(true)}}else{g.onAuthRefreshError&&g.onAuthRefreshError();for(var G=q.pop();G!=null;G=q.pop()){G.setError(true)}}}};E.send(F)}}};if(s.enable){var A=j();A.success(function(){z()}).error(function(){B.setError()})}else{z()}return B.promise};g.clearToken=function(){if(g.token){p(null,null,null,true);g.onAuthLogout&&g.onAuthLogout();if(g.loginRequired){g.login()}}};function l(){if(g.authServerUrl.charAt(g.authServerUrl.length-1)=="/"){return g.authServerUrl+"realms/"+encodeURIComponent(g.realm)}else{return g.authServerUrl+"/realms/"+encodeURIComponent(g.realm)}}function t(){if(!a.location.origin){return a.location.protocol+"//"+a.location.hostname+(a.location.port?":"+a.location.port:"")}else{return a.location.origin}}function k(E,H){var A=E.code;var F=E.error;var B=E.prompt;var z=new Date().getTime();if(F){if(B!="none"){g.onAuthError&&g.onAuthError();H&&H.setError()}else{H&&H.setSuccess()}return}else{if((g.flow!="standard")&&(E.access_token||E.id_token)){D(E.access_token,null,E.id_token,true)}}if((g.flow!="implicit")&&A){var C="code="+A+"&grant_type=authorization_code";var y=l()+"/protocol/openid-connect/token";var G=new XMLHttpRequest();G.open("POST",y,true);G.setRequestHeader("Content-type","application/x-www-form-urlencoded");if(g.clientId&&g.clientSecret){G.setRequestHeader("Authorization","Basic "+btoa(g.clientId+":"+g.clientSecret))}else{C+="&client_id="+encodeURIComponent(g.clientId)}C+="&redirect_uri="+E.redirectUri;G.withCredentials=true;G.onreadystatechange=function(){if(G.readyState==4){if(G.status==200){var I=JSON.parse(G.responseText);D(I.access_token,I.refresh_token,I.id_token,g.flow==="standard")}else{g.onAuthError&&g.onAuthError();H&&H.setError()}}};G.send(C)}function D(I,J,L,K){z=(z+new Date().getTime())/2;p(I,J,L,true);if((g.tokenParsed&&g.tokenParsed.nonce!=E.storedNonce)||(g.refreshTokenParsed&&g.refreshTokenParsed.nonce!=E.storedNonce)||(g.idTokenParsed&&g.idTokenParsed.nonce!=E.storedNonce)){console.log("invalid nonce!");g.clearToken();H&&H.setError()}else{g.timeSkew=Math.floor(z/1000)-g.tokenParsed.iat;if(K){g.onAuthSuccess&&g.onAuthSuccess();H&&H.setSuccess()}}}}function h(A){var D=d();var z;if(!x){z="keycloak.json"}else{if(typeof x==="string"){z=x}}if(z){var C=new XMLHttpRequest();C.open("GET",z,true);C.setRequestHeader("Accept","application/json");C.onreadystatechange=function(){if(C.readyState==4){if(C.status==200){var E=JSON.parse(C.responseText);g.authServerUrl=E["auth-server-url"];g.realm=E.realm;g.clientId=E.resource;g.clientSecret=(E.credentials||{})["secret"];D.setSuccess()}else{D.setError()}}};C.send()}else{if(!x.url){var y=document.getElementsByTagName("script");for(var B=0;B<y.length;B++){if(y[B].src.match(/.*keycloak\.js/)){x.url=y[B].src.substr(0,y[B].src.indexOf("/js/keycloak.js"));break}}}if(!x.realm){throw"realm missing"}if(!x.clientId){throw"clientId missing"}g.authServerUrl=x.url;g.realm=x.realm;g.clientId=x.clientId;g.clientSecret=(x.credentials||{}).secret;D.setSuccess()}return D.promise}function p(B,A,E,y){if(g.tokenTimeoutHandle){clearTimeout(g.tokenTimeoutHandle);g.tokenTimeoutHandle=null}if(B){g.token=B;g.tokenParsed=n(B);var C=g.realm+"/"+g.tokenParsed.sub;if(g.tokenParsed.session_state){C=C+"/"+g.tokenParsed.session_state}g.sessionId=C;g.authenticated=true;g.subject=g.tokenParsed.sub;g.realmAccess=g.tokenParsed.realm_access;g.resourceAccess=g.tokenParsed.resource_access;if(g.onTokenExpired){var D=y?g.tokenParsed.iat:(new Date().getTime()/1000);var z=g.tokenParsed.exp-D;g.tokenTimeoutHandle=setTimeout(g.onTokenExpired,z*1000)}}else{delete g.token;delete g.tokenParsed;delete g.subject;delete g.realmAccess;delete g.resourceAccess;g.authenticated=false}if(A){g.refreshToken=A;g.refreshTokenParsed=n(A)}else{delete g.refreshToken;delete g.refreshTokenParsed}if(E){g.idToken=E;g.idTokenParsed=n(E)}else{delete g.idToken;delete g.idTokenParsed}}function n(y){y=y.split(".")[1];y=y.replace("/-/g","+");y=y.replace("/_/g","/");switch(y.length%4){case 0:break;case 2:y+="==";break;case 3:y+="=";break;default:throw"Invalid token"}y=(y+"===").slice(0,y.length+(y.length%4));y=y.replace(/-/g,"+").replace(/_/g,"/");y=decodeURIComponent(escape(atob(y)));y=JSON.parse(y);return y}function e(){var B=[];var y="0123456789abcdef";for(var z=0;z<36;z++){B[z]=y.substr(Math.floor(Math.random()*16),1)}B[14]="4";B[19]=y.substr((B[19]&3)|8,1);B[8]=B[13]=B[18]=B[23]="-";var A=B.join("");return A}g.callback_id=0;function o(){var y="<id: "+(g.callback_id++)+(Math.random())+">";return y}function f(A){var y=new i(A,g.responseMode).parseUri();var B=r.getItem("oauthState");var z=B&&JSON.parse(B);if(z&&(y.code||y.error||y.access_token||y.id_token)&&y.state&&y.state==z.state){r.removeItem("oauthState");y.redirectUri=z.redirectUri;y.storedNonce=z.nonce;if(y.fragment){y.newUrl+="#"+y.fragment}return y}}function d(){var y={setSuccess:function(z){y.success=true;y.result=z;if(y.successCallback){y.successCallback(z)}},setError:function(z){y.error=true;y.result=z;if(y.errorCallback){y.errorCallback(z)}},promise:{success:function(z){if(y.success){z(y.result)}else{if(!y.error){y.successCallback=z}}return y.promise},error:function(z){if(y.error){z(y.result)}else{if(!y.success){y.errorCallback=z}}return y.promise}}};return y}function w(){var C=d();if(!s.enable){C.setSuccess();return C.promise}if(s.iframe){C.setSuccess();return C.promise}var A=document.createElement("iframe");s.iframe=A;A.onload=function(){var D=l();if(D.charAt(0)==="/"){s.iframeOrigin=t()}else{s.iframeOrigin=D.substring(0,D.indexOf("/",8))}C.setSuccess();setTimeout(y,s.interval*1000)};var B=l()+"/protocol/openid-connect/login-status-iframe.html?client_id="+encodeURIComponent(g.clientId)+"&origin="+t();A.setAttribute("src",B);A.style.display="none";document.body.appendChild(A);var z=function(D){if(D.origin!==s.iframeOrigin){return}var E=JSON.parse(D.data);var F=s.callbackMap[E.callbackId];delete s.callbackMap[E.callbackId];if((!g.sessionId||g.sessionId==E.session)&&E.loggedIn){F.setSuccess()}else{g.clearToken();F.setError()}};a.addEventListener("message",z,false);var y=function(){j();if(g.token){setTimeout(y,s.interval*1000)}};return C.promise}function j(){var A=d();if(s.iframe&&s.iframeOrigin){var z={};z.callbackId=o();s.callbackMap[z.callbackId]=A;var y=s.iframeOrigin;s.iframe.contentWindow.postMessage(JSON.stringify(z),y)}else{A.setSuccess()}return A.promise}function u(y){if(!y||y=="default"){return{login:function(z){a.location.href=g.createLoginUrl(z);return d().promise},logout:function(z){a.location.href=g.createLogoutUrl(z);return d().promise},register:function(z){a.location.href=g.createRegisterUrl(z);return d().promise},accountManagement:function(){a.location.href=g.createAccountUrl();return d().promise},redirectUri:function(z,A){if(arguments.length==1){A=true}if(z&&z.redirectUri){return z.redirectUri}else{if(g.redirectUri){return g.redirectUri}else{var B=location.href;if(location.hash&&A){B=B.substring(0,location.href.indexOf("#"));B+=(B.indexOf("?")==-1?"?":"&")+"redirect_fragment="+encodeURIComponent(location.hash.substring(1))}return B}}}}}if(y=="cordova"){s.enable=false;return{login:function(z){var E=d();var D="location=no";if(z&&z.prompt=="none"){D+=",hidden=yes"}var C=g.createLoginUrl(z);var B=a.open(C,"_blank",D);var A=false;B.addEventListener("loadstart",function(F){if(F.url.indexOf("http://localhost")==0){var G=f(F.url);k(G,E);B.close();A=true}});B.addEventListener("loaderror",function(F){if(!A){if(F.url.indexOf("http://localhost")==0){var G=f(F.url);k(G,E);B.close();A=true}else{E.setError();B.close()}}});return E.promise},logout:function(B){var D=d();var z=g.createLogoutUrl(B);var C=a.open(z,"_blank","location=no,hidden=yes");var A;C.addEventListener("loadstart",function(E){if(E.url.indexOf("http://localhost")==0){C.close()}});C.addEventListener("loaderror",function(E){if(E.url.indexOf("http://localhost")==0){C.close()}else{A=true;C.close()}});C.addEventListener("exit",function(E){if(A){D.setError()}else{g.clearToken();D.setSuccess()}});return D.promise},register:function(){var z=g.createRegisterUrl();var A=a.open(z,"_blank","location=no");A.addEventListener("loadstart",function(B){if(B.url.indexOf("http://localhost")==0){A.close()}})},accountManagement:function(){var z=g.createAccountUrl();var A=a.open(z,"_blank","location=no");A.addEventListener("loadstart",function(B){if(B.url.indexOf("http://localhost")==0){A.close()}})},redirectUri:function(z){return"http://localhost"}}}throw"invalid adapter type: "+y}var v=function(){if(!(this instanceof v)){return new v()}var C=this;var y=function(){if(typeof localStorage==="undefined"){return true}try{var D="@@keycloak-session-storage/test";localStorage.setItem(D,"test");localStorage.removeItem(D);return false}catch(E){return true}};C.setItem=function(D,E){if(y()){A(D,E,B(5))}else{localStorage.setItem(D,E)}};C.getItem=function(D){if(y()){return z(D)}return localStorage.getItem(D)};C.removeItem=function(D){if(typeof localStorage!=="undefined"){try{localStorage.removeItem(D)}catch(E){}}A(D,"",B(-100))};var B=function(D){var E=new Date();E.setTime(E.getTime()+(D*60*1000));return E};var z=function(G){var E=G+"=";var D=document.cookie.split(";");for(var F=0;F<D.length;F++){var H=D[F];while(H.charAt(0)==" "){H=H.substring(1)}if(H.indexOf(E)==0){return H.substring(E.length,H.length)}}return""};var A=function(F,G,D){var E=F+"="+G+"; expires="+D.toUTCString()+"; ";document.cookie=E}};var i=function(y,B){if(!(this instanceof i)){return new i(y,B)}var D=this;var z=function(){var H=null;var I=null;var G=null;var E=y.indexOf("?");var F=y.indexOf("#",E+1);if(E==-1&&F==-1){H=y}else{if(E!=-1){H=y.substring(0,E);I=y.substring(E+1);if(F!=-1){F=I.indexOf("#");G=I.substring(F+1);I=I.substring(0,F)}}else{H=y.substring(0,F);G=y.substring(F+1)}}return{baseUri:H,queryString:I,fragmentString:G}};var A=function(K){var E={};var J=K.split("&");for(var F=0;F<J.length;F++){var H=J[F].split("=");var G=decodeURIComponent(H[0]);var I=decodeURIComponent(H[1]);E[G]=I}return E};var C=function(H,I,E){var G=["code","error","state"];for(var F=0;F<G.length;F++){if(H===G[F]){E[H]=I;return true}}return false};D.parseUri=function(){var I=z();var G={};if(I.queryString){G=A(I.queryString)}var E={newUrl:I.baseUri};for(var H in G){switch(H){case"redirect_fragment":E.fragment=G[H];break;case"prompt":E.prompt=G[H];break;default:if(B!="query"||!C(H,G[H],E)){E.newUrl+=(E.newUrl.indexOf("?")==-1?"?":"&")+H+"="+G[H]}break}}if(B==="fragment"){var F={};if(I.fragmentString){F=A(I.fragmentString)}for(var H in F){E[H]=F[H]}}return E}}};if(typeof module==="object"&&module&&typeof module.exports==="object"){module.exports=b}else{a.Keycloak=b;if(typeof define==="function"&&define.amd){define("keycloak",[],function(){return b})}}})(window);
(function(a,c){var b=function(z){if(!(this instanceof b)){return new b(z)}var h=this;var p;var u=[];var f;var v={enable:true,callbackMap:[],interval:5};h.init=function(E){h.authenticated=false;f=q();if(E&&E.adapter==="cordova"){p=x("cordova")}else{if(E&&E.adapter==="default"){p=x()}else{if(a.Cordova){p=x("cordova")}else{p=x()}}}if(E){if(typeof E.checkLoginIframe!=="undefined"){v.enable=E.checkLoginIframe}if(E.checkLoginIframeInterval){v.interval=E.checkLoginIframeInterval}if(E.onLoad==="login-required"){h.loginRequired=true}if(E.responseMode){if(E.responseMode==="query"||E.responseMode==="fragment"){h.responseMode=E.responseMode}else{throw"Invalid value for responseMode"}}if(E.flow){switch(E.flow){case"standard":h.responseType="code";break;case"implicit":h.responseType="id_token token";break;case"hybrid":h.responseType="code id_token token";break;default:throw"Invalid value for flow"}h.flow=E.flow}}if(!h.responseMode){h.responseMode="fragment"}if(!h.responseType){h.responseType="code";h.flow="standard"}var F=d();var B=d();B.promise.success(function(){h.onReady&&h.onReady(h.authenticated);F.setSuccess(h.authenticated)}).error(function(G){F.setError(G)});var D=j(z);function C(){var H=function(I){if(!I){G.prompt="none"}h.login(G).success(function(){B.setSuccess()}).error(function(){B.setError()})};var G={};switch(E.onLoad){case"check-sso":if(v.enable){y().success(function(){l().success(function(){H(false)}).error(function(){B.setSuccess()})})}else{H(false)}break;case"login-required":H(true);break;default:throw"Invalid value for onLoad"}}function A(){var G=g(a.location.href);if(G){y();a.history.replaceState({},null,G.newUrl);n(G,B);return}else{if(E){if(E.token||E.refreshToken){t(E.token,E.refreshToken,E.idToken,false);h.timeSkew=E.timeSkew||0;if(v.enable){y().success(function(){l().success(function(){B.setSuccess()}).error(function(){if(E.onLoad){C()}})})}else{B.setSuccess()}}else{if(E.onLoad){C()}else{B.setSuccess()}}}else{B.setSuccess()}}}D.success(A);D.error(function(){F.setError()});return F.promise};h.login=function(A){return p.login(A)};h.createLoginUrl=function(B){var F=e();var D=e();var G=p.redirectUri(B);if(B&&B.prompt){G+=(G.indexOf("?")==-1?"?":"&")+"prompt="+B.prompt}f.add({state:F,nonce:D,redirectUri:encodeURIComponent(G)});var E="auth";if(B&&B.action=="register"){E="registrations"}var C=(B&&B.scope)?"openid "+B.scope:"openid";var A=o()+"/protocol/openid-connect/"+E+"?client_id="+encodeURIComponent(h.clientId)+"&redirect_uri="+encodeURIComponent(G)+"&state="+encodeURIComponent(F)+"&nonce="+encodeURIComponent(D)+"&response_mode="+encodeURIComponent(h.responseMode)+"&response_type="+encodeURIComponent(h.responseType)+"&scope="+encodeURIComponent(C);if(B&&B.prompt){A+="&prompt="+encodeURIComponent(B.prompt)}if(B&&B.maxAge){A+="&max_age="+encodeURIComponent(B.maxAge)}if(B&&B.loginHint){A+="&login_hint="+encodeURIComponent(B.loginHint)}if(B&&B.idpHint){A+="&kc_idp_hint="+encodeURIComponent(B.idpHint)}if(B&&B.locale){A+="&ui_locales="+encodeURIComponent(B.locale)}return A};h.logout=function(A){return p.logout(A)};h.createLogoutUrl=function(B){var A=o()+"/protocol/openid-connect/logout?redirect_uri="+encodeURIComponent(p.redirectUri(B,false));return A};h.register=function(A){return p.register(A)};h.createRegisterUrl=function(A){if(!A){A={}}A.action="register";return h.createLoginUrl(A)};h.createAccountUrl=function(B){var A=o()+"/account?referrer="+encodeURIComponent(h.clientId)+"&referrer_uri="+encodeURIComponent(p.redirectUri(B));return A};h.accountManagement=function(){return p.accountManagement()};h.hasRealmRole=function(B){var A=h.realmAccess;return !!A&&A.roles.indexOf(B)>=0};h.hasResourceRole=function(C,B){if(!h.resourceAccess){return false}var A=h.resourceAccess[B||h.clientId];return !!A&&A.roles.indexOf(C)>=0};h.loadUserProfile=function(){var A=o()+"/account";var B=new XMLHttpRequest();B.open("GET",A,true);B.setRequestHeader("Accept","application/json");B.setRequestHeader("Authorization","bearer "+h.token);var C=d();B.onreadystatechange=function(){if(B.readyState==4){if(B.status==200){h.profile=JSON.parse(B.responseText);C.setSuccess(h.profile)}else{C.setError()}}};B.send();return C.promise};h.loadUserInfo=function(){var A=o()+"/protocol/openid-connect/userinfo";var B=new XMLHttpRequest();B.open("GET",A,true);B.setRequestHeader("Accept","application/json");B.setRequestHeader("Authorization","bearer "+h.token);var C=d();B.onreadystatechange=function(){if(B.readyState==4){if(B.status==200){h.userInfo=JSON.parse(B.responseText);C.setSuccess(h.userInfo)}else{C.setError()}}};B.send();return C.promise};h.isTokenExpired=function(A){if(!h.tokenParsed||(!h.refreshToken&&h.flow!="implicit")){throw"Not authenticated"}var B=h.tokenParsed.exp-(new Date().getTime()/1000)+h.timeSkew;if(A){B-=A}return B<0};h.updateToken=function(A){var D=d();if(!h.tokenParsed||!h.refreshToken){D.setError();return D.promise}A=A||5;var B=function(){if(!h.isTokenExpired(A)){D.setSuccess(false)}else{var H="grant_type=refresh_token&refresh_token="+h.refreshToken;var F=o()+"/protocol/openid-connect/token";u.push(D);if(u.length==1){var G=new XMLHttpRequest();G.open("POST",F,true);G.setRequestHeader("Content-type","application/x-www-form-urlencoded");if(h.clientId&&h.clientSecret){G.setRequestHeader("Authorization","Basic "+btoa(h.clientId+":"+h.clientSecret))}else{H+="&client_id="+encodeURIComponent(h.clientId)}var E=new Date().getTime();G.onreadystatechange=function(){if(G.readyState==4){if(G.status==200){E=(E+new Date().getTime())/2;var J=JSON.parse(G.responseText);t(J.access_token,J.refresh_token,J.id_token,true);h.timeSkew=Math.floor(E/1000)-h.tokenParsed.iat;h.onAuthRefreshSuccess&&h.onAuthRefreshSuccess();for(var I=u.pop();I!=null;I=u.pop()){I.setSuccess(true)}}else{h.onAuthRefreshError&&h.onAuthRefreshError();for(var I=u.pop();I!=null;I=u.pop()){I.setError(true)}}}};G.send(H)}}};if(v.enable){var C=l();C.success(function(){B()}).error(function(){D.setError()})}else{B()}return D.promise};h.clearToken=function(){if(h.token){t(null,null,null,true);h.onAuthLogout&&h.onAuthLogout();if(h.loginRequired){h.login()}}};function o(){if(h.authServerUrl.charAt(h.authServerUrl.length-1)=="/"){return h.authServerUrl+"realms/"+encodeURIComponent(h.realm)}else{return h.authServerUrl+"/realms/"+encodeURIComponent(h.realm)}}function w(){if(!a.location.origin){return a.location.protocol+"//"+a.location.hostname+(a.location.port?":"+a.location.port:"")}else{return a.location.origin}}function n(H,K){var D=H.code;var I=H.error;var E=H.prompt;var C=new Date().getTime();if(I){if(E!="none"){var B={error:I,error_description:H.error_description};h.onAuthError&&h.onAuthError(B);K&&K.setError(B)}else{K&&K.setSuccess()}return}else{if((h.flow!="standard")&&(H.access_token||H.id_token)){G(H.access_token,null,H.id_token,true)}}if((h.flow!="implicit")&&D){var F="code="+D+"&grant_type=authorization_code";var A=o()+"/protocol/openid-connect/token";var J=new XMLHttpRequest();J.open("POST",A,true);J.setRequestHeader("Content-type","application/x-www-form-urlencoded");if(h.clientId&&h.clientSecret){J.setRequestHeader("Authorization","Basic "+btoa(h.clientId+":"+h.clientSecret))}else{F+="&client_id="+encodeURIComponent(h.clientId)}F+="&redirect_uri="+H.redirectUri;J.withCredentials=true;J.onreadystatechange=function(){if(J.readyState==4){if(J.status==200){var L=JSON.parse(J.responseText);G(L.access_token,L.refresh_token,L.id_token,h.flow==="standard")}else{h.onAuthError&&h.onAuthError();K&&K.setError()}}};J.send(F)}function G(L,M,O,N){C=(C+new Date().getTime())/2;t(L,M,O,true);if((h.tokenParsed&&h.tokenParsed.nonce!=H.storedNonce)||(h.refreshTokenParsed&&h.refreshTokenParsed.nonce!=H.storedNonce)||(h.idTokenParsed&&h.idTokenParsed.nonce!=H.storedNonce)){console.log("invalid nonce!");h.clearToken();K&&K.setError()}else{h.timeSkew=Math.floor(C/1000)-h.tokenParsed.iat;if(N){h.onAuthSuccess&&h.onAuthSuccess();K&&K.setSuccess()}}}}function j(C){var F=d();var B;if(!z){B="keycloak.json"}else{if(typeof z==="string"){B=z}}if(B){var E=new XMLHttpRequest();E.open("GET",B,true);E.setRequestHeader("Accept","application/json");E.onreadystatechange=function(){if(E.readyState==4){if(E.status==200){var G=JSON.parse(E.responseText);h.authServerUrl=G["auth-server-url"];h.realm=G.realm;h.clientId=G.resource;h.clientSecret=(G.credentials||{})["secret"];F.setSuccess()}else{F.setError()}}};E.send()}else{if(!z.url){var A=document.getElementsByTagName("script");for(var D=0;D<A.length;D++){if(A[D].src.match(/.*keycloak\.js/)){z.url=A[D].src.substr(0,A[D].src.indexOf("/js/keycloak.js"));break}}}if(!z.realm){throw"realm missing"}if(!z.clientId){throw"clientId missing"}h.authServerUrl=z.url;h.realm=z.realm;h.clientId=z.clientId;h.clientSecret=(z.credentials||{}).secret;F.setSuccess()}return F.promise}function t(D,C,G,A){if(h.tokenTimeoutHandle){clearTimeout(h.tokenTimeoutHandle);h.tokenTimeoutHandle=null}if(D){h.token=D;h.tokenParsed=r(D);var E=h.realm+"/"+h.tokenParsed.sub;if(h.tokenParsed.session_state){E=E+"/"+h.tokenParsed.session_state}h.sessionId=E;h.authenticated=true;h.subject=h.tokenParsed.sub;h.realmAccess=h.tokenParsed.realm_access;h.resourceAccess=h.tokenParsed.resource_access;if(h.onTokenExpired){var F=A?h.tokenParsed.iat:(new Date().getTime()/1000);var B=h.tokenParsed.exp-F;h.tokenTimeoutHandle=setTimeout(h.onTokenExpired,B*1000)}}else{delete h.token;delete h.tokenParsed;delete h.subject;delete h.realmAccess;delete h.resourceAccess;h.authenticated=false}if(C){h.refreshToken=C;h.refreshTokenParsed=r(C)}else{delete h.refreshToken;delete h.refreshTokenParsed}if(G){h.idToken=G;h.idTokenParsed=r(G)}else{delete h.idToken;delete h.idTokenParsed}}function r(A){A=A.split(".")[1];A=A.replace("/-/g","+");A=A.replace("/_/g","/");switch(A.length%4){case 0:break;case 2:A+="==";break;case 3:A+="=";break;default:throw"Invalid token"}A=(A+"===").slice(0,A.length+(A.length%4));A=A.replace(/-/g,"+").replace(/_/g,"/");A=decodeURIComponent(escape(atob(A)));A=JSON.parse(A);return A}function e(){var D=[];var A="0123456789abcdef";for(var B=0;B<36;B++){D[B]=A.substr(Math.floor(Math.random()*16),1)}D[14]="4";D[19]=A.substr((D[19]&3)|8,1);D[8]=D[13]=D[18]=D[23]="-";var C=D.join("");return C}h.callback_id=0;function s(){var A="<id: "+(h.callback_id++)+(Math.random())+">";return A}function g(B){var A=new k(B,h.responseMode).parseUri();var C=f.get(A.state);if(C&&(A.code||A.error||A.access_token||A.id_token)){A.redirectUri=C.redirectUri;A.storedNonce=C.nonce;if(A.fragment){A.newUrl+="#"+A.fragment}return A}}function d(){var A={setSuccess:function(B){A.success=true;A.result=B;if(A.successCallback){A.successCallback(B)}},setError:function(B){A.error=true;A.result=B;if(A.errorCallback){A.errorCallback(B)}},promise:{success:function(B){if(A.success){B(A.result)}else{if(!A.error){A.successCallback=B}}return A.promise},error:function(B){if(A.error){B(A.result)}else{if(!A.success){A.errorCallback=B}}return A.promise}}};return A}function y(){var E=d();if(!v.enable){E.setSuccess();return E.promise}if(v.iframe){E.setSuccess();return E.promise}var C=document.createElement("iframe");v.iframe=C;C.onload=function(){var F=o();if(F.charAt(0)==="/"){v.iframeOrigin=w()}else{v.iframeOrigin=F.substring(0,F.indexOf("/",8))}E.setSuccess();setTimeout(A,v.interval*1000)};var D=o()+"/protocol/openid-connect/login-status-iframe.html?client_id="+encodeURIComponent(h.clientId)+"&origin="+w();C.setAttribute("src",D);C.style.display="none";document.body.appendChild(C);var B=function(G){if(G.origin!==v.iframeOrigin){return}try{var H=JSON.parse(G.data)}catch(F){return}if(!H.callbackId){return}var I=v.callbackMap[H.callbackId];if(!I){return}delete v.callbackMap[H.callbackId];if((!h.sessionId||h.sessionId==H.session)&&H.loggedIn){I.setSuccess()}else{h.clearToken();I.setError()}};a.addEventListener("message",B,false);var A=function(){l();if(h.token){setTimeout(A,v.interval*1000)}};return E.promise}function l(){var C=d();if(v.iframe&&v.iframeOrigin){var B={};B.callbackId=s();v.callbackMap[B.callbackId]=C;var A=v.iframeOrigin;v.iframe.contentWindow.postMessage(JSON.stringify(B),A)}else{C.setSuccess()}return C.promise}function x(A){if(!A||A=="default"){return{login:function(B){a.location.href=h.createLoginUrl(B);return d().promise},logout:function(B){a.location.href=h.createLogoutUrl(B);return d().promise},register:function(B){a.location.href=h.createRegisterUrl(B);return d().promise},accountManagement:function(){a.location.href=h.createAccountUrl();return d().promise},redirectUri:function(B,C){if(arguments.length==1){C=true}if(B&&B.redirectUri){return B.redirectUri}else{if(h.redirectUri){return h.redirectUri}else{var D=location.href;if(location.hash&&C){D=D.substring(0,location.href.indexOf("#"));D+=(D.indexOf("?")==-1?"?":"&")+"redirect_fragment="+encodeURIComponent(location.hash.substring(1))}return D}}}}}if(A=="cordova"){v.enable=false;return{login:function(B){var G=d();var F="location=no";if(B&&B.prompt=="none"){F+=",hidden=yes"}var E=h.createLoginUrl(B);var D=a.open(E,"_blank",F);var C=false;D.addEventListener("loadstart",function(H){if(H.url.indexOf("http://localhost")==0){var I=g(H.url);n(I,G);D.close();C=true}});D.addEventListener("loaderror",function(H){if(!C){if(H.url.indexOf("http://localhost")==0){var I=g(H.url);n(I,G);D.close();C=true}else{G.setError();D.close()}}});return G.promise},logout:function(D){var F=d();var B=h.createLogoutUrl(D);var E=a.open(B,"_blank","location=no,hidden=yes");var C;E.addEventListener("loadstart",function(G){if(G.url.indexOf("http://localhost")==0){E.close()}});E.addEventListener("loaderror",function(G){if(G.url.indexOf("http://localhost")==0){E.close()}else{C=true;E.close()}});E.addEventListener("exit",function(G){if(C){F.setError()}else{h.clearToken();F.setSuccess()}});return F.promise},register:function(){var B=h.createRegisterUrl();var C=a.open(B,"_blank","location=no");C.addEventListener("loadstart",function(D){if(D.url.indexOf("http://localhost")==0){C.close()}})},accountManagement:function(){var B=h.createAccountUrl();var C=a.open(B,"_blank","location=no");C.addEventListener("loadstart",function(D){if(D.url.indexOf("http://localhost")==0){C.close()}})},redirectUri:function(B){return"http://localhost"}}}throw"invalid adapter type: "+A}var m=function(){if(!(this instanceof m)){return new m()}localStorage.setItem("kc-test","test");localStorage.removeItem("kc-test");var A=this;function B(){var H=new Date().getTime();for(var E=1;E<=localStorage.length;E++){var D=localStorage.key(E);if(D&&D.indexOf("kc-callback-")==0){var G=localStorage.getItem(D);if(G){try{var C=JSON.parse(G).expires;if(!C||C<H){localStorage.removeItem(D)}}catch(F){localStorage.removeItem(D)}}}}}A.get=function(E){if(!E){return}var C="kc-callback-"+E;var D=localStorage.getItem(C);if(D){localStorage.removeItem(C);D=JSON.parse(D)}B();return D};A.add=function(D){B();var C="kc-callback-"+D.state;D.expires=new Date().getTime()+(60*60*1000);localStorage.setItem(C,JSON.stringify(D))}};var i=function(){if(!(this instanceof i)){return new i()}var C=this;C.get=function(F){if(!F){return}var E=A("kc-callback-"+F);B("kc-callback-"+F,"",D(-100));if(E){return JSON.parse(E)}};C.add=function(E){B("kc-callback-"+E.state,JSON.stringify(E),D(60))};C.removeItem=function(E){B(E,"",D(-100))};var D=function(E){var F=new Date();F.setTime(F.getTime()+(E*60*1000));return F};var A=function(H){var F=H+"=";var E=document.cookie.split(";");for(var G=0;G<E.length;G++){var I=E[G];while(I.charAt(0)==" "){I=I.substring(1)}if(I.indexOf(F)==0){return I.substring(F.length,I.length)}}return""};var B=function(G,H,E){var F=G+"="+H+"; expires="+E.toUTCString()+"; ";document.cookie=F}};function q(){try{return new m()}catch(A){}return new i()}var k=function(A,D){if(!(this instanceof k)){return new k(A,D)}var F=this;var B=function(){var J=null;var K=null;var I=null;var G=A.indexOf("?");var H=A.indexOf("#",G+1);if(G==-1&&H==-1){J=A}else{if(G!=-1){J=A.substring(0,G);K=A.substring(G+1);if(H!=-1){H=K.indexOf("#");I=K.substring(H+1);K=K.substring(0,H)}}else{J=A.substring(0,H);I=A.substring(H+1)}}return{baseUri:J,queryString:K,fragmentString:I}};var C=function(M){var G={};var L=M.split("&");for(var H=0;H<L.length;H++){var J=L[H].split("=");var I=decodeURIComponent(J[0]);var K=decodeURIComponent(J[1]);G[I]=K}return G};var E=function(J,K,G){var I=["code","state","error","error_description"];for(var H=0;H<I.length;H++){if(J===I[H]){G[J]=K;return true}}return false};F.parseUri=function(){var K=B();var I={};if(K.queryString){I=C(K.queryString)}var G={newUrl:K.baseUri};for(var J in I){switch(J){case"redirect_fragment":G.fragment=I[J];break;case"prompt":G.prompt=I[J];break;default:if(D!="query"||!E(J,I[J],G)){G.newUrl+=(G.newUrl.indexOf("?")==-1?"?":"&")+J+"="+I[J]}break}}if(D==="fragment"){var H={};if(K.fragmentString){H=C(K.fragmentString)}for(var J in H){G[J]=H[J]}}return G}}};if(typeof module==="object"&&module&&typeof module.exports==="object"){module.exports=b}else{a.Keycloak=b;if(typeof define==="function"&&define.amd){define("keycloak",[],function(){return b})}}})(window);
{
"name": "keycloak-js",
"version": "1.9.8",
"version": "2.1.0",
"description": "Keycloak Adapter",

@@ -5,0 +5,0 @@ "main": "dist/keycloak.js",

keycloak-adapter-bower
======================
A [Bower](http://bower.io) project for the [Keycloak](http://keycloak.jboss.org/) [javascript adapter](http://keycloak.github.io/docs/userguide/keycloak-server/html/ch08.html#javascript-adapter).
A [Bower](http://bower.io) project for the [Keycloak](http://www.keycloak.org/) [javascript adapter](https://keycloak.gitbooks.io/securing-client-applications-guide/content/topics/oidc/javascript-adapter.html).

@@ -6,0 +6,0 @@ # Usage

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc