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.8.1 to 1.9.0-cr.1

2

bower.json
{
"name": "keycloak",
"version": "1.8.1",
"version": "1.9.0-cr.1",
"main": "dist/keycloak.js",

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

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

/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function( window, undefined ) {

@@ -871,3 +888,6 @@

ref.addEventListener('loaderror', function(event) {
if (event.url.indexOf('http://localhost') != 0) {
if (event.url.indexOf('http://localhost') == 0) {
callback = parseCallback(event.url);
ref.close();
} else {
error = true;

@@ -904,3 +924,5 @@ ref.close();

ref.addEventListener('loaderror', function(event) {
if (event.url.indexOf('http://localhost') != 0) {
if (event.url.indexOf('http://localhost') == 0) {
ref.close();
} else {
error = true;

@@ -907,0 +929,0 @@ ref.close();

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

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

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

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