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