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

@crossid/crossid-spa-js

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@crossid/crossid-spa-js - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

8

CHANGELOG.md
# @crossid/crossid-spa-js
## 0.4.2
[All Changes](https://github.com/crossid/crossid-spa-js/compare/v0.4.1...v0.4.2)
### Major Changes
Add support for crossid region tenant configuration.
## 0.4.1

@@ -4,0 +12,0 @@

6

dist/client.d.ts

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

import { CACHE_INMEM, CACHE_LS, CACHE_SS } from './const';
import { CACHE_INMEM, CACHE_LS, CACHE_SS, REGION_EU, REGION_US } from './const';
import { IDToken, JWTClaims, LoginCompleteResponse, LogoutCompleteResponse } from './types';

@@ -64,2 +64,6 @@ /**

/**
* your crossid tenant region
*/
region: typeof REGION_US | typeof REGION_EU;
/**
* custom authorization server, defaults to `default`

@@ -66,0 +70,0 @@ */

@@ -15,1 +15,3 @@ export declare const CACHE_INMEM = "memory";

export declare const CACHE_IDX_KEY: string;
export declare const REGION_US = "us";
export declare const REGION_EU = "eu";

2

dist/crossid-spa-js.js

@@ -15,3 +15,3 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).crossid={})}(this,(function(t){"use strict";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,n)};function n(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function o(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function i(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))}function s(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}var a=function(t){function e(n,r){var o=t.call(this,r)||this;return o.error=n,o.error_description=r,Object.setPrototypeOf(o,e.prototype),o}return n(e,t),e.create=function(t){return new e(t.error,t.error_description)},e}(Error);function u(t){var e=t.wellknown_endpoint;return i(this,void 0,void 0,(function(){var t;return s(this,(function(n){switch(n.label){case 0:return[4,fetch(e)];case 1:return 200!==(t=n.sent()).status?[3,3]:[4,t.json()];case 2:return[2,n.sent()];case 3:throw Error("failed to discover data from well known discovery endpoint.")}}))}))}function c(t){var e=t.tokenEndpoint,n=t.timeout,u=o(t,["tokenEndpoint","timeout"]);return i(this,void 0,void 0,(function(){var t,o,c;return s(this,(function(l){switch(l.label){case 0:return t=new FormData,Object.keys(u).forEach((function(e){return t.append(e,u[e])})),[4,(p=e,h={timeout:n,method:"POST",body:t},void 0===h&&(h={}),i(void 0,void 0,void 0,(function(){var t,e,n,o,i;return s(this,(function(s){switch(s.label){case 0:return t=h.timeout,e=void 0===t?5e3:t,n=new AbortController,o=setTimeout((function(){return n.abort()}),e),[4,fetch(p,r(r({},h),{signal:n.signal}))];case 1:return i=s.sent(),clearTimeout(o),[2,i]}}))})))];case 1:return[4,(o=l.sent()).json()];case 2:if(c=l.sent(),200!==o.status)throw a.create(c);return[2,c]}var p,h}))}))}var l="memory",p="local_storage",h="session_storage",d="__",f="|",v="crossid-spa-js|index",_=function(t){return null!==t&&"Object"===(null==t?void 0:t.constructor.name)},y=function(t){return"number"==typeof t},g=function(t){return"string"==typeof t},w=String.fromCharCode(0),m=function(){function t(t,e){void 0===e&&(e={}),this.gopts=e,this.storage=t,e.purgeOnInit&&this.purge(!0)}return t.prototype.set=function(t,e,n){var r=this._key(t),o=this._ttl(null==n?void 0:n.ttl);try{var i=function(t,e){var n;return e&&e>0?((n={})[w]=t,n.ttl=Date.now()+1e3*e,n):t}(e,o);return this.storage.setItem(r,JSON.stringify(i)),!0}catch(t){return!1}},t.prototype.get=function(t,e){var n,r=this._key(t);try{var o=this.storage.getItem(r);if(null===o)return;var i=JSON.parse(o);return _(n=i)&&w in n?function(t,e){return Date.now()-1e3*e>t.ttl}(i,(null==e?void 0:e.ttl)||0)?void this.storage.removeItem(t):i[w]:i}catch(t){return}},t.prototype.remove=function(t){var e=this._key(t);return!!this.storage.getItem(e)&&(this.storage.removeItem(e),!0)},t.prototype.purge=function(t){var e=this;void 0===t&&(t=!1);var n=0;return Object.keys(this.storage).filter((function(t){return t.startsWith(e.gopts.prefix)})).forEach((function(r){var o=e.storage.getItem(r);if(o){var i;try{i=JSON.parse(o)}catch(t){return}(_(i)&&w in i&&Date.now()>i.ttl||t)&&(n++,e.storage.removeItem(r))}})),n},t.prototype._key=function(t){return this.gopts.prefix?""+this.gopts.prefix+t:t},t.prototype._ttl=function(t){return null===t?null:t||this.gopts.ttl||null},t}(),b=function(t){function e(e){var n=t.call(this,sessionStorage,e)||this;if("undefined"==typeof sessionStorage)throw Error("no support for session storage.");return n}return n(e,t),e}(m),k=function(t){function e(e){var n=t.call(this,localStorage,e)||this;if("undefined"==typeof localStorage)throw Error("no support for local storage.");return n}return n(e,t),e}(m),S=function(){function t(){}return t.prototype.getItem=function(t){return t in this?this[t]:null},t.prototype.setItem=function(t,e){void 0===e?this.removeItem(t):this[t]=""+e},t.prototype.removeItem=function(t){this.hasOwnProperty(t)&&delete this[t]},t}(),T=function(t){function e(e){return t.call(this,new S,e)||this}return n(e,t),e}(m),O=function(t){return Array.from(new Set(t))},j=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return O(t.join(" ").trim().split(/\s+/))},x=function(){return t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",e=Math.floor(86*Math.random()+43),Array.from(window.crypto.getRandomValues(new Uint8Array(e))).map((function(e){return t[e%t.length]})).join("");var t,e},A=function(t){return btoa(t)},E=function(t){return atob(t)},C=function(t){var e={"+":"-","/":"_","=":""};return t.replace(/[+/=]/g,(function(t){return e[t]}))},I=function(t){var e={"-":"+",_:"/"};return t.replace(/[-_]/g,(function(t){return e[t]}))},F=function(t){return Object.keys(t).filter((function(e){return void 0!==t[e]&&null!==t[e]})).map((function(e){return encodeURIComponent(e)+"="+encodeURIComponent(Array.isArray(t[e])?t[e].join(" "):t[e])})).join("&")},R=function(t){var e=t.split("."),n=e[0],r=e[1],o=e[2];if(3!==e.length||!n||!r||!o)throw new Error("malformed JWT token.");var i,s=JSON.parse(E(I(r)));if(s.aud)if(g(s.aud))s.aud=[s.aud];else if(i=s.aud,!Array.isArray(i)||!i.every((function(t){return g(t)})))throw new Error("Audience (aud) must be a string or an array of strings");return{header:JSON.parse(E(I(n))),payload:s}},K=function(t){function e(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var o=t.apply(this,n)||this;return o.fields_=e,o}return n(e,t),e.prototype.getMissingFields=function(){return this.fields_},e}(Error),D=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=e.map((function(e){return e(t)})).filter((function(t){return null!==t}));if(r&&r.length)throw new K(r,r.join(","));return null},U=function(t,e){var n=[];return function(r){return e&&e.filter((function(t){return!r.payload[t]})).forEach((function(t){return n.push(t)})),t&&t.filter((function(t){return!r.header[t]})).forEach((function(t){return n.push(t)})),n&&n.length?n.join(",")+" missing":null}},P=function(t){return function(e){return J("Issuer (iss)",t,e.payload.iss)}},z=function(t){return function(e){return J("Issuer (iss) claim",t,e.header.alg)}},L=function(t){return void 0===t&&(t=[]),function(e){return n=t,e.payload.aud.every((function(t){return n.includes(t)}))?null:"Audience (aud) claim mismatch: audience ("+e.payload.aud+") must contain only ("+t+")";var n}},N=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.exp)return null;if(!y(n.payload.exp))return"Expiration Time (exp) claim must be a present number";var r=W(n.payload.exp,e);return new Date(Date.now())>r?"Expiration Time (exp) claim expired ("+r+")":null}},q=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.nbf)return null;if(!y(n.payload.nbf))return"Not Before (nbf) claim must be a present number";var r=W(n.payload.nbf,-1*e),o=new Date(Date.now());return o<r?"Not Before (nbf) claim cannot be used yet, current time ("+o+") is before ("+r+")":null}},J=function(t,e,n){return e!==n?t+' mismatch: expected "'+e+'" but got "'+n+'"':null},W=function(t,e){void 0===e&&(e=0);var n=new Date(0);return n.setUTCSeconds(t+e),n},M=function(){function t(t){this.opts=t,this.loginStateKey="crossid-spa-js|login",this.logoutStateKey="crossid-spa-js|logout",this.scope=t.scope,this.state=this._stateFactory(this.opts.state_type||h),this.cache=this._cacheFactory(this.opts.cache_type||l),this._purgeIndex()}return t.prototype.createRedirectURL=function(t){return void 0===t&&(t={}),i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return[4,this._createAuthorizationData(t)];case 1:return e=n.sent(),[4,this._persistAuthorizationData(e)];case 2:return n.sent(),[2,this._authorizeUrl(e.request)]}}))}))},t.prototype.loginWithRedirect=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),window.location.replace(e),[2]}}))}))},t.prototype.createRegistrationUrl=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:if(!this.opts.registration_endpoint)throw new Error("registration_endpoint not defiend");return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),[2,this.opts.registration_endpoint+"?"+F({return_to:e})]}}))}))},t.prototype.registerWithRedirect=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return[4,this.createRegistrationUrl(t)];case 1:return e=n.sent(),window.location.replace(e),[2]}}))}))},t.prototype.handleRedirectCallback=function(t){return void 0===t&&(t=new URL(window.location.href)),i(this,void 0,void 0,(function(){var e,n,r,o,i,a,u;return s(this,(function(s){switch(s.label){case 0:if(e=t.searchParams,n=e.get("code"),r=e.get("error"))throw new Error(r);if(!(null==(o=this.state.get(this.loginStateKey))?void 0:o.code_verifier))throw new Error("invalid state, try sign-in again");return[4,c({tokenEndpoint:this.opts.token_endpoint,client_id:this.opts.client_id,code_verifier:o.code_verifier,grant_type:"authorization_code",redirect_uri:o.redirect_uri,code:n})];case 1:return(i=s.sent()).id_token&&((a=R(i.id_token)).payload.__bearer=i.id_token,this._assertIDToken(a,o.nonce)),u=R(i.access_token),this.state.remove(this.loginStateKey),this._assertAccessToken(u,o.audience),u.payload._raw=i.access_token,this._cacheTokens(a,u,i.refresh_token),[2,{state:o.state}]}}))}))},t.prototype.getUser=function(t){return void 0===t&&(t={}),i(this,void 0,void 0,(function(){var e,n,r,o;return s(this,(function(i){return e=this.getFinalAudience(t.audience),n=this.getFinalScope(t.scope),r=this._getTokensKeysFromCache("id_token",e,n),[2,null==(o=this._getNarrowedKey(r))?void 0:o.payload]}))}))},t.prototype.getAccessToken=function(t){var e;return void 0===t&&(t={}),i(this,void 0,void 0,(function(){var n,r,o,i;return s(this,(function(s){return n=this.getFinalAudience(t.audience),r=this.getFinalScope(t.scope),o=this._getTokensKeysFromCache("access_token",n,r),i=this._getNarrowedKey(o),[2,null===(e=null==i?void 0:i.payload)||void 0===e?void 0:e._raw]}))}))},t.prototype.introspectAccessToken=function(t){return void 0===t&&(t={}),i(this,void 0,void 0,(function(){var e,n,o,i;return s(this,(function(s){return e=this.getFinalAudience(t.audience),n=this.getFinalScope(t.scope),o=this._getTokensKeysFromCache("access_token",e,n),(i=this._getNarrowedKey(o))?[2,r(r({active:!0},i.payload),{_raw:void 0})]:[2,void 0]}))}))},t.prototype.createLogoutRedirectURL=function(t){return void 0===t&&(t={}),i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return[4,this._createLogoutData(t)];case 1:return e=n.sent(),e.request.id_token_hint&&t.post_logout_redirect_uri?[4,this._persistLogoutData(e)]:(this._removeTokens(e.audience,e.scopes),[2,this._logoutUrl()]);case 2:return n.sent(),[2,this._logoutUrl(e.request)]}}))}))},t.prototype.logoutWithRedirect=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return[4,this.createLogoutRedirectURL(t)];case 1:return e=n.sent(),window.location.assign(e),[2]}}))}))},t.prototype.handleLogoutRedirectCallback=function(t){return void 0===t&&(t=new URL(window.location.href)),i(this,void 0,void 0,(function(){var e,n,r,o;return s(this,(function(i){if(e=t.searchParams,n=e.get("state"),r=e.get("error"))throw new Error(r);if(!(null==(o=this.state.get(this.logoutStateKey))?void 0:o.state)||o.state!==n)throw new Error("invalid state, try sign-in again");return this._removeTokens(o.audience,o.scopes),this.state.remove(this.logoutStateKey),[2,{state:o.appState}]}))}))},t.prototype._createAuthorizationData=function(t){return i(this,void 0,void 0,(function(){var e,n,r,o,a,u;return s(this,(function(c){switch(c.label){case 0:return e=C(A(x())),n=C(A(x())),r=x(),[4,(p=r,i(void 0,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,window.crypto.subtle.digest({name:"SHA-256"},(new TextEncoder).encode(p))];case 1:return[2,t.sent()]}}))})))];case 1:return o=c.sent(),l=new Uint8Array(o),a=C(A(String.fromCharCode.apply(String,Array.from(l)))),u={audience:t.audience,redirect_uri:t.redirect_uri,response_type:t.response_type,scope:t.scope,state:e,nonce:n,code_challenge:a},[2,{request:this._mergeAuthorizationCodeParams(u),code_verifier:r,appState:t.state}]}var l,p}))}))},t.prototype._persistAuthorizationData=function(t){return i(this,void 0,void 0,(function(){var e,n;return s(this,(function(r){return e=t.request,n={audience:e.audience,redirect_uri:e.redirect_uri,scope:e.scope,nonce:e.nonce,state:t.appState,code_verifier:t.code_verifier},this.state.set(this.loginStateKey,n),[2]}))}))},t.prototype._mergeAuthorizationCodeParams=function(t){return{client_id:this.opts.client_id,audience:this.getFinalAudience(t.audience),response_type:t.response_type||this.opts.response_type||"code",redirect_uri:t.redirect_uri||this.opts.redirect_uri,nonce:t.nonce,state:t.state,scope:this.getFinalScope(t.scope).join(" "),code_challenge:t.code_challenge,code_challenge_method:"S256",ui_locales:t.ui_locales||this.opts.ui_locales,template_id:t.template_id||this.opts.template_id}},t.prototype._createLogoutData=function(t){return i(this,void 0,void 0,(function(){var e,n;return s(this,(function(r){switch(r.label){case 0:return(e={id_token_hint:t.id_token_hint,post_logout_redirect_uri:t.post_logout_redirect_uri}).id_token_hint||null===e.id_token_hint?[3,2]:[4,this.getUser()];case 1:(n=r.sent())&&n.__bearer&&(e.id_token_hint=n.__bearer),r.label=2;case 2:return e.id_token_hint&&(e.state=C(A(x()))),[2,{request:e,audience:t.audience||this.opts.audience,scopes:(t.scope||this.scope).split(" "),appState:t.state}]}}))}))},t.prototype._persistLogoutData=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){return e={client_id:this.opts.client_id,audience:t.audience,scopes:t.scopes,post_logout_redirect_uri:t.request.post_logout_redirect_uri,state:t.request.state,appState:t.appState},this.state.set(this.logoutStateKey,e),[2]}))}))},t.prototype._assertAccessToken=function(t,e){D(t,U(["alg"],["iss","sub","aud","exp","iat"]),P(this.opts.issuer),z("RS256"),L(e),N(!0),q(!0))},t.prototype._assertIDToken=function(t,e){var n;return D(t,U(["alg"],["iss","sub","aud","nonce","exp","iat"]),P(this.opts.issuer),(n=e,function(t){return J("Nonce (nonce)",n,t.payload.nonce)}),z("RS256"),L([this.opts.client_id]),N(!0),q(!1),(function(t){return y(t.payload.iat)?null:"Issued At (iat) claim must be a present number"})),null},t.prototype._removeTokens=function(t,e){var n=this,r=this._getTokensKeysFromCache("id_token",t,e),o=this._getTokensKeysFromCache("access_token",t,e),i=this._getTokensKeysFromCache("refresh_token",t,e);r.concat(o).concat(i).forEach((function(t){return n.cache.remove(t)})),this._purgeIndex()},t.prototype._authorizeUrl=function(t){return this.opts.authorization_endpoint+"?"+F(t)},t.prototype._logoutUrl=function(t){var e=this.opts.logout_endpoint;return t&&(e=e+"?"+F(t)),e},t.prototype._stateFactory=function(t){var e={ttl:300};switch(t){case p:return new k(e);case h:return new b(e);default:throw new Error('Invalid cache type "'+t+'"')}},t.prototype._cacheFactory=function(t){switch(t){case l:return new T;case p:return new k({purgeOnInit:!0});case h:return new b({purgeOnInit:!0});default:throw new Error('Invalid cache type "'+t+'"')}},t.prototype._cacheTokens=function(t,e,n){var r=this._ttlFromToken(e);this._cacheToken("access_token",e,this.opts.client_id,e.payload.aud,e.payload.scp,r),t&&this._cacheToken("id_token",t,this.opts.client_id,e.payload.aud,e.payload.scp||[],this._ttlFromToken(t)),n&&this._cacheToken("refresh_token",n,this.opts.client_id,e.payload.aud,e.payload.scp,432e3)},t.prototype._cacheToken=function(t,e,n,r,o,i){var s=this._cacheKey({tokType:t,client_id:n,audience:r,scope:o});this.cache.set(s,e,{ttl:i});var a=[r[0]||""],u=this.cache.get(v);u||(u={}),o=o.length?o:[""],a.forEach((function(t){u[t]||(u[t]={});var e=u[t];o.forEach((function(t){e[t]||(e[t]=[]),e[t].push(s)}))})),this.cache.set(v,u)},t.prototype._cacheKey=function(t){var e,n=t.tokType,r=t.client_id,o=t.audience,i=t.scope;return i&&i.length&&(i.sort(),e=i.join(d)),["crossid-spa-js",n,r,o.join(d),e].join(f)},t.prototype._decodeKey=function(t){var e=t.split(f),n=e[1],r=e[2],o=e[3];return{tokenType:n,audience:r.split(d),scope:o.split(d)}},t.prototype._getTokensKeysFromCache=function(t,e,n){var r=this;void 0===e&&(e=[""]);var o,i=(this.cache.get(v)||{})[e[0]]||[""];if(!i)return[];for(var s=function(e){return i[e]&&i[e].length?o?void(o=o.filter((function(t){return i[e].includes(t)}))):(o=i[e].filter((function(e){return r._decodeKey(e).tokenType===t})),"continue"):{value:[]}},a=0,u=n;a<u.length;a++){var c=s(u[a]);if("object"==typeof c)return c.value}return o},t.prototype._getNarrowedKey=function(t){for(var e in t){var n=this.cache.get(t[e]);if(n)return n}},t.prototype._ttlFromToken=function(t){return(new Date(1e3*t.payload.exp).getTime()-Date.now())/1e3},t.prototype._purgeIndex=function(){var t=this.cache.get(v);if(t){for(var e=0,n=Object.entries(t);e<n.length;e++){for(var r=n[e],o=r[0],i=r[1],s=function(e,n){for(var r=[],i=0;i<n.length;i++)a.cache.get(n[i])||r.push(i);t[o][e]=n.filter((function(t,e){return-1===r.indexOf(e)})),t[o][e].length||delete t[o][e]},a=this,u=0,c=Object.entries(i);u<c.length;u++){var l=c[u];s(l[0],l[1])}Object.keys(t[o]).length||delete t[o]}this.cache.set(v,t)}},t.prototype.getFinalAudience=function(t){return t||this.opts.audience},t.prototype.getFinalScope=function(t){return j(void 0!==t?t:this.scope)},t}();t.Client=M,t.OAuth2Error=a,t.newCrossidClient=function(t){return i(this,void 0,void 0,(function(){var e,n,r,i,a,c;return s(this,(function(s){switch(s.label){case 0:return e=t.tenant_id,n=t.auth_server,r=void 0===n?"default":n,i=o(t,["tenant_id","auth_server"]),a=i,[4,u({wellknown_endpoint:"https://"+e+".crossid.io/oauth2/"+r+"/.well-known/openid-configuration"})];case 1:return c=s.sent(),a.authorization_endpoint=c.authorization_endpoint,a.token_endpoint=c.token_endpoint,a.issuer=c.issuer,a.logout_endpoint=a.issuer+"logout",a.registration_endpoint="https://"+e+".crossid.io/auth/register",[2,new M(a)]}}))}))},t.newCrossidClientByDiscovery=function(t){return i(this,void 0,void 0,(function(){var e,n,r;return s(this,(function(i){switch(i.label){case 0:return[4,u(t)];case 1:return e=i.sent(),n=o(t,["wellknown_endpoint"]),(r=n).authorization_endpoint=e.authorization_endpoint,r.token_endpoint=e.token_endpoint,r.issuer=e.issuer,[2,new M(r)]}}))}))},t.newCrossidClientCustom=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new M(t)]}))}))},Object.defineProperty(t,"__esModule",{value:!0})}));
***************************************************************************** */var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,n)};function n(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function o(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function i(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))}function s(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}var a=function(t){function e(n,r){var o=t.call(this,r)||this;return o.error=n,o.error_description=r,Object.setPrototypeOf(o,e.prototype),o}return n(e,t),e.create=function(t){return new e(t.error,t.error_description)},e}(Error);function u(t){var e=t.wellknown_endpoint;return i(this,void 0,void 0,(function(){var t;return s(this,(function(n){switch(n.label){case 0:return[4,fetch(e)];case 1:return 200!==(t=n.sent()).status?[3,3]:[4,t.json()];case 2:return[2,n.sent()];case 3:throw Error("failed to discover data from well known discovery endpoint.")}}))}))}function c(t){var e=t.tokenEndpoint,n=t.timeout,u=o(t,["tokenEndpoint","timeout"]);return i(this,void 0,void 0,(function(){var t,o,c;return s(this,(function(l){switch(l.label){case 0:return t=new FormData,Object.keys(u).forEach((function(e){return t.append(e,u[e])})),[4,(p=e,h={timeout:n,method:"POST",body:t},void 0===h&&(h={}),i(void 0,void 0,void 0,(function(){var t,e,n,o,i;return s(this,(function(s){switch(s.label){case 0:return t=h.timeout,e=void 0===t?5e3:t,n=new AbortController,o=setTimeout((function(){return n.abort()}),e),[4,fetch(p,r(r({},h),{signal:n.signal}))];case 1:return i=s.sent(),clearTimeout(o),[2,i]}}))})))];case 1:return[4,(o=l.sent()).json()];case 2:if(c=l.sent(),200!==o.status)throw a.create(c);return[2,c]}var p,h}))}))}var l="memory",p="local_storage",h="session_storage",d="__",f="|",v="crossid-spa-js|index",_=function(t){return null!==t&&"Object"===(null==t?void 0:t.constructor.name)},y=function(t){return"number"==typeof t},g=function(t){return"string"==typeof t},w=String.fromCharCode(0),m=function(){function t(t,e){void 0===e&&(e={}),this.gopts=e,this.storage=t,e.purgeOnInit&&this.purge(!0)}return t.prototype.set=function(t,e,n){var r=this._key(t),o=this._ttl(null==n?void 0:n.ttl);try{var i=function(t,e){var n;return e&&e>0?((n={})[w]=t,n.ttl=Date.now()+1e3*e,n):t}(e,o);return this.storage.setItem(r,JSON.stringify(i)),!0}catch(t){return!1}},t.prototype.get=function(t,e){var n,r=this._key(t);try{var o=this.storage.getItem(r);if(null===o)return;var i=JSON.parse(o);return _(n=i)&&w in n?function(t,e){return Date.now()-1e3*e>t.ttl}(i,(null==e?void 0:e.ttl)||0)?void this.storage.removeItem(t):i[w]:i}catch(t){return}},t.prototype.remove=function(t){var e=this._key(t);return!!this.storage.getItem(e)&&(this.storage.removeItem(e),!0)},t.prototype.purge=function(t){var e=this;void 0===t&&(t=!1);var n=0;return Object.keys(this.storage).filter((function(t){return t.startsWith(e.gopts.prefix)})).forEach((function(r){var o=e.storage.getItem(r);if(o){var i;try{i=JSON.parse(o)}catch(t){return}(_(i)&&w in i&&Date.now()>i.ttl||t)&&(n++,e.storage.removeItem(r))}})),n},t.prototype._key=function(t){return this.gopts.prefix?""+this.gopts.prefix+t:t},t.prototype._ttl=function(t){return null===t?null:t||this.gopts.ttl||null},t}(),b=function(t){function e(e){var n=t.call(this,sessionStorage,e)||this;if("undefined"==typeof sessionStorage)throw Error("no support for session storage.");return n}return n(e,t),e}(m),k=function(t){function e(e){var n=t.call(this,localStorage,e)||this;if("undefined"==typeof localStorage)throw Error("no support for local storage.");return n}return n(e,t),e}(m),S=function(){function t(){}return t.prototype.getItem=function(t){return t in this?this[t]:null},t.prototype.setItem=function(t,e){void 0===e?this.removeItem(t):this[t]=""+e},t.prototype.removeItem=function(t){this.hasOwnProperty(t)&&delete this[t]},t}(),T=function(t){function e(e){return t.call(this,new S,e)||this}return n(e,t),e}(m),O=function(t){return Array.from(new Set(t))},j=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return O(t.join(" ").trim().split(/\s+/))},x=function(){return t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",e=Math.floor(86*Math.random()+43),Array.from(window.crypto.getRandomValues(new Uint8Array(e))).map((function(e){return t[e%t.length]})).join("");var t,e},A=function(t){return btoa(t)},E=function(t){return atob(t)},C=function(t){var e={"+":"-","/":"_","=":""};return t.replace(/[+/=]/g,(function(t){return e[t]}))},I=function(t){var e={"-":"+",_:"/"};return t.replace(/[-_]/g,(function(t){return e[t]}))},F=function(t){return Object.keys(t).filter((function(e){return void 0!==t[e]&&null!==t[e]})).map((function(e){return encodeURIComponent(e)+"="+encodeURIComponent(Array.isArray(t[e])?t[e].join(" "):t[e])})).join("&")},R=function(t){var e=t.split("."),n=e[0],r=e[1],o=e[2];if(3!==e.length||!n||!r||!o)throw new Error("malformed JWT token.");var i,s=JSON.parse(E(I(r)));if(s.aud)if(g(s.aud))s.aud=[s.aud];else if(i=s.aud,!Array.isArray(i)||!i.every((function(t){return g(t)})))throw new Error("Audience (aud) must be a string or an array of strings");return{header:JSON.parse(E(I(n))),payload:s}},K=function(t){function e(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var o=t.apply(this,n)||this;return o.fields_=e,o}return n(e,t),e.prototype.getMissingFields=function(){return this.fields_},e}(Error),D=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=e.map((function(e){return e(t)})).filter((function(t){return null!==t}));if(r&&r.length)throw new K(r,r.join(","));return null},U=function(t,e){var n=[];return function(r){return e&&e.filter((function(t){return!r.payload[t]})).forEach((function(t){return n.push(t)})),t&&t.filter((function(t){return!r.header[t]})).forEach((function(t){return n.push(t)})),n&&n.length?n.join(",")+" missing":null}},P=function(t){return function(e){return J("Issuer (iss)",t,e.payload.iss)}},z=function(t){return function(e){return J("Issuer (iss) claim",t,e.header.alg)}},L=function(t){return void 0===t&&(t=[]),function(e){return n=t,e.payload.aud.every((function(t){return n.includes(t)}))?null:"Audience (aud) claim mismatch: audience ("+e.payload.aud+") must contain only ("+t+")";var n}},N=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.exp)return null;if(!y(n.payload.exp))return"Expiration Time (exp) claim must be a present number";var r=W(n.payload.exp,e);return new Date(Date.now())>r?"Expiration Time (exp) claim expired ("+r+")":null}},q=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.nbf)return null;if(!y(n.payload.nbf))return"Not Before (nbf) claim must be a present number";var r=W(n.payload.nbf,-1*e),o=new Date(Date.now());return o<r?"Not Before (nbf) claim cannot be used yet, current time ("+o+") is before ("+r+")":null}},J=function(t,e,n){return e!==n?t+' mismatch: expected "'+e+'" but got "'+n+'"':null},W=function(t,e){void 0===e&&(e=0);var n=new Date(0);return n.setUTCSeconds(t+e),n},M=function(){function t(t){this.opts=t,this.loginStateKey="crossid-spa-js|login",this.logoutStateKey="crossid-spa-js|logout",this.scope=t.scope,this.state=this._stateFactory(this.opts.state_type||h),this.cache=this._cacheFactory(this.opts.cache_type||l),this._purgeIndex()}return t.prototype.createRedirectURL=function(t){return void 0===t&&(t={}),i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return[4,this._createAuthorizationData(t)];case 1:return e=n.sent(),[4,this._persistAuthorizationData(e)];case 2:return n.sent(),[2,this._authorizeUrl(e.request)]}}))}))},t.prototype.loginWithRedirect=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),window.location.replace(e),[2]}}))}))},t.prototype.createRegistrationUrl=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:if(!this.opts.registration_endpoint)throw new Error("registration_endpoint not defiend");return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),[2,this.opts.registration_endpoint+"?"+F({return_to:e})]}}))}))},t.prototype.registerWithRedirect=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return[4,this.createRegistrationUrl(t)];case 1:return e=n.sent(),window.location.replace(e),[2]}}))}))},t.prototype.handleRedirectCallback=function(t){return void 0===t&&(t=new URL(window.location.href)),i(this,void 0,void 0,(function(){var e,n,r,o,i,a,u;return s(this,(function(s){switch(s.label){case 0:if(e=t.searchParams,n=e.get("code"),r=e.get("error"))throw new Error(r);if(!(null==(o=this.state.get(this.loginStateKey))?void 0:o.code_verifier))throw new Error("invalid state, try sign-in again");return[4,c({tokenEndpoint:this.opts.token_endpoint,client_id:this.opts.client_id,code_verifier:o.code_verifier,grant_type:"authorization_code",redirect_uri:o.redirect_uri,code:n})];case 1:return(i=s.sent()).id_token&&((a=R(i.id_token)).payload.__bearer=i.id_token,this._assertIDToken(a,o.nonce)),u=R(i.access_token),this.state.remove(this.loginStateKey),this._assertAccessToken(u,o.audience),u.payload._raw=i.access_token,this._cacheTokens(a,u,i.refresh_token),[2,{state:o.state}]}}))}))},t.prototype.getUser=function(t){return void 0===t&&(t={}),i(this,void 0,void 0,(function(){var e,n,r,o;return s(this,(function(i){return e=this.getFinalAudience(t.audience),n=this.getFinalScope(t.scope),r=this._getTokensKeysFromCache("id_token",e,n),[2,null==(o=this._getNarrowedKey(r))?void 0:o.payload]}))}))},t.prototype.getAccessToken=function(t){var e;return void 0===t&&(t={}),i(this,void 0,void 0,(function(){var n,r,o,i;return s(this,(function(s){return n=this.getFinalAudience(t.audience),r=this.getFinalScope(t.scope),o=this._getTokensKeysFromCache("access_token",n,r),i=this._getNarrowedKey(o),[2,null===(e=null==i?void 0:i.payload)||void 0===e?void 0:e._raw]}))}))},t.prototype.introspectAccessToken=function(t){return void 0===t&&(t={}),i(this,void 0,void 0,(function(){var e,n,o,i;return s(this,(function(s){return e=this.getFinalAudience(t.audience),n=this.getFinalScope(t.scope),o=this._getTokensKeysFromCache("access_token",e,n),(i=this._getNarrowedKey(o))?[2,r(r({active:!0},i.payload),{_raw:void 0})]:[2,void 0]}))}))},t.prototype.createLogoutRedirectURL=function(t){return void 0===t&&(t={}),i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return[4,this._createLogoutData(t)];case 1:return e=n.sent(),e.request.id_token_hint&&t.post_logout_redirect_uri?[4,this._persistLogoutData(e)]:(this._removeTokens(e.audience,e.scopes),[2,this._logoutUrl()]);case 2:return n.sent(),[2,this._logoutUrl(e.request)]}}))}))},t.prototype.logoutWithRedirect=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return[4,this.createLogoutRedirectURL(t)];case 1:return e=n.sent(),window.location.assign(e),[2]}}))}))},t.prototype.handleLogoutRedirectCallback=function(t){return void 0===t&&(t=new URL(window.location.href)),i(this,void 0,void 0,(function(){var e,n,r,o;return s(this,(function(i){if(e=t.searchParams,n=e.get("state"),r=e.get("error"))throw new Error(r);if(!(null==(o=this.state.get(this.logoutStateKey))?void 0:o.state)||o.state!==n)throw new Error("invalid state, try sign-in again");return this._removeTokens(o.audience,o.scopes),this.state.remove(this.logoutStateKey),[2,{state:o.appState}]}))}))},t.prototype._createAuthorizationData=function(t){return i(this,void 0,void 0,(function(){var e,n,r,o,a,u;return s(this,(function(c){switch(c.label){case 0:return e=C(A(x())),n=C(A(x())),r=x(),[4,(p=r,i(void 0,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,window.crypto.subtle.digest({name:"SHA-256"},(new TextEncoder).encode(p))];case 1:return[2,t.sent()]}}))})))];case 1:return o=c.sent(),l=new Uint8Array(o),a=C(A(String.fromCharCode.apply(String,Array.from(l)))),u={audience:t.audience,redirect_uri:t.redirect_uri,response_type:t.response_type,scope:t.scope,state:e,nonce:n,code_challenge:a},[2,{request:this._mergeAuthorizationCodeParams(u),code_verifier:r,appState:t.state}]}var l,p}))}))},t.prototype._persistAuthorizationData=function(t){return i(this,void 0,void 0,(function(){var e,n;return s(this,(function(r){return e=t.request,n={audience:e.audience,redirect_uri:e.redirect_uri,scope:e.scope,nonce:e.nonce,state:t.appState,code_verifier:t.code_verifier},this.state.set(this.loginStateKey,n),[2]}))}))},t.prototype._mergeAuthorizationCodeParams=function(t){return{client_id:this.opts.client_id,audience:this.getFinalAudience(t.audience),response_type:t.response_type||this.opts.response_type||"code",redirect_uri:t.redirect_uri||this.opts.redirect_uri,nonce:t.nonce,state:t.state,scope:this.getFinalScope(t.scope).join(" "),code_challenge:t.code_challenge,code_challenge_method:"S256",ui_locales:t.ui_locales||this.opts.ui_locales,template_id:t.template_id||this.opts.template_id}},t.prototype._createLogoutData=function(t){return i(this,void 0,void 0,(function(){var e,n;return s(this,(function(r){switch(r.label){case 0:return(e={id_token_hint:t.id_token_hint,post_logout_redirect_uri:t.post_logout_redirect_uri}).id_token_hint||null===e.id_token_hint?[3,2]:[4,this.getUser()];case 1:(n=r.sent())&&n.__bearer&&(e.id_token_hint=n.__bearer),r.label=2;case 2:return e.id_token_hint&&(e.state=C(A(x()))),[2,{request:e,audience:t.audience||this.opts.audience,scopes:(t.scope||this.scope).split(" "),appState:t.state}]}}))}))},t.prototype._persistLogoutData=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){return e={client_id:this.opts.client_id,audience:t.audience,scopes:t.scopes,post_logout_redirect_uri:t.request.post_logout_redirect_uri,state:t.request.state,appState:t.appState},this.state.set(this.logoutStateKey,e),[2]}))}))},t.prototype._assertAccessToken=function(t,e){D(t,U(["alg"],["iss","sub","aud","exp","iat"]),P(this.opts.issuer),z("RS256"),L(e),N(!0),q(!0))},t.prototype._assertIDToken=function(t,e){var n;return D(t,U(["alg"],["iss","sub","aud","nonce","exp","iat"]),P(this.opts.issuer),(n=e,function(t){return J("Nonce (nonce)",n,t.payload.nonce)}),z("RS256"),L([this.opts.client_id]),N(!0),q(!1),(function(t){return y(t.payload.iat)?null:"Issued At (iat) claim must be a present number"})),null},t.prototype._removeTokens=function(t,e){var n=this,r=this._getTokensKeysFromCache("id_token",t,e),o=this._getTokensKeysFromCache("access_token",t,e),i=this._getTokensKeysFromCache("refresh_token",t,e);r.concat(o).concat(i).forEach((function(t){return n.cache.remove(t)})),this._purgeIndex()},t.prototype._authorizeUrl=function(t){return this.opts.authorization_endpoint+"?"+F(t)},t.prototype._logoutUrl=function(t){var e=this.opts.logout_endpoint;return t&&(e=e+"?"+F(t)),e},t.prototype._stateFactory=function(t){var e={ttl:300};switch(t){case p:return new k(e);case h:return new b(e);default:throw new Error('Invalid cache type "'+t+'"')}},t.prototype._cacheFactory=function(t){switch(t){case l:return new T;case p:return new k({purgeOnInit:!0});case h:return new b({purgeOnInit:!0});default:throw new Error('Invalid cache type "'+t+'"')}},t.prototype._cacheTokens=function(t,e,n){var r=this._ttlFromToken(e);this._cacheToken("access_token",e,this.opts.client_id,e.payload.aud,e.payload.scp,r),t&&this._cacheToken("id_token",t,this.opts.client_id,e.payload.aud,e.payload.scp||[],this._ttlFromToken(t)),n&&this._cacheToken("refresh_token",n,this.opts.client_id,e.payload.aud,e.payload.scp,432e3)},t.prototype._cacheToken=function(t,e,n,r,o,i){var s=this._cacheKey({tokType:t,client_id:n,audience:r,scope:o});this.cache.set(s,e,{ttl:i});var a=[r[0]||""],u=this.cache.get(v);u||(u={}),o=o.length?o:[""],a.forEach((function(t){u[t]||(u[t]={});var e=u[t];o.forEach((function(t){e[t]||(e[t]=[]),e[t].push(s)}))})),this.cache.set(v,u)},t.prototype._cacheKey=function(t){var e,n=t.tokType,r=t.client_id,o=t.audience,i=t.scope;return i&&i.length&&(i.sort(),e=i.join(d)),["crossid-spa-js",n,r,o.join(d),e].join(f)},t.prototype._decodeKey=function(t){var e=t.split(f),n=e[1],r=e[2],o=e[3];return{tokenType:n,audience:r.split(d),scope:o.split(d)}},t.prototype._getTokensKeysFromCache=function(t,e,n){var r=this;void 0===e&&(e=[""]);var o,i=(this.cache.get(v)||{})[e[0]]||[""];if(!i)return[];for(var s=function(e){return i[e]&&i[e].length?o?void(o=o.filter((function(t){return i[e].includes(t)}))):(o=i[e].filter((function(e){return r._decodeKey(e).tokenType===t})),"continue"):{value:[]}},a=0,u=n;a<u.length;a++){var c=s(u[a]);if("object"==typeof c)return c.value}return o},t.prototype._getNarrowedKey=function(t){for(var e in t){var n=this.cache.get(t[e]);if(n)return n}},t.prototype._ttlFromToken=function(t){return(new Date(1e3*t.payload.exp).getTime()-Date.now())/1e3},t.prototype._purgeIndex=function(){var t=this.cache.get(v);if(t){for(var e=0,n=Object.entries(t);e<n.length;e++){for(var r=n[e],o=r[0],i=r[1],s=function(e,n){for(var r=[],i=0;i<n.length;i++)a.cache.get(n[i])||r.push(i);t[o][e]=n.filter((function(t,e){return-1===r.indexOf(e)})),t[o][e].length||delete t[o][e]},a=this,u=0,c=Object.entries(i);u<c.length;u++){var l=c[u];s(l[0],l[1])}Object.keys(t[o]).length||delete t[o]}this.cache.set(v,t)}},t.prototype.getFinalAudience=function(t){return t||this.opts.audience},t.prototype.getFinalScope=function(t){return j(void 0!==t?t:this.scope)},t}();t.Client=M,t.OAuth2Error=a,t.newCrossidClient=function(t){return i(this,void 0,void 0,(function(){var e,n,r,i,a,c,l;return s(this,(function(s){switch(s.label){case 0:return e=t.tenant_id,n=t.region,r=t.auth_server,i=void 0===r?"default":r,a=o(t,["tenant_id","region","auth_server"]),c=a,[4,u({wellknown_endpoint:"https://"+e+"."+n+".crossid.io/oauth2/"+i+"/.well-known/openid-configuration"})];case 1:return l=s.sent(),c.authorization_endpoint=l.authorization_endpoint,c.token_endpoint=l.token_endpoint,c.issuer=l.issuer,c.logout_endpoint=c.issuer+"logout",c.registration_endpoint="https://"+e+"."+n+".crossid.io/auth/register",[2,new M(c)]}}))}))},t.newCrossidClientByDiscovery=function(t){return i(this,void 0,void 0,(function(){var e,n,r;return s(this,(function(i){switch(i.label){case 0:return[4,u(t)];case 1:return e=i.sent(),n=o(t,["wellknown_endpoint"]),(r=n).authorization_endpoint=e.authorization_endpoint,r.token_endpoint=e.token_endpoint,r.issuer=e.issuer,[2,new M(r)]}}))}))},t.newCrossidClientCustom=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new M(t)]}))}))},Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=crossid-spa-js.js.map

@@ -15,3 +15,3 @@ /*! *****************************************************************************

***************************************************************************** */
var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return(n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function r(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function o(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))}function i(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}var s=function(t){function n(e,r){var o=t.call(this,r)||this;return o.error=e,o.error_description=r,Object.setPrototypeOf(o,n.prototype),o}return e(n,t),n.create=function(t){return new n(t.error,t.error_description)},n}(Error);function a(t){var e=t.wellknown_endpoint;return o(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,fetch(e)];case 1:return 200!==(t=n.sent()).status?[3,3]:[4,t.json()];case 2:return[2,n.sent()];case 3:throw Error("failed to discover data from well known discovery endpoint.")}}))}))}function u(t){var e=t.tokenEndpoint,a=t.timeout,u=r(t,["tokenEndpoint","timeout"]);return o(this,void 0,void 0,(function(){var t,r,c;return i(this,(function(l){switch(l.label){case 0:return t=new FormData,Object.keys(u).forEach((function(e){return t.append(e,u[e])})),[4,(p=e,h={timeout:a,method:"POST",body:t},void 0===h&&(h={}),o(void 0,void 0,void 0,(function(){var t,e,r,o,s;return i(this,(function(i){switch(i.label){case 0:return t=h.timeout,e=void 0===t?5e3:t,r=new AbortController,o=setTimeout((function(){return r.abort()}),e),[4,fetch(p,n(n({},h),{signal:r.signal}))];case 1:return s=i.sent(),clearTimeout(o),[2,s]}}))})))];case 1:return[4,(r=l.sent()).json()];case 2:if(c=l.sent(),200!==r.status)throw s.create(c);return[2,c]}var p,h}))}))}var c="crossid-spa-js|index",l=function(t){return null!==t&&"Object"===(null==t?void 0:t.constructor.name)},p=function(t){return"number"==typeof t},h=function(t){return"string"==typeof t},d=String.fromCharCode(0),f=function(){function t(t,e){void 0===e&&(e={}),this.gopts=e,this.storage=t,e.purgeOnInit&&this.purge(!0)}return t.prototype.set=function(t,e,n){var r=this._key(t),o=this._ttl(null==n?void 0:n.ttl);try{var i=function(t,e){var n;return e&&e>0?((n={})[d]=t,n.ttl=Date.now()+1e3*e,n):t}(e,o);return this.storage.setItem(r,JSON.stringify(i)),!0}catch(t){return!1}},t.prototype.get=function(t,e){var n,r=this._key(t);try{var o=this.storage.getItem(r);if(null===o)return;var i=JSON.parse(o);return l(n=i)&&d in n?function(t,e){return Date.now()-1e3*e>t.ttl}(i,(null==e?void 0:e.ttl)||0)?void this.storage.removeItem(t):i[d]:i}catch(t){return}},t.prototype.remove=function(t){var e=this._key(t);return!!this.storage.getItem(e)&&(this.storage.removeItem(e),!0)},t.prototype.purge=function(t){var e=this;void 0===t&&(t=!1);var n=0;return Object.keys(this.storage).filter((function(t){return t.startsWith(e.gopts.prefix)})).forEach((function(r){var o=e.storage.getItem(r);if(o){var i;try{i=JSON.parse(o)}catch(t){return}(l(i)&&d in i&&Date.now()>i.ttl||t)&&(n++,e.storage.removeItem(r))}})),n},t.prototype._key=function(t){return this.gopts.prefix?""+this.gopts.prefix+t:t},t.prototype._ttl=function(t){return null===t?null:t||this.gopts.ttl||null},t}(),_=function(t){function n(e){var n=t.call(this,sessionStorage,e)||this;if("undefined"==typeof sessionStorage)throw Error("no support for session storage.");return n}return e(n,t),n}(f),v=function(t){function n(e){var n=t.call(this,localStorage,e)||this;if("undefined"==typeof localStorage)throw Error("no support for local storage.");return n}return e(n,t),n}(f),y=function(){function t(){}return t.prototype.getItem=function(t){return t in this?this[t]:null},t.prototype.setItem=function(t,e){void 0===e?this.removeItem(t):this[t]=""+e},t.prototype.removeItem=function(t){this.hasOwnProperty(t)&&delete this[t]},t}(),g=function(t){function n(e){return t.call(this,new y,e)||this}return e(n,t),n}(f),w=function(t){return Array.from(new Set(t))},m=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return w(t.join(" ").trim().split(/\s+/))},b=function(){return t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",e=Math.floor(86*Math.random()+43),Array.from(window.crypto.getRandomValues(new Uint8Array(e))).map((function(e){return t[e%t.length]})).join("");var t,e},k=function(t){return btoa(t)},S=function(t){return atob(t)},T=function(t){var e={"+":"-","/":"_","=":""};return t.replace(/[+/=]/g,(function(t){return e[t]}))},O=function(t){var e={"-":"+",_:"/"};return t.replace(/[-_]/g,(function(t){return e[t]}))},j=function(t){return Object.keys(t).filter((function(e){return void 0!==t[e]&&null!==t[e]})).map((function(e){return encodeURIComponent(e)+"="+encodeURIComponent(Array.isArray(t[e])?t[e].join(" "):t[e])})).join("&")},x=function(t){var e=t.split("."),n=e[0],r=e[1],o=e[2];if(3!==e.length||!n||!r||!o)throw new Error("malformed JWT token.");var i,s=JSON.parse(S(O(r)));if(s.aud)if(h(s.aud))s.aud=[s.aud];else if(i=s.aud,!Array.isArray(i)||!i.every((function(t){return h(t)})))throw new Error("Audience (aud) must be a string or an array of strings");return{header:JSON.parse(S(O(n))),payload:s}},A=function(t){function n(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var o=t.apply(this,n)||this;return o.fields_=e,o}return e(n,t),n.prototype.getMissingFields=function(){return this.fields_},n}(Error),E=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=e.map((function(e){return e(t)})).filter((function(t){return null!==t}));if(r&&r.length)throw new A(r,r.join(","));return null},I=function(t,e){var n=[];return function(r){return e&&e.filter((function(t){return!r.payload[t]})).forEach((function(t){return n.push(t)})),t&&t.filter((function(t){return!r.header[t]})).forEach((function(t){return n.push(t)})),n&&n.length?n.join(",")+" missing":null}},F=function(t){return function(e){return U("Issuer (iss)",t,e.payload.iss)}},R=function(t){return function(e){return U("Issuer (iss) claim",t,e.header.alg)}},K=function(t){return void 0===t&&(t=[]),function(e){return n=t,e.payload.aud.every((function(t){return n.includes(t)}))?null:"Audience (aud) claim mismatch: audience ("+e.payload.aud+") must contain only ("+t+")";var n}},C=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.exp)return null;if(!p(n.payload.exp))return"Expiration Time (exp) claim must be a present number";var r=z(n.payload.exp,e);return new Date(Date.now())>r?"Expiration Time (exp) claim expired ("+r+")":null}},D=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.nbf)return null;if(!p(n.payload.nbf))return"Not Before (nbf) claim must be a present number";var r=z(n.payload.nbf,-1*e),o=new Date(Date.now());return o<r?"Not Before (nbf) claim cannot be used yet, current time ("+o+") is before ("+r+")":null}},U=function(t,e,n){return e!==n?t+' mismatch: expected "'+e+'" but got "'+n+'"':null},z=function(t,e){void 0===e&&(e=0);var n=new Date(0);return n.setUTCSeconds(t+e),n},L=function(){function t(t){this.opts=t,this.loginStateKey="crossid-spa-js|login",this.logoutStateKey="crossid-spa-js|logout",this.scope=t.scope,this.state=this._stateFactory(this.opts.state_type||"session_storage"),this.cache=this._cacheFactory(this.opts.cache_type||"memory"),this._purgeIndex()}return t.prototype.createRedirectURL=function(t){return void 0===t&&(t={}),o(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this._createAuthorizationData(t)];case 1:return e=n.sent(),[4,this._persistAuthorizationData(e)];case 2:return n.sent(),[2,this._authorizeUrl(e.request)]}}))}))},t.prototype.loginWithRedirect=function(t){return o(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),window.location.replace(e),[2]}}))}))},t.prototype.createRegistrationUrl=function(t){return o(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:if(!this.opts.registration_endpoint)throw new Error("registration_endpoint not defiend");return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),[2,this.opts.registration_endpoint+"?"+j({return_to:e})]}}))}))},t.prototype.registerWithRedirect=function(t){return o(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this.createRegistrationUrl(t)];case 1:return e=n.sent(),window.location.replace(e),[2]}}))}))},t.prototype.handleRedirectCallback=function(t){return void 0===t&&(t=new URL(window.location.href)),o(this,void 0,void 0,(function(){var e,n,r,o,s,a,c;return i(this,(function(i){switch(i.label){case 0:if(e=t.searchParams,n=e.get("code"),r=e.get("error"))throw new Error(r);if(!(null==(o=this.state.get(this.loginStateKey))?void 0:o.code_verifier))throw new Error("invalid state, try sign-in again");return[4,u({tokenEndpoint:this.opts.token_endpoint,client_id:this.opts.client_id,code_verifier:o.code_verifier,grant_type:"authorization_code",redirect_uri:o.redirect_uri,code:n})];case 1:return(s=i.sent()).id_token&&((a=x(s.id_token)).payload.__bearer=s.id_token,this._assertIDToken(a,o.nonce)),c=x(s.access_token),this.state.remove(this.loginStateKey),this._assertAccessToken(c,o.audience),c.payload._raw=s.access_token,this._cacheTokens(a,c,s.refresh_token),[2,{state:o.state}]}}))}))},t.prototype.getUser=function(t){return void 0===t&&(t={}),o(this,void 0,void 0,(function(){var e,n,r,o;return i(this,(function(i){return e=this.getFinalAudience(t.audience),n=this.getFinalScope(t.scope),r=this._getTokensKeysFromCache("id_token",e,n),[2,null==(o=this._getNarrowedKey(r))?void 0:o.payload]}))}))},t.prototype.getAccessToken=function(t){var e;return void 0===t&&(t={}),o(this,void 0,void 0,(function(){var n,r,o,s;return i(this,(function(i){return n=this.getFinalAudience(t.audience),r=this.getFinalScope(t.scope),o=this._getTokensKeysFromCache("access_token",n,r),s=this._getNarrowedKey(o),[2,null===(e=null==s?void 0:s.payload)||void 0===e?void 0:e._raw]}))}))},t.prototype.introspectAccessToken=function(t){return void 0===t&&(t={}),o(this,void 0,void 0,(function(){var e,r,o,s;return i(this,(function(i){return e=this.getFinalAudience(t.audience),r=this.getFinalScope(t.scope),o=this._getTokensKeysFromCache("access_token",e,r),(s=this._getNarrowedKey(o))?[2,n(n({active:!0},s.payload),{_raw:void 0})]:[2,void 0]}))}))},t.prototype.createLogoutRedirectURL=function(t){return void 0===t&&(t={}),o(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this._createLogoutData(t)];case 1:return e=n.sent(),e.request.id_token_hint&&t.post_logout_redirect_uri?[4,this._persistLogoutData(e)]:(this._removeTokens(e.audience,e.scopes),[2,this._logoutUrl()]);case 2:return n.sent(),[2,this._logoutUrl(e.request)]}}))}))},t.prototype.logoutWithRedirect=function(t){return o(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this.createLogoutRedirectURL(t)];case 1:return e=n.sent(),window.location.assign(e),[2]}}))}))},t.prototype.handleLogoutRedirectCallback=function(t){return void 0===t&&(t=new URL(window.location.href)),o(this,void 0,void 0,(function(){var e,n,r,o;return i(this,(function(i){if(e=t.searchParams,n=e.get("state"),r=e.get("error"))throw new Error(r);if(!(null==(o=this.state.get(this.logoutStateKey))?void 0:o.state)||o.state!==n)throw new Error("invalid state, try sign-in again");return this._removeTokens(o.audience,o.scopes),this.state.remove(this.logoutStateKey),[2,{state:o.appState}]}))}))},t.prototype._createAuthorizationData=function(t){return o(this,void 0,void 0,(function(){var e,n,r,s,a,u;return i(this,(function(c){switch(c.label){case 0:return e=T(k(b())),n=T(k(b())),r=b(),[4,(p=r,o(void 0,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,window.crypto.subtle.digest({name:"SHA-256"},(new TextEncoder).encode(p))];case 1:return[2,t.sent()]}}))})))];case 1:return s=c.sent(),l=new Uint8Array(s),a=T(k(String.fromCharCode.apply(String,Array.from(l)))),u={audience:t.audience,redirect_uri:t.redirect_uri,response_type:t.response_type,scope:t.scope,state:e,nonce:n,code_challenge:a},[2,{request:this._mergeAuthorizationCodeParams(u),code_verifier:r,appState:t.state}]}var l,p}))}))},t.prototype._persistAuthorizationData=function(t){return o(this,void 0,void 0,(function(){var e,n;return i(this,(function(r){return e=t.request,n={audience:e.audience,redirect_uri:e.redirect_uri,scope:e.scope,nonce:e.nonce,state:t.appState,code_verifier:t.code_verifier},this.state.set(this.loginStateKey,n),[2]}))}))},t.prototype._mergeAuthorizationCodeParams=function(t){return{client_id:this.opts.client_id,audience:this.getFinalAudience(t.audience),response_type:t.response_type||this.opts.response_type||"code",redirect_uri:t.redirect_uri||this.opts.redirect_uri,nonce:t.nonce,state:t.state,scope:this.getFinalScope(t.scope).join(" "),code_challenge:t.code_challenge,code_challenge_method:"S256",ui_locales:t.ui_locales||this.opts.ui_locales,template_id:t.template_id||this.opts.template_id}},t.prototype._createLogoutData=function(t){return o(this,void 0,void 0,(function(){var e,n;return i(this,(function(r){switch(r.label){case 0:return(e={id_token_hint:t.id_token_hint,post_logout_redirect_uri:t.post_logout_redirect_uri}).id_token_hint||null===e.id_token_hint?[3,2]:[4,this.getUser()];case 1:(n=r.sent())&&n.__bearer&&(e.id_token_hint=n.__bearer),r.label=2;case 2:return e.id_token_hint&&(e.state=T(k(b()))),[2,{request:e,audience:t.audience||this.opts.audience,scopes:(t.scope||this.scope).split(" "),appState:t.state}]}}))}))},t.prototype._persistLogoutData=function(t){return o(this,void 0,void 0,(function(){var e;return i(this,(function(n){return e={client_id:this.opts.client_id,audience:t.audience,scopes:t.scopes,post_logout_redirect_uri:t.request.post_logout_redirect_uri,state:t.request.state,appState:t.appState},this.state.set(this.logoutStateKey,e),[2]}))}))},t.prototype._assertAccessToken=function(t,e){E(t,I(["alg"],["iss","sub","aud","exp","iat"]),F(this.opts.issuer),R("RS256"),K(e),C(!0),D(!0))},t.prototype._assertIDToken=function(t,e){var n;return E(t,I(["alg"],["iss","sub","aud","nonce","exp","iat"]),F(this.opts.issuer),(n=e,function(t){return U("Nonce (nonce)",n,t.payload.nonce)}),R("RS256"),K([this.opts.client_id]),C(!0),D(!1),(function(t){return p(t.payload.iat)?null:"Issued At (iat) claim must be a present number"})),null},t.prototype._removeTokens=function(t,e){var n=this,r=this._getTokensKeysFromCache("id_token",t,e),o=this._getTokensKeysFromCache("access_token",t,e),i=this._getTokensKeysFromCache("refresh_token",t,e);r.concat(o).concat(i).forEach((function(t){return n.cache.remove(t)})),this._purgeIndex()},t.prototype._authorizeUrl=function(t){return this.opts.authorization_endpoint+"?"+j(t)},t.prototype._logoutUrl=function(t){var e=this.opts.logout_endpoint;return t&&(e=e+"?"+j(t)),e},t.prototype._stateFactory=function(t){var e={ttl:300};switch(t){case"local_storage":return new v(e);case"session_storage":return new _(e);default:throw new Error('Invalid cache type "'+t+'"')}},t.prototype._cacheFactory=function(t){switch(t){case"memory":return new g;case"local_storage":return new v({purgeOnInit:!0});case"session_storage":return new _({purgeOnInit:!0});default:throw new Error('Invalid cache type "'+t+'"')}},t.prototype._cacheTokens=function(t,e,n){var r=this._ttlFromToken(e);this._cacheToken("access_token",e,this.opts.client_id,e.payload.aud,e.payload.scp,r),t&&this._cacheToken("id_token",t,this.opts.client_id,e.payload.aud,e.payload.scp||[],this._ttlFromToken(t)),n&&this._cacheToken("refresh_token",n,this.opts.client_id,e.payload.aud,e.payload.scp,432e3)},t.prototype._cacheToken=function(t,e,n,r,o,i){var s=this._cacheKey({tokType:t,client_id:n,audience:r,scope:o});this.cache.set(s,e,{ttl:i});var a=[r[0]||""],u=this.cache.get(c);u||(u={}),o=o.length?o:[""],a.forEach((function(t){u[t]||(u[t]={});var e=u[t];o.forEach((function(t){e[t]||(e[t]=[]),e[t].push(s)}))})),this.cache.set(c,u)},t.prototype._cacheKey=function(t){var e,n=t.tokType,r=t.client_id,o=t.audience,i=t.scope;return i&&i.length&&(i.sort(),e=i.join("__")),["crossid-spa-js",n,r,o.join("__"),e].join("|")},t.prototype._decodeKey=function(t){var e=t.split("|"),n=e[1],r=e[2],o=e[3];return{tokenType:n,audience:r.split("__"),scope:o.split("__")}},t.prototype._getTokensKeysFromCache=function(t,e,n){var r=this;void 0===e&&(e=[""]);var o,i=(this.cache.get(c)||{})[e[0]]||[""];if(!i)return[];for(var s=function(e){return i[e]&&i[e].length?o?void(o=o.filter((function(t){return i[e].includes(t)}))):(o=i[e].filter((function(e){return r._decodeKey(e).tokenType===t})),"continue"):{value:[]}},a=0,u=n;a<u.length;a++){var l=s(u[a]);if("object"==typeof l)return l.value}return o},t.prototype._getNarrowedKey=function(t){for(var e in t){var n=this.cache.get(t[e]);if(n)return n}},t.prototype._ttlFromToken=function(t){return(new Date(1e3*t.payload.exp).getTime()-Date.now())/1e3},t.prototype._purgeIndex=function(){var t=this.cache.get(c);if(t){for(var e=0,n=Object.entries(t);e<n.length;e++){for(var r=n[e],o=r[0],i=r[1],s=function(e,n){for(var r=[],i=0;i<n.length;i++)a.cache.get(n[i])||r.push(i);t[o][e]=n.filter((function(t,e){return-1===r.indexOf(e)})),t[o][e].length||delete t[o][e]},a=this,u=0,l=Object.entries(i);u<l.length;u++){var p=l[u];s(p[0],p[1])}Object.keys(t[o]).length||delete t[o]}this.cache.set(c,t)}},t.prototype.getFinalAudience=function(t){return t||this.opts.audience},t.prototype.getFinalScope=function(t){return m(void 0!==t?t:this.scope)},t}();function P(t){return o(this,void 0,void 0,(function(){var e,n,o,s,u,c;return i(this,(function(i){switch(i.label){case 0:return e=t.tenant_id,n=t.auth_server,o=void 0===n?"default":n,s=r(t,["tenant_id","auth_server"]),u=s,[4,a({wellknown_endpoint:"https://"+e+".crossid.io/oauth2/"+o+"/.well-known/openid-configuration"})];case 1:return c=i.sent(),u.authorization_endpoint=c.authorization_endpoint,u.token_endpoint=c.token_endpoint,u.issuer=c.issuer,u.logout_endpoint=u.issuer+"logout",u.registration_endpoint="https://"+e+".crossid.io/auth/register",[2,new L(u)]}}))}))}function N(t){return o(this,void 0,void 0,(function(){var e,n,o;return i(this,(function(i){switch(i.label){case 0:return[4,a(t)];case 1:return e=i.sent(),n=r(t,["wellknown_endpoint"]),(o=n).authorization_endpoint=e.authorization_endpoint,o.token_endpoint=e.token_endpoint,o.issuer=e.issuer,[2,new L(o)]}}))}))}function q(t){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,new L(t)]}))}))}export{L as Client,s as OAuth2Error,P as newCrossidClient,N as newCrossidClientByDiscovery,q as newCrossidClientCustom};
var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return(n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function r(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function o(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))}function i(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}var s=function(t){function n(e,r){var o=t.call(this,r)||this;return o.error=e,o.error_description=r,Object.setPrototypeOf(o,n.prototype),o}return e(n,t),n.create=function(t){return new n(t.error,t.error_description)},n}(Error);function a(t){var e=t.wellknown_endpoint;return o(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,fetch(e)];case 1:return 200!==(t=n.sent()).status?[3,3]:[4,t.json()];case 2:return[2,n.sent()];case 3:throw Error("failed to discover data from well known discovery endpoint.")}}))}))}function u(t){var e=t.tokenEndpoint,a=t.timeout,u=r(t,["tokenEndpoint","timeout"]);return o(this,void 0,void 0,(function(){var t,r,c;return i(this,(function(l){switch(l.label){case 0:return t=new FormData,Object.keys(u).forEach((function(e){return t.append(e,u[e])})),[4,(p=e,h={timeout:a,method:"POST",body:t},void 0===h&&(h={}),o(void 0,void 0,void 0,(function(){var t,e,r,o,s;return i(this,(function(i){switch(i.label){case 0:return t=h.timeout,e=void 0===t?5e3:t,r=new AbortController,o=setTimeout((function(){return r.abort()}),e),[4,fetch(p,n(n({},h),{signal:r.signal}))];case 1:return s=i.sent(),clearTimeout(o),[2,s]}}))})))];case 1:return[4,(r=l.sent()).json()];case 2:if(c=l.sent(),200!==r.status)throw s.create(c);return[2,c]}var p,h}))}))}var c="crossid-spa-js|index",l=function(t){return null!==t&&"Object"===(null==t?void 0:t.constructor.name)},p=function(t){return"number"==typeof t},h=function(t){return"string"==typeof t},d=String.fromCharCode(0),f=function(){function t(t,e){void 0===e&&(e={}),this.gopts=e,this.storage=t,e.purgeOnInit&&this.purge(!0)}return t.prototype.set=function(t,e,n){var r=this._key(t),o=this._ttl(null==n?void 0:n.ttl);try{var i=function(t,e){var n;return e&&e>0?((n={})[d]=t,n.ttl=Date.now()+1e3*e,n):t}(e,o);return this.storage.setItem(r,JSON.stringify(i)),!0}catch(t){return!1}},t.prototype.get=function(t,e){var n,r=this._key(t);try{var o=this.storage.getItem(r);if(null===o)return;var i=JSON.parse(o);return l(n=i)&&d in n?function(t,e){return Date.now()-1e3*e>t.ttl}(i,(null==e?void 0:e.ttl)||0)?void this.storage.removeItem(t):i[d]:i}catch(t){return}},t.prototype.remove=function(t){var e=this._key(t);return!!this.storage.getItem(e)&&(this.storage.removeItem(e),!0)},t.prototype.purge=function(t){var e=this;void 0===t&&(t=!1);var n=0;return Object.keys(this.storage).filter((function(t){return t.startsWith(e.gopts.prefix)})).forEach((function(r){var o=e.storage.getItem(r);if(o){var i;try{i=JSON.parse(o)}catch(t){return}(l(i)&&d in i&&Date.now()>i.ttl||t)&&(n++,e.storage.removeItem(r))}})),n},t.prototype._key=function(t){return this.gopts.prefix?""+this.gopts.prefix+t:t},t.prototype._ttl=function(t){return null===t?null:t||this.gopts.ttl||null},t}(),_=function(t){function n(e){var n=t.call(this,sessionStorage,e)||this;if("undefined"==typeof sessionStorage)throw Error("no support for session storage.");return n}return e(n,t),n}(f),v=function(t){function n(e){var n=t.call(this,localStorage,e)||this;if("undefined"==typeof localStorage)throw Error("no support for local storage.");return n}return e(n,t),n}(f),y=function(){function t(){}return t.prototype.getItem=function(t){return t in this?this[t]:null},t.prototype.setItem=function(t,e){void 0===e?this.removeItem(t):this[t]=""+e},t.prototype.removeItem=function(t){this.hasOwnProperty(t)&&delete this[t]},t}(),g=function(t){function n(e){return t.call(this,new y,e)||this}return e(n,t),n}(f),w=function(t){return Array.from(new Set(t))},m=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return w(t.join(" ").trim().split(/\s+/))},b=function(){return t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",e=Math.floor(86*Math.random()+43),Array.from(window.crypto.getRandomValues(new Uint8Array(e))).map((function(e){return t[e%t.length]})).join("");var t,e},k=function(t){return btoa(t)},S=function(t){return atob(t)},T=function(t){var e={"+":"-","/":"_","=":""};return t.replace(/[+/=]/g,(function(t){return e[t]}))},O=function(t){var e={"-":"+",_:"/"};return t.replace(/[-_]/g,(function(t){return e[t]}))},j=function(t){return Object.keys(t).filter((function(e){return void 0!==t[e]&&null!==t[e]})).map((function(e){return encodeURIComponent(e)+"="+encodeURIComponent(Array.isArray(t[e])?t[e].join(" "):t[e])})).join("&")},x=function(t){var e=t.split("."),n=e[0],r=e[1],o=e[2];if(3!==e.length||!n||!r||!o)throw new Error("malformed JWT token.");var i,s=JSON.parse(S(O(r)));if(s.aud)if(h(s.aud))s.aud=[s.aud];else if(i=s.aud,!Array.isArray(i)||!i.every((function(t){return h(t)})))throw new Error("Audience (aud) must be a string or an array of strings");return{header:JSON.parse(S(O(n))),payload:s}},A=function(t){function n(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var o=t.apply(this,n)||this;return o.fields_=e,o}return e(n,t),n.prototype.getMissingFields=function(){return this.fields_},n}(Error),E=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=e.map((function(e){return e(t)})).filter((function(t){return null!==t}));if(r&&r.length)throw new A(r,r.join(","));return null},I=function(t,e){var n=[];return function(r){return e&&e.filter((function(t){return!r.payload[t]})).forEach((function(t){return n.push(t)})),t&&t.filter((function(t){return!r.header[t]})).forEach((function(t){return n.push(t)})),n&&n.length?n.join(",")+" missing":null}},F=function(t){return function(e){return U("Issuer (iss)",t,e.payload.iss)}},R=function(t){return function(e){return U("Issuer (iss) claim",t,e.header.alg)}},K=function(t){return void 0===t&&(t=[]),function(e){return n=t,e.payload.aud.every((function(t){return n.includes(t)}))?null:"Audience (aud) claim mismatch: audience ("+e.payload.aud+") must contain only ("+t+")";var n}},C=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.exp)return null;if(!p(n.payload.exp))return"Expiration Time (exp) claim must be a present number";var r=z(n.payload.exp,e);return new Date(Date.now())>r?"Expiration Time (exp) claim expired ("+r+")":null}},D=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.nbf)return null;if(!p(n.payload.nbf))return"Not Before (nbf) claim must be a present number";var r=z(n.payload.nbf,-1*e),o=new Date(Date.now());return o<r?"Not Before (nbf) claim cannot be used yet, current time ("+o+") is before ("+r+")":null}},U=function(t,e,n){return e!==n?t+' mismatch: expected "'+e+'" but got "'+n+'"':null},z=function(t,e){void 0===e&&(e=0);var n=new Date(0);return n.setUTCSeconds(t+e),n},L=function(){function t(t){this.opts=t,this.loginStateKey="crossid-spa-js|login",this.logoutStateKey="crossid-spa-js|logout",this.scope=t.scope,this.state=this._stateFactory(this.opts.state_type||"session_storage"),this.cache=this._cacheFactory(this.opts.cache_type||"memory"),this._purgeIndex()}return t.prototype.createRedirectURL=function(t){return void 0===t&&(t={}),o(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this._createAuthorizationData(t)];case 1:return e=n.sent(),[4,this._persistAuthorizationData(e)];case 2:return n.sent(),[2,this._authorizeUrl(e.request)]}}))}))},t.prototype.loginWithRedirect=function(t){return o(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),window.location.replace(e),[2]}}))}))},t.prototype.createRegistrationUrl=function(t){return o(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:if(!this.opts.registration_endpoint)throw new Error("registration_endpoint not defiend");return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),[2,this.opts.registration_endpoint+"?"+j({return_to:e})]}}))}))},t.prototype.registerWithRedirect=function(t){return o(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this.createRegistrationUrl(t)];case 1:return e=n.sent(),window.location.replace(e),[2]}}))}))},t.prototype.handleRedirectCallback=function(t){return void 0===t&&(t=new URL(window.location.href)),o(this,void 0,void 0,(function(){var e,n,r,o,s,a,c;return i(this,(function(i){switch(i.label){case 0:if(e=t.searchParams,n=e.get("code"),r=e.get("error"))throw new Error(r);if(!(null==(o=this.state.get(this.loginStateKey))?void 0:o.code_verifier))throw new Error("invalid state, try sign-in again");return[4,u({tokenEndpoint:this.opts.token_endpoint,client_id:this.opts.client_id,code_verifier:o.code_verifier,grant_type:"authorization_code",redirect_uri:o.redirect_uri,code:n})];case 1:return(s=i.sent()).id_token&&((a=x(s.id_token)).payload.__bearer=s.id_token,this._assertIDToken(a,o.nonce)),c=x(s.access_token),this.state.remove(this.loginStateKey),this._assertAccessToken(c,o.audience),c.payload._raw=s.access_token,this._cacheTokens(a,c,s.refresh_token),[2,{state:o.state}]}}))}))},t.prototype.getUser=function(t){return void 0===t&&(t={}),o(this,void 0,void 0,(function(){var e,n,r,o;return i(this,(function(i){return e=this.getFinalAudience(t.audience),n=this.getFinalScope(t.scope),r=this._getTokensKeysFromCache("id_token",e,n),[2,null==(o=this._getNarrowedKey(r))?void 0:o.payload]}))}))},t.prototype.getAccessToken=function(t){var e;return void 0===t&&(t={}),o(this,void 0,void 0,(function(){var n,r,o,s;return i(this,(function(i){return n=this.getFinalAudience(t.audience),r=this.getFinalScope(t.scope),o=this._getTokensKeysFromCache("access_token",n,r),s=this._getNarrowedKey(o),[2,null===(e=null==s?void 0:s.payload)||void 0===e?void 0:e._raw]}))}))},t.prototype.introspectAccessToken=function(t){return void 0===t&&(t={}),o(this,void 0,void 0,(function(){var e,r,o,s;return i(this,(function(i){return e=this.getFinalAudience(t.audience),r=this.getFinalScope(t.scope),o=this._getTokensKeysFromCache("access_token",e,r),(s=this._getNarrowedKey(o))?[2,n(n({active:!0},s.payload),{_raw:void 0})]:[2,void 0]}))}))},t.prototype.createLogoutRedirectURL=function(t){return void 0===t&&(t={}),o(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this._createLogoutData(t)];case 1:return e=n.sent(),e.request.id_token_hint&&t.post_logout_redirect_uri?[4,this._persistLogoutData(e)]:(this._removeTokens(e.audience,e.scopes),[2,this._logoutUrl()]);case 2:return n.sent(),[2,this._logoutUrl(e.request)]}}))}))},t.prototype.logoutWithRedirect=function(t){return o(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this.createLogoutRedirectURL(t)];case 1:return e=n.sent(),window.location.assign(e),[2]}}))}))},t.prototype.handleLogoutRedirectCallback=function(t){return void 0===t&&(t=new URL(window.location.href)),o(this,void 0,void 0,(function(){var e,n,r,o;return i(this,(function(i){if(e=t.searchParams,n=e.get("state"),r=e.get("error"))throw new Error(r);if(!(null==(o=this.state.get(this.logoutStateKey))?void 0:o.state)||o.state!==n)throw new Error("invalid state, try sign-in again");return this._removeTokens(o.audience,o.scopes),this.state.remove(this.logoutStateKey),[2,{state:o.appState}]}))}))},t.prototype._createAuthorizationData=function(t){return o(this,void 0,void 0,(function(){var e,n,r,s,a,u;return i(this,(function(c){switch(c.label){case 0:return e=T(k(b())),n=T(k(b())),r=b(),[4,(p=r,o(void 0,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,window.crypto.subtle.digest({name:"SHA-256"},(new TextEncoder).encode(p))];case 1:return[2,t.sent()]}}))})))];case 1:return s=c.sent(),l=new Uint8Array(s),a=T(k(String.fromCharCode.apply(String,Array.from(l)))),u={audience:t.audience,redirect_uri:t.redirect_uri,response_type:t.response_type,scope:t.scope,state:e,nonce:n,code_challenge:a},[2,{request:this._mergeAuthorizationCodeParams(u),code_verifier:r,appState:t.state}]}var l,p}))}))},t.prototype._persistAuthorizationData=function(t){return o(this,void 0,void 0,(function(){var e,n;return i(this,(function(r){return e=t.request,n={audience:e.audience,redirect_uri:e.redirect_uri,scope:e.scope,nonce:e.nonce,state:t.appState,code_verifier:t.code_verifier},this.state.set(this.loginStateKey,n),[2]}))}))},t.prototype._mergeAuthorizationCodeParams=function(t){return{client_id:this.opts.client_id,audience:this.getFinalAudience(t.audience),response_type:t.response_type||this.opts.response_type||"code",redirect_uri:t.redirect_uri||this.opts.redirect_uri,nonce:t.nonce,state:t.state,scope:this.getFinalScope(t.scope).join(" "),code_challenge:t.code_challenge,code_challenge_method:"S256",ui_locales:t.ui_locales||this.opts.ui_locales,template_id:t.template_id||this.opts.template_id}},t.prototype._createLogoutData=function(t){return o(this,void 0,void 0,(function(){var e,n;return i(this,(function(r){switch(r.label){case 0:return(e={id_token_hint:t.id_token_hint,post_logout_redirect_uri:t.post_logout_redirect_uri}).id_token_hint||null===e.id_token_hint?[3,2]:[4,this.getUser()];case 1:(n=r.sent())&&n.__bearer&&(e.id_token_hint=n.__bearer),r.label=2;case 2:return e.id_token_hint&&(e.state=T(k(b()))),[2,{request:e,audience:t.audience||this.opts.audience,scopes:(t.scope||this.scope).split(" "),appState:t.state}]}}))}))},t.prototype._persistLogoutData=function(t){return o(this,void 0,void 0,(function(){var e;return i(this,(function(n){return e={client_id:this.opts.client_id,audience:t.audience,scopes:t.scopes,post_logout_redirect_uri:t.request.post_logout_redirect_uri,state:t.request.state,appState:t.appState},this.state.set(this.logoutStateKey,e),[2]}))}))},t.prototype._assertAccessToken=function(t,e){E(t,I(["alg"],["iss","sub","aud","exp","iat"]),F(this.opts.issuer),R("RS256"),K(e),C(!0),D(!0))},t.prototype._assertIDToken=function(t,e){var n;return E(t,I(["alg"],["iss","sub","aud","nonce","exp","iat"]),F(this.opts.issuer),(n=e,function(t){return U("Nonce (nonce)",n,t.payload.nonce)}),R("RS256"),K([this.opts.client_id]),C(!0),D(!1),(function(t){return p(t.payload.iat)?null:"Issued At (iat) claim must be a present number"})),null},t.prototype._removeTokens=function(t,e){var n=this,r=this._getTokensKeysFromCache("id_token",t,e),o=this._getTokensKeysFromCache("access_token",t,e),i=this._getTokensKeysFromCache("refresh_token",t,e);r.concat(o).concat(i).forEach((function(t){return n.cache.remove(t)})),this._purgeIndex()},t.prototype._authorizeUrl=function(t){return this.opts.authorization_endpoint+"?"+j(t)},t.prototype._logoutUrl=function(t){var e=this.opts.logout_endpoint;return t&&(e=e+"?"+j(t)),e},t.prototype._stateFactory=function(t){var e={ttl:300};switch(t){case"local_storage":return new v(e);case"session_storage":return new _(e);default:throw new Error('Invalid cache type "'+t+'"')}},t.prototype._cacheFactory=function(t){switch(t){case"memory":return new g;case"local_storage":return new v({purgeOnInit:!0});case"session_storage":return new _({purgeOnInit:!0});default:throw new Error('Invalid cache type "'+t+'"')}},t.prototype._cacheTokens=function(t,e,n){var r=this._ttlFromToken(e);this._cacheToken("access_token",e,this.opts.client_id,e.payload.aud,e.payload.scp,r),t&&this._cacheToken("id_token",t,this.opts.client_id,e.payload.aud,e.payload.scp||[],this._ttlFromToken(t)),n&&this._cacheToken("refresh_token",n,this.opts.client_id,e.payload.aud,e.payload.scp,432e3)},t.prototype._cacheToken=function(t,e,n,r,o,i){var s=this._cacheKey({tokType:t,client_id:n,audience:r,scope:o});this.cache.set(s,e,{ttl:i});var a=[r[0]||""],u=this.cache.get(c);u||(u={}),o=o.length?o:[""],a.forEach((function(t){u[t]||(u[t]={});var e=u[t];o.forEach((function(t){e[t]||(e[t]=[]),e[t].push(s)}))})),this.cache.set(c,u)},t.prototype._cacheKey=function(t){var e,n=t.tokType,r=t.client_id,o=t.audience,i=t.scope;return i&&i.length&&(i.sort(),e=i.join("__")),["crossid-spa-js",n,r,o.join("__"),e].join("|")},t.prototype._decodeKey=function(t){var e=t.split("|"),n=e[1],r=e[2],o=e[3];return{tokenType:n,audience:r.split("__"),scope:o.split("__")}},t.prototype._getTokensKeysFromCache=function(t,e,n){var r=this;void 0===e&&(e=[""]);var o,i=(this.cache.get(c)||{})[e[0]]||[""];if(!i)return[];for(var s=function(e){return i[e]&&i[e].length?o?void(o=o.filter((function(t){return i[e].includes(t)}))):(o=i[e].filter((function(e){return r._decodeKey(e).tokenType===t})),"continue"):{value:[]}},a=0,u=n;a<u.length;a++){var l=s(u[a]);if("object"==typeof l)return l.value}return o},t.prototype._getNarrowedKey=function(t){for(var e in t){var n=this.cache.get(t[e]);if(n)return n}},t.prototype._ttlFromToken=function(t){return(new Date(1e3*t.payload.exp).getTime()-Date.now())/1e3},t.prototype._purgeIndex=function(){var t=this.cache.get(c);if(t){for(var e=0,n=Object.entries(t);e<n.length;e++){for(var r=n[e],o=r[0],i=r[1],s=function(e,n){for(var r=[],i=0;i<n.length;i++)a.cache.get(n[i])||r.push(i);t[o][e]=n.filter((function(t,e){return-1===r.indexOf(e)})),t[o][e].length||delete t[o][e]},a=this,u=0,l=Object.entries(i);u<l.length;u++){var p=l[u];s(p[0],p[1])}Object.keys(t[o]).length||delete t[o]}this.cache.set(c,t)}},t.prototype.getFinalAudience=function(t){return t||this.opts.audience},t.prototype.getFinalScope=function(t){return m(void 0!==t?t:this.scope)},t}();function P(t){return o(this,void 0,void 0,(function(){var e,n,o,s,u,c,l;return i(this,(function(i){switch(i.label){case 0:return e=t.tenant_id,n=t.region,o=t.auth_server,s=void 0===o?"default":o,u=r(t,["tenant_id","region","auth_server"]),c=u,[4,a({wellknown_endpoint:"https://"+e+"."+n+".crossid.io/oauth2/"+s+"/.well-known/openid-configuration"})];case 1:return l=i.sent(),c.authorization_endpoint=l.authorization_endpoint,c.token_endpoint=l.token_endpoint,c.issuer=l.issuer,c.logout_endpoint=c.issuer+"logout",c.registration_endpoint="https://"+e+"."+n+".crossid.io/auth/register",[2,new L(c)]}}))}))}function N(t){return o(this,void 0,void 0,(function(){var e,n,o;return i(this,(function(i){switch(i.label){case 0:return[4,a(t)];case 1:return e=i.sent(),n=r(t,["wellknown_endpoint"]),(o=n).authorization_endpoint=e.authorization_endpoint,o.token_endpoint=e.token_endpoint,o.issuer=e.issuer,[2,new L(o)]}}))}))}function q(t){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,new L(t)]}))}))}export{L as Client,s as OAuth2Error,P as newCrossidClient,N as newCrossidClientByDiscovery,q as newCrossidClientCustom};
//# sourceMappingURL=index.js.map
{
"name": "@crossid/crossid-spa-js",
"version": "0.4.1",
"version": "0.4.2",
"description": "Crossid is an OAuth2 / OIDC client for single page application (SPA) with support for PKCE extension.",

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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