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

@crossid/crossid-react

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@crossid/crossid-react - npm Package Compare versions

Comparing version 0.2.4 to 0.2.5

8

CHANGELOG.md

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

## 0.2.5
[All Changes](https://github.com/crossid/crossid-spa-js/compare/v0.2.4...v0.2.5)
### Major Changes
- upgrade `@crossid/crossid-spa-js` to v0.4.4
## 0.2.4

@@ -2,0 +10,0 @@

17

dist/crossid-react.js

@@ -15,18 +15,3 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).reactCrossid={},t.React)}(this,(function(t,e){"use strict";function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=n(e),o=function(){return(o=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)};

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function i(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())}))}function a(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)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 a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}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,s])}}}function s(){throw new Error("Please wrap your app with <AuthProvider>")}var u={loading:!0},c={signupWithRedirect:s,loginWithRedirect:s,logoutWithRedirect:s,getAccessToken:s,introspectAccessToken:s},l=o(o({},u),c),d=e.createContext(l),p=function(){return e.useContext(d)},h=function(){return""+window.location.pathname+window.location.search};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var f=function(t,e){return(f=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,e)};function v(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}f(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var _=function(){return(_=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 y(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 g(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())}))}function w(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)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 a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}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,s])}}}var m=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 v(e,t),e.create=function(t){return new e(t.error,t.error_description)},e}(Error);function b(t){var e=t.wellknown_endpoint;return g(this,void 0,void 0,(function(){var t;return w(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 k(t){var e=t.tokenEndpoint,n=t.timeout,r=y(t,["tokenEndpoint","timeout"]);return g(this,void 0,void 0,(function(){var t,o,i;return w(this,(function(a){switch(a.label){case 0:return t=new FormData,Object.keys(r).forEach((function(e){return t.append(e,r[e])})),[4,(s=e,u={timeout:n,method:"POST",body:t},void 0===u&&(u={}),g(void 0,void 0,void 0,(function(){var t,e,n,r,o;return w(this,(function(i){switch(i.label){case 0:return t=u.timeout,e=void 0===t?5e3:t,n=new AbortController,r=setTimeout((function(){return n.abort()}),e),[4,fetch(s,_(_({},u),{signal:n.signal}))];case 1:return o=i.sent(),clearTimeout(r),[2,o]}}))})))];case 1:return[4,(o=a.sent()).json()];case 2:if(i=a.sent(),200!==o.status)throw m.create(i);return[2,i]}var s,u}))}))}var T="crossid-spa-js|index",R=function(t){return null!==t&&"Object"===(null==t?void 0:t.constructor.name)},S=function(t){return"number"==typeof t},O=function(t){return"string"==typeof t},E=String.fromCharCode(0),A=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={})[E]=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 R(n=i)&&E 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[E]: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}(R(i)&&E 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}(),j=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 v(e,t),e}(A),x=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 v(e,t),e}(A),I=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}(),C=function(t){function e(e){return t.call(this,new I,e)||this}return v(e,t),e}(A),U=function(t){return Array.from(new Set(t))},D=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},F=function(t){return btoa(t)},L=function(t){return atob(t)},P=function(t){var e={"+":"-","/":"_","=":""};return t.replace(/[+/=]/g,(function(t){return e[t]}))},K=function(t){var e={"-":"+",_:"/"};return t.replace(/[-_]/g,(function(t){return e[t]}))},z=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("&")},N=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,a=JSON.parse(L(K(r)));if(a.aud)if(O(a.aud))a.aud=[a.aud];else if(i=a.aud,!Array.isArray(i)||!i.every((function(t){return O(t)})))throw new Error("Audience (aud) must be a string or an array of strings");return{header:JSON.parse(L(K(n))),payload:a}},W=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 v(e,t),e.prototype.getMissingFields=function(){return this.fields_},e}(Error),q=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 W(r,r.join(","));return null},J=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}},M=function(t){return function(e){return V("Issuer (iss)",t,e.payload.iss)}},G=function(t){return function(e){return V("Issuer (iss) claim",t,e.header.alg)}},Z=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}},B=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.exp)return null;if(!S(n.payload.exp))return"Expiration Time (exp) claim must be a present number";var r=Q(n.payload.exp,e);return new Date(Date.now())>r?"Expiration Time (exp) claim expired ("+r+")":null}},H=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.nbf)return null;if(!S(n.payload.nbf))return"Not Before (nbf) claim must be a present number";var r=Q(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}},V=function(t,e,n){return e!==n?t+' mismatch: expected "'+e+'" but got "'+n+'"':null},Q=function(t,e){void 0===e&&(e=0);var n=new Date(0);return n.setUTCSeconds(t+e),n},X=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={}),g(this,void 0,void 0,(function(){var e;return w(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 g(this,void 0,void 0,(function(){var e;return w(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.createSignupUrl=function(t){return g(this,void 0,void 0,(function(){var e;return w(this,(function(n){switch(n.label){case 0:if(!this.opts.signup_endpoint)throw new Error("signup_endpoint not defiend");return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),[2,this.opts.signup_endpoint+"?"+z({return_to:e})]}}))}))},t.prototype.signupWithRedirect=function(t){return g(this,void 0,void 0,(function(){var e;return w(this,(function(n){switch(n.label){case 0:return[4,this.createSignupUrl(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)),g(this,void 0,void 0,(function(){var e,n,r,o,i,a,s;return w(this,(function(u){switch(u.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,k({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=u.sent()).id_token&&((a=N(i.id_token)).payload.__bearer=i.id_token,this._assertIDToken(a,o.nonce)),s=N(i.access_token),this.state.remove(this.loginStateKey),this._assertAccessToken(s,o.audience),s.payload._raw=i.access_token,this._cacheTokens(a,s,i.refresh_token),[2,{state:o.state}]}}))}))},t.prototype.getUser=function(t){return void 0===t&&(t={}),g(this,void 0,void 0,(function(){var e,n,r,o;return w(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={}),g(this,void 0,void 0,(function(){var n,r,o,i;return w(this,(function(a){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={}),g(this,void 0,void 0,(function(){var e,n,r,o;return w(this,(function(i){return e=this.getFinalAudience(t.audience),n=this.getFinalScope(t.scope),r=this._getTokensKeysFromCache("access_token",e,n),(o=this._getNarrowedKey(r))?[2,_(_({active:!0},o.payload),{_raw:void 0})]:[2,void 0]}))}))},t.prototype.createLogoutRedirectURL=function(t){return void 0===t&&(t={}),g(this,void 0,void 0,(function(){var e;return w(this,(function(n){switch(n.label){case 0:return[4,this._createLogoutData(t)];case 1:return(e=n.sent()).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 g(this,void 0,void 0,(function(){var e;return w(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)),g(this,void 0,void 0,(function(){var e,n,r,o;return w(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 g(this,void 0,void 0,(function(){var e,n,r,o,i,a;return w(this,(function(s){switch(s.label){case 0:return e=P(F(D())),n=P(F(D())),r=D(),[4,(c=r,g(void 0,void 0,void 0,(function(){return w(this,(function(t){switch(t.label){case 0:return[4,window.crypto.subtle.digest({name:"SHA-256"},(new TextEncoder).encode(c))];case 1:return[2,t.sent()]}}))})))];case 1:return o=s.sent(),u=new Uint8Array(o),i=P(F(String.fromCharCode.apply(String,Array.from(u)))),a={audience:t.audience,redirect_uri:t.redirect_uri,response_type:t.response_type,scope:t.scope,state:e,nonce:n,code_challenge:i},[2,{request:this._mergeAuthorizationCodeParams(a),code_verifier:r,appState:t.state}]}var u,c}))}))},t.prototype._persistAuthorizationData=function(t){return g(this,void 0,void 0,(function(){var e,n;return w(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 g(this,void 0,void 0,(function(){var e,n;return w(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=P(F(D()))),[2,{request:e,audience:t.audience||this.opts.audience,scopes:(t.scope||this.scope).split(" "),appState:t.state}]}}))}))},t.prototype._persistLogoutData=function(t){return g(this,void 0,void 0,(function(){var e;return w(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){q(t,J(["alg"],["iss","sub","aud","exp","iat"]),M(this.opts.issuer),G("RS256"),Z(e),B(!0),H(!0))},t.prototype._assertIDToken=function(t,e){var n;return q(t,J(["alg"],["iss","sub","aud","nonce","exp","iat"]),M(this.opts.issuer),(n=e,function(t){return V("Nonce (nonce)",n,t.payload.nonce)}),G("RS256"),Z([this.opts.client_id]),B(!0),H(!1),(function(t){return S(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+"?"+z(t)},t.prototype._logoutUrl=function(t){var e=this.opts.logout_endpoint;return t&&(e=e+"?"+z(t)),e},t.prototype._stateFactory=function(t){var e={ttl:300};switch(t){case"local_storage":return new x(e);case"session_storage":return new j(e);default:throw new Error('Invalid cache type "'+t+'"')}},t.prototype._cacheFactory=function(t){switch(t){case"memory":return new C;case"local_storage":return new x({purgeOnInit:!0});case"session_storage":return new j({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 a=this._cacheKey({tokType:t,client_id:n,audience:r,scope:o});this.cache.set(a,e,{ttl:i});var s=[r[0]||""],u=this.cache.get(T);u||(u={}),o=o.length?o:[""],s.forEach((function(t){u[t]||(u[t]={});var e=u[t];o.forEach((function(t){e[t]||(e[t]=[]),e[t].push(a)}))})),this.cache.set(T,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(T)||{})[e[0]]||[""];if(!i)return[];for(var a=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:[]}},s=0,u=n;s<u.length;s++){var c=a(u[s]);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(T);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],a=function(e,n){for(var r=[],i=0;i<n.length;i++)s.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]},s=this,u=0,c=Object.entries(i);u<c.length;u++){var l=c[u];a(l[0],l[1])}Object.keys(t[o]).length||delete t[o]}this.cache.set(T,t)}},t.prototype.getFinalAudience=function(t){return t||this.opts.audience},t.prototype.getFinalScope=function(t){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return U(t.join(" ").trim().split(/\s+/))}(void 0!==t?t:this.scope)},t}();function Y(t){return g(this,void 0,void 0,(function(){var e,n,r,o,i,a,s;return w(this,(function(u){switch(u.label){case 0:return e=t.tenant_id,n=t.region,r=t.auth_server,o=void 0===r?"default":r,i=y(t,["tenant_id","region","auth_server"]),a=i,[4,b({wellknown_endpoint:"https://"+e+"."+n+".crossid.io/oauth2/"+o+"/.well-known/openid-configuration"})];case 1:return s=u.sent(),a.authorization_endpoint=s.authorization_endpoint,a.token_endpoint=s.token_endpoint,a.issuer=s.issuer,a.logout_endpoint=a.issuer+"logout",a.signup_endpoint="https://"+e+"."+n+".crossid.io/auth/signup",[2,new X(a)]}}))}))}function $(t){return g(this,void 0,void 0,(function(){var e,n,r;return w(this,(function(o){switch(o.label){case 0:return[4,b(t)];case 1:return e=o.sent(),n=y(t,["wellknown_endpoint"]),(r=n).authorization_endpoint=e.authorization_endpoint,r.token_endpoint=e.token_endpoint,r.issuer=e.issuer,[2,new X(r)]}}))}))}function tt(t){return g(this,void 0,void 0,(function(){return w(this,(function(e){return[2,new X(t)]}))}))}var et=function(t,e){switch(e.type){case"INITIALIZED":return o(o({},t),{loading:!1,idToken:e.idToken,error:void 0});case"LOGOUT_COMPLETED":return o(o({},t),{loading:!1,idToken:void 0,error:void 0});case"ERROR":return o(o({},t),{loading:!1,error:e.error})}},nt=function(t,e){void 0===t&&(t=window.location);var n=t.origin,r=t.pathname;if(e.some((function(t){return t===n+r}))){var o=new URLSearchParams(t.search);if(o.get("error"))return m.create({error:o.get("error")||"",error_description:o.get("error_description")||""})}},rt=function(t){return m.create({error:t.message,error_description:""})},ot=function(t){return i(void 0,void 0,void 0,(function(){var e,n,r,o;return a(this,(function(i){switch(i.label){case 0:return r=e=t,o=e,(n=e).tenant_id?[4,Y(n)]:[3,2];case 1:return[2,i.sent()];case 2:return r.wellknown_endpoint?[4,$(r)]:[3,4];case 3:return[2,i.sent()];case 4:return o.authorization_endpoint&&o.token_endpoint&&o.issuer?[4,tt(o)]:[3,6];case 5:return[2,i.sent()];case 6:throw new Error("invalid props")}}))}))},it=function(t){window.history.replaceState({},document.title,(null==t?void 0:t.return_to)||window.location.pathname)};t.AuthProvider=function(t){var n=e.useState(),s=n[0],c=n[1],l=e.useReducer(et,u),p=l[0],h=l[1],f=t.onRedirectTo,v=void 0===f?it:f,_=t.redirect_uri,y=t.post_logout_redirect_uri,g=t.children;e.useEffect((function(){i(void 0,void 0,void 0,(function(){var e,n;return a(this,(function(r){switch(r.label){case 0:if(s)return[3,4];r.label=1;case 1:return r.trys.push([1,3,,4]),[4,ot(t)];case 2:return e=r.sent(),c(e),[3,4];case 3:return n=r.sent(),h({type:"ERROR",error:rt(n)}),[3,4];case 4:return[2]}}))}))}),[s]),e.useEffect((function(){i(void 0,void 0,void 0,(function(){var t,e,n,r,o;return a(this,(function(i){switch(i.label){case 0:if(!s)return[3,11];i.label=1;case 1:return i.trys.push([1,10,,11]),function(t,e){void 0===t&&(t=window.location);var n=t.origin,r=t.pathname,o=new URLSearchParams(t.search);return n+r===e&&o.has("code")&&!o.has("error")}(window.location,_)?[4,s.handleRedirectCallback()]:[3,4];case 2:return t=i.sent().state,[4,s.getUser({scope:"openid"})];case 3:return r=i.sent(),h({type:"INITIALIZED",idToken:r}),v(t),[3,9];case 4:return function(t,e){void 0===t&&(t=window.location);var n=t.origin,r=t.pathname,o=new URLSearchParams(t.search);return n+r===e&&o.has("state")&&!o.has("error")}(window.location,y)?[4,s.handleLogoutRedirectCallback()]:[3,6];case 5:return e=i.sent().state,h({type:"LOGOUT_COMPLETED"}),v(e),[3,9];case 6:return nt(window.location,[_,y])?((n=nt(window.location,[_,y]))&&h({type:"ERROR",error:n}),[3,9]):[3,7];case 7:return[4,s.getUser({scope:"openid"})];case 8:r=i.sent(),h({type:"INITIALIZED",idToken:r}),i.label=9;case 9:return[3,11];case 10:return o=i.sent(),h({type:"ERROR",error:rt(o)}),[3,11];case 11:return[2]}}))}))}),[s]);var w=e.useCallback((function(t){void 0===t&&(t={}),null==s||s.loginWithRedirect(t)}),[s]),m=e.useCallback((function(e){void 0===e&&(e={}),e.post_logout_redirect_uri||(e.post_logout_redirect_uri=t.post_logout_redirect_uri),null==s||s.logoutWithRedirect(e)}),[s]),b=e.useCallback((function(t){void 0===t&&(t={}),null==s||s.signupWithRedirect(t)}),[s]),k=e.useCallback((function(t){return void 0===t&&(t={}),i(void 0,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,null==s?void 0:s.getAccessToken(t)];case 1:return[2,e.sent()||""]}}))}))}),[s]),T=e.useCallback((function(t){return void 0===t&&(t={}),i(void 0,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,null==s?void 0:s.introspectAccessToken(t)];case 1:return[2,e.sent()]}}))}))}),[s]);return r.default.createElement(d.Provider,{value:o(o({},p),{signupWithRedirect:b,loginWithRedirect:w,logoutWithRedirect:m,getAccessToken:k,introspectAccessToken:T})},g)},t.useAuth=p,t.withAuth=function(t,n){var s=this;return void 0===n&&(n={}),function(u){var c=e.useRef(!1),l=p(),d=l.loading,f=l.loginWithRedirect,v=l.idToken,_=n.return_to,y=void 0===_?h:_,g=n.login_opts,w=!!v;return e.useEffect((function(){if(c.current=!0,!d&&!w)return i(s,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,f(o(o({},g),{state:{return_to:"function"==typeof y?y():y}}))];case 1:return t.sent(),[2]}}))})),function(){c.current=!1}}),[w,d,f,y]),w?r.default.createElement(t,o({},u)):r.default.createElement("div",null,"Loading...")}},Object.defineProperty(t,"__esModule",{value:!0})}));
***************************************************************************** */function i(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))}function a(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)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 a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}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,u])}}}function u(){throw new Error("Please wrap your app with <AuthProvider>")}var s={loading:!0},c={signupWithRedirect:u,loginWithRedirect:u,logoutWithRedirect:u,getAccessToken:u,introspectAccessToken:u},l=o(o({},s),c),d=e.createContext(l),p=function(){return e.useContext(d)},h=function(){return""+window.location.pathname+window.location.search};var f=function(t,e){return(f=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,e)};function v(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}f(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var _=function(){return(_=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 y(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 g(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))}function w(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}var m=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 v(e,t),e.create=function(t){return new e(t.error,t.error_description)},e}(Error),b=function(t,e){return void 0===e&&(e={}),g(void 0,void 0,void 0,(function(){var n,r,o,i,a;return w(this,(function(u){switch(u.label){case 0:return n=e.timeout,r=void 0===n?5e3:n,o=new AbortController,i=setTimeout((function(){return o.abort()}),r),[4,fetch(t,_(_({},e),{signal:o.signal}))];case 1:return a=u.sent(),clearTimeout(i),[2,a]}}))}))};function k(t){var e=t.wellknown_endpoint;return g(this,void 0,void 0,(function(){var t;return w(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 T(t){var e=t.tokenEndpoint,n=t.timeout,r=y(t,["tokenEndpoint","timeout"]);return g(this,void 0,void 0,(function(){var t,o,i;return w(this,(function(a){switch(a.label){case 0:return t=new FormData,Object.keys(r).forEach((function(e){return t.append(e,r[e])})),[4,b(e,{timeout:n,method:"POST",body:t})];case 1:return[4,(o=a.sent()).json()];case 2:if(i=a.sent(),200!==o.status)throw m.create(i);return[2,i]}}))}))}var R="memory",S="local_storage",O="session_storage",E="__bearer",A="__",j="crossid-spa-js",x=j+"|index",I=function(t){return null!==t&&"Object"===(null==t?void 0:t.constructor.name)},C=function(t){return"number"==typeof t},U=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 I(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}(I(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}(),L=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 v(e,t),e}(F),P=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 v(e,t),e}(F),K=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}(),z=function(t){function e(e){return t.call(this,new K,e)||this}return v(e,t),e}(F),N=function(t){return Array.from(new Set(t))},W=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},q=function(t){return btoa(t)},J=function(t){return atob(t)},M=function(t){var e={"+":"-","/":"_","=":""};return t.replace(/[+/=]/g,(function(t){return e[t]}))},G=function(t){var e={"-":"+",_:"/"};return t.replace(/[-_]/g,(function(t){return e[t]}))},Z=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("&")},B=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,a=JSON.parse(J(G(r)));if(a.aud)if(U(a.aud))a.aud=[a.aud];else if(i=a.aud,!Array.isArray(i)||!i.every((function(t){return U(t)})))throw new Error("Audience (aud) must be a string or an array of strings");return{header:JSON.parse(J(G(n))),payload:a}},H=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 v(e,t),e.prototype.getMissingFields=function(){return this.fields_},e}(Error),V=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 H(r,r.join(","));return null},Q=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}},X=function(t){return function(e){return nt("Issuer (iss)",t,e.payload.iss)}},Y=function(t){return function(e){return nt("Issuer (iss) claim",t,e.header.alg)}},$=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}},tt=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.exp)return null;if(!C(n.payload.exp))return"Expiration Time (exp) claim must be a present number";var r=rt(n.payload.exp,e);return new Date(Date.now())>r?"Expiration Time (exp) claim expired ("+r+")":null}},et=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.nbf)return null;if(!C(n.payload.nbf))return"Not Before (nbf) claim must be a present number";var r=rt(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}},nt=function(t,e,n){return e!==n?t+' mismatch: expected "'+e+'" but got "'+n+'"':null},rt=function(t,e){void 0===e&&(e=0);var n=new Date(0);return n.setUTCSeconds(t+e),n},ot=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||O),this.cache=this._cacheFactory(this.opts.cache_type||R),this._purgeIndex()}return t.prototype.createRedirectURL=function(t){return void 0===t&&(t={}),g(this,void 0,void 0,(function(){var e;return w(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 g(this,void 0,void 0,(function(){var e;return w(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.createSignupUrl=function(t){return g(this,void 0,void 0,(function(){var e;return w(this,(function(n){switch(n.label){case 0:if(!this.opts.signup_endpoint)throw new Error("signup_endpoint not defiend");return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),[2,this.opts.signup_endpoint+"?"+Z({return_to:e})]}}))}))},t.prototype.signupWithRedirect=function(t){return g(this,void 0,void 0,(function(){var e;return w(this,(function(n){switch(n.label){case 0:return[4,this.createSignupUrl(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)),g(this,void 0,void 0,(function(){var e,n,r,o,i,a,u;return w(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,T({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=B(i.id_token)).payload[E]=i.id_token,this._assertIDToken(a,o.nonce)),u=B(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={}),g(this,void 0,void 0,(function(){var e,n,r,o;return w(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={}),g(this,void 0,void 0,(function(){var n,r,o,i;return w(this,(function(a){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={}),g(this,void 0,void 0,(function(){var e,n,r,o;return w(this,(function(i){return e=this.getFinalAudience(t.audience),n=this.getFinalScope(t.scope),r=this._getTokensKeysFromCache("access_token",e,n),(o=this._getNarrowedKey(r))?[2,_(_({active:!0},o.payload),{_raw:void 0})]:[2,void 0]}))}))},t.prototype.createLogoutRedirectURL=function(t){return void 0===t&&(t={}),g(this,void 0,void 0,(function(){var e;return w(this,(function(n){switch(n.label){case 0:return[4,this._createLogoutData(t)];case 1:return(e=n.sent()).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 g(this,void 0,void 0,(function(){var e;return w(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)),g(this,void 0,void 0,(function(){var e,n,r,o;return w(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 g(this,void 0,void 0,(function(){var e,n,r,o,i,a;return w(this,(function(u){switch(u.label){case 0:return e=M(q(W())),n=M(q(W())),r=W(),[4,(c=r,g(void 0,void 0,void 0,(function(){return w(this,(function(t){switch(t.label){case 0:return[4,window.crypto.subtle.digest({name:"SHA-256"},(new TextEncoder).encode(c))];case 1:return[2,t.sent()]}}))})))];case 1:return o=u.sent(),s=new Uint8Array(o),i=M(q(String.fromCharCode.apply(String,Array.from(s)))),a={audience:t.audience,redirect_uri:t.redirect_uri,response_type:t.response_type,scope:t.scope,state:e,nonce:n,code_challenge:i},[2,{request:this._mergeAuthorizationCodeParams(a),code_verifier:r,appState:t.state}]}var s,c}))}))},t.prototype._persistAuthorizationData=function(t){return g(this,void 0,void 0,(function(){var e,n;return w(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 g(this,void 0,void 0,(function(){var e,n;return w(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[E]&&(e.id_token_hint=n[E]),r.label=2;case 2:return e.id_token_hint&&(e.state=M(q(W()))),[2,{request:e,audience:t.audience||this.opts.audience,scopes:(t.scope||this.scope).split(" "),appState:t.state}]}}))}))},t.prototype._persistLogoutData=function(t){return g(this,void 0,void 0,(function(){var e;return w(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){V(t,Q(["alg"],["iss","sub","aud","exp","iat"]),X(this.opts.issuer),Y("RS256"),$(e),tt(!0),et(!0))},t.prototype._assertIDToken=function(t,e){var n;return V(t,Q(["alg"],["iss","sub","aud","nonce","exp","iat"]),X(this.opts.issuer),(n=e,function(t){return nt("Nonce (nonce)",n,t.payload.nonce)}),Y("RS256"),$([this.opts.client_id]),tt(!0),et(!1),(function(t){return C(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+"?"+Z(t)},t.prototype._logoutUrl=function(t){var e=this.opts.logout_endpoint;return t&&(e=e+"?"+Z(t)),e},t.prototype._stateFactory=function(t){var e={ttl:300};switch(t){case S:return new P(e);case O:return new L(e);default:throw new Error('Invalid cache type "'+t+'"')}},t.prototype._cacheFactory=function(t){switch(t){case R:return new z;case S:return new P({purgeOnInit:!0});case O:return new L({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 a=this._cacheKey({tokType:t,client_id:n,audience:r,scope:o});this.cache.set(a,e,{ttl:i});var u=[r[0]||""],s=this.cache.get(x);s||(s={}),o=o.length?o:[""],u.forEach((function(t){s[t]||(s[t]={});var e=s[t];o.forEach((function(t){e[t]||(e[t]=[]),e[t].push(a)}))})),this.cache.set(x,s)},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(A)),["crossid-spa-js",n,r,o.join(A),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(A),scope:o.split(A)}},t.prototype._getTokensKeysFromCache=function(t,e,n){var r=this;void 0===e&&(e=[""]);var o,i=(this.cache.get(x)||{})[e[0]]||[""];if(!i)return[];for(var a=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:[]}},u=0,s=n;u<s.length;u++){var c=a(s[u]);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(x);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],a=function(e,n){for(var r=[],i=0;i<n.length;i++)u.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]},u=this,s=0,c=Object.entries(i);s<c.length;s++){var l=c[s];a(l[0],l[1])}Object.keys(t[o]).length||delete t[o]}this.cache.set(x,t)}},t.prototype.getFinalAudience=function(t){return t||this.opts.audience},t.prototype.getFinalScope=function(t){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return N(t.join(" ").trim().split(/\s+/))}(void 0!==t?t:this.scope)},t}();function it(t){return g(this,void 0,void 0,(function(){var e,n,r,o,i,a;return w(this,(function(u){switch(u.label){case 0:return e=t.domain,n=t.auth_server,r=void 0===n?"default":n,o=y(t,["domain","auth_server"]),i=o,[4,k({wellknown_endpoint:"https://"+e+"/oauth2/"+r+"/.well-known/openid-configuration"})];case 1:return a=u.sent(),i.authorization_endpoint=a.authorization_endpoint,i.token_endpoint=a.token_endpoint,i.issuer=a.issuer,i.logout_endpoint=i.issuer+"logout",i.signup_endpoint="https://"+e+"/auth/signup",[2,new ot(i)]}}))}))}function at(t){return g(this,void 0,void 0,(function(){var e,n,r;return w(this,(function(o){switch(o.label){case 0:return[4,k(t)];case 1:return e=o.sent(),n=y(t,["wellknown_endpoint"]),(r=n).authorization_endpoint=e.authorization_endpoint,r.token_endpoint=e.token_endpoint,r.issuer=e.issuer,[2,new ot(r)]}}))}))}function ut(t){return g(this,void 0,void 0,(function(){return w(this,(function(e){return[2,new ot(t)]}))}))}var st=function(t,e){switch(e.type){case"INITIALIZED":return o(o({},t),{loading:!1,idToken:e.idToken,error:void 0});case"LOGOUT_COMPLETED":return o(o({},t),{loading:!1,idToken:void 0,error:void 0});case"ERROR":return o(o({},t),{loading:!1,error:e.error})}},ct=function(t,e){void 0===t&&(t=window.location);var n=t.origin,r=t.pathname;if(e.some((function(t){return t===n+r}))){var o=new URLSearchParams(t.search);if(o.get("error"))return m.create({error:o.get("error")||"",error_description:o.get("error_description")||""})}},lt=function(t){return m.create({error:t.message,error_description:""})},dt=function(t){return i(void 0,void 0,void 0,(function(){var e,n,r,o;return a(this,(function(i){switch(i.label){case 0:return r=e=t,o=e,(n=e).domain?[4,it(n)]:[3,2];case 1:return[2,i.sent()];case 2:return r.wellknown_endpoint?[4,at(r)]:[3,4];case 3:return[2,i.sent()];case 4:return o.authorization_endpoint&&o.token_endpoint&&o.issuer?[4,ut(o)]:[3,6];case 5:return[2,i.sent()];case 6:throw new Error("invalid props")}}))}))},pt=function(t){window.history.replaceState({},document.title,(null==t?void 0:t.return_to)||window.location.pathname)};t.AuthProvider=function(t){var n=e.useState(),u=n[0],c=n[1],l=e.useReducer(st,s),p=l[0],h=l[1],f=t.onRedirectTo,v=void 0===f?pt:f,_=t.redirect_uri,y=t.post_logout_redirect_uri,g=t.children;e.useEffect((function(){i(void 0,void 0,void 0,(function(){var e,n;return a(this,(function(r){switch(r.label){case 0:if(u)return[3,4];r.label=1;case 1:return r.trys.push([1,3,,4]),[4,dt(t)];case 2:return e=r.sent(),c(e),[3,4];case 3:return n=r.sent(),h({type:"ERROR",error:lt(n)}),[3,4];case 4:return[2]}}))}))}),[u]),e.useEffect((function(){i(void 0,void 0,void 0,(function(){var t,e,n,r,o;return a(this,(function(i){switch(i.label){case 0:if(!u)return[3,11];i.label=1;case 1:return i.trys.push([1,10,,11]),function(t,e){void 0===t&&(t=window.location);var n=t.origin,r=t.pathname,o=new URLSearchParams(t.search);return n+r===e&&o.has("code")&&!o.has("error")}(window.location,_)?[4,u.handleRedirectCallback()]:[3,4];case 2:return t=i.sent().state,[4,u.getUser({scope:"openid"})];case 3:return r=i.sent(),h({type:"INITIALIZED",idToken:r}),v(t),[3,9];case 4:return function(t,e){void 0===t&&(t=window.location);var n=t.origin,r=t.pathname,o=new URLSearchParams(t.search);return n+r===e&&o.has("state")&&!o.has("error")}(window.location,y)?[4,u.handleLogoutRedirectCallback()]:[3,6];case 5:return e=i.sent().state,h({type:"LOGOUT_COMPLETED"}),v(e),[3,9];case 6:return ct(window.location,[_,y])?((n=ct(window.location,[_,y]))&&h({type:"ERROR",error:n}),[3,9]):[3,7];case 7:return[4,u.getUser({scope:"openid"})];case 8:r=i.sent(),h({type:"INITIALIZED",idToken:r}),i.label=9;case 9:return[3,11];case 10:return o=i.sent(),h({type:"ERROR",error:lt(o)}),[3,11];case 11:return[2]}}))}))}),[u]);var w=e.useCallback((function(t){void 0===t&&(t={}),null==u||u.loginWithRedirect(t)}),[u]),m=e.useCallback((function(e){void 0===e&&(e={}),e.post_logout_redirect_uri||(e.post_logout_redirect_uri=t.post_logout_redirect_uri),null==u||u.logoutWithRedirect(e)}),[u]),b=e.useCallback((function(t){void 0===t&&(t={}),null==u||u.signupWithRedirect(t)}),[u]),k=e.useCallback((function(t){return void 0===t&&(t={}),i(void 0,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,null==u?void 0:u.getAccessToken(t)];case 1:return[2,e.sent()||""]}}))}))}),[u]),T=e.useCallback((function(t){return void 0===t&&(t={}),i(void 0,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,null==u?void 0:u.introspectAccessToken(t)];case 1:return[2,e.sent()]}}))}))}),[u]);return r.default.createElement(d.Provider,{value:o(o({},p),{signupWithRedirect:b,loginWithRedirect:w,logoutWithRedirect:m,getAccessToken:k,introspectAccessToken:T})},g)},t.useAuth=p,t.withAuth=function(t,n){var u=this;return void 0===n&&(n={}),function(s){var c=e.useRef(!1),l=p(),d=l.loading,f=l.loginWithRedirect,v=l.idToken,_=n.return_to,y=void 0===_?h:_,g=n.login_opts,w=!!v;return e.useEffect((function(){if(c.current=!0,!d&&!w)return i(u,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,f(o(o({},g),{state:{return_to:"function"==typeof y?y():y}}))];case 1:return t.sent(),[2]}}))})),function(){c.current=!1}}),[w,d,f,y]),w?r.default.createElement(t,o({},s)):r.default.createElement("div",null,"Loading...")}},Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=crossid-react.js.map

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

import t,{createContext as e,useContext as n,useRef as r,useEffect as o,useState as i,useReducer as a,useCallback as s}from"react";
import t,{createContext as e,useContext as n,useRef as r,useEffect as o,useState as i,useReducer as a,useCallback as u}from"react";
/*! *****************************************************************************

@@ -15,17 +15,3 @@ Copyright (c) Microsoft Corporation.

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var c=function(){return(c=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 u(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}c((r=r.apply(t,e||[])).next())}))}function l(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)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 a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}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,s])}}}function p(){throw new Error("Please wrap your app with <AuthProvider>")}var d={loading:!0},h={signupWithRedirect:p,loginWithRedirect:p,logoutWithRedirect:p,getAccessToken:p,introspectAccessToken:p},f=e(c(c({},d),h)),v=function(){return n(f)},_=function(){return""+window.location.pathname+window.location.search};function y(e,n){var i=this;void 0===n&&(n={});return function(a){var s=r(!1),p=v(),d=p.loading,h=p.loginWithRedirect,f=p.idToken,y=n.return_to,g=void 0===y?_:y,w=n.login_opts,m=!!f;return o((function(){if(s.current=!0,!d&&!m)return u(i,void 0,void 0,(function(){return l(this,(function(t){switch(t.label){case 0:return[4,h(c(c({},w),{state:{return_to:"function"==typeof g?g():g}}))];case 1:return t.sent(),[2]}}))})),function(){s.current=!1}}),[m,d,h,g]),m?t.createElement(e,c({},a)):t.createElement("div",null,"Loading...")}}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var g=function(t,e){return(g=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,e)};function w(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}g(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var m=function(){return(m=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 b(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 k(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}c((r=r.apply(t,e||[])).next())}))}function T(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)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 a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}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,s])}}}var S=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 w(e,t),e.create=function(t){return new e(t.error,t.error_description)},e}(Error);function O(t){var e=t.wellknown_endpoint;return k(this,void 0,void 0,(function(){var t;return T(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 R(t){var e=t.tokenEndpoint,n=t.timeout,r=b(t,["tokenEndpoint","timeout"]);return k(this,void 0,void 0,(function(){var t,o,i;return T(this,(function(a){switch(a.label){case 0:return t=new FormData,Object.keys(r).forEach((function(e){return t.append(e,r[e])})),[4,(s=e,c={timeout:n,method:"POST",body:t},void 0===c&&(c={}),k(void 0,void 0,void 0,(function(){var t,e,n,r,o;return T(this,(function(i){switch(i.label){case 0:return t=c.timeout,e=void 0===t?5e3:t,n=new AbortController,r=setTimeout((function(){return n.abort()}),e),[4,fetch(s,m(m({},c),{signal:n.signal}))];case 1:return o=i.sent(),clearTimeout(r),[2,o]}}))})))];case 1:return[4,(o=a.sent()).json()];case 2:if(i=a.sent(),200!==o.status)throw S.create(i);return[2,i]}var s,c}))}))}var E="crossid-spa-js|index",A=function(t){return null!==t&&"Object"===(null==t?void 0:t.constructor.name)},I=function(t){return"number"==typeof t},j=function(t){return"string"==typeof t},x=String.fromCharCode(0),U=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={})[x]=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 A(n=i)&&x 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[x]: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}(A(i)&&x 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}(),D=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 w(e,t),e}(U),F=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 w(e,t),e}(U),L=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}(),C=function(t){function e(e){return t.call(this,new L,e)||this}return w(e,t),e}(U),P=function(t){return Array.from(new Set(t))},K=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},z=function(t){return btoa(t)},N=function(t){return atob(t)},W=function(t){var e={"+":"-","/":"_","=":""};return t.replace(/[+/=]/g,(function(t){return e[t]}))},q=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("&")},M=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,a=JSON.parse(N(q(r)));if(a.aud)if(j(a.aud))a.aud=[a.aud];else if(i=a.aud,!Array.isArray(i)||!i.every((function(t){return j(t)})))throw new Error("Audience (aud) must be a string or an array of strings");return{header:JSON.parse(N(q(n))),payload:a}},G=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 w(e,t),e.prototype.getMissingFields=function(){return this.fields_},e}(Error),Z=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 G(r,r.join(","));return null},B=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}},H=function(t){return function(e){return $("Issuer (iss)",t,e.payload.iss)}},V=function(t){return function(e){return $("Issuer (iss) claim",t,e.header.alg)}},Q=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}},X=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.exp)return null;if(!I(n.payload.exp))return"Expiration Time (exp) claim must be a present number";var r=tt(n.payload.exp,e);return new Date(Date.now())>r?"Expiration Time (exp) claim expired ("+r+")":null}},Y=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.nbf)return null;if(!I(n.payload.nbf))return"Not Before (nbf) claim must be a present number";var r=tt(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}},$=function(t,e,n){return e!==n?t+' mismatch: expected "'+e+'" but got "'+n+'"':null},tt=function(t,e){void 0===e&&(e=0);var n=new Date(0);return n.setUTCSeconds(t+e),n},et=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={}),k(this,void 0,void 0,(function(){var e;return T(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 k(this,void 0,void 0,(function(){var e;return T(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.createSignupUrl=function(t){return k(this,void 0,void 0,(function(){var e;return T(this,(function(n){switch(n.label){case 0:if(!this.opts.signup_endpoint)throw new Error("signup_endpoint not defiend");return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),[2,this.opts.signup_endpoint+"?"+J({return_to:e})]}}))}))},t.prototype.signupWithRedirect=function(t){return k(this,void 0,void 0,(function(){var e;return T(this,(function(n){switch(n.label){case 0:return[4,this.createSignupUrl(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)),k(this,void 0,void 0,(function(){var e,n,r,o,i,a,s;return T(this,(function(c){switch(c.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,R({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=c.sent()).id_token&&((a=M(i.id_token)).payload.__bearer=i.id_token,this._assertIDToken(a,o.nonce)),s=M(i.access_token),this.state.remove(this.loginStateKey),this._assertAccessToken(s,o.audience),s.payload._raw=i.access_token,this._cacheTokens(a,s,i.refresh_token),[2,{state:o.state}]}}))}))},t.prototype.getUser=function(t){return void 0===t&&(t={}),k(this,void 0,void 0,(function(){var e,n,r,o;return T(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={}),k(this,void 0,void 0,(function(){var n,r,o,i;return T(this,(function(a){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={}),k(this,void 0,void 0,(function(){var e,n,r,o;return T(this,(function(i){return e=this.getFinalAudience(t.audience),n=this.getFinalScope(t.scope),r=this._getTokensKeysFromCache("access_token",e,n),(o=this._getNarrowedKey(r))?[2,m(m({active:!0},o.payload),{_raw:void 0})]:[2,void 0]}))}))},t.prototype.createLogoutRedirectURL=function(t){return void 0===t&&(t={}),k(this,void 0,void 0,(function(){var e;return T(this,(function(n){switch(n.label){case 0:return[4,this._createLogoutData(t)];case 1:return(e=n.sent()).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 k(this,void 0,void 0,(function(){var e;return T(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)),k(this,void 0,void 0,(function(){var e,n,r,o;return T(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 k(this,void 0,void 0,(function(){var e,n,r,o,i,a;return T(this,(function(s){switch(s.label){case 0:return e=W(z(K())),n=W(z(K())),r=K(),[4,(u=r,k(void 0,void 0,void 0,(function(){return T(this,(function(t){switch(t.label){case 0:return[4,window.crypto.subtle.digest({name:"SHA-256"},(new TextEncoder).encode(u))];case 1:return[2,t.sent()]}}))})))];case 1:return o=s.sent(),c=new Uint8Array(o),i=W(z(String.fromCharCode.apply(String,Array.from(c)))),a={audience:t.audience,redirect_uri:t.redirect_uri,response_type:t.response_type,scope:t.scope,state:e,nonce:n,code_challenge:i},[2,{request:this._mergeAuthorizationCodeParams(a),code_verifier:r,appState:t.state}]}var c,u}))}))},t.prototype._persistAuthorizationData=function(t){return k(this,void 0,void 0,(function(){var e,n;return T(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 k(this,void 0,void 0,(function(){var e,n;return T(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=W(z(K()))),[2,{request:e,audience:t.audience||this.opts.audience,scopes:(t.scope||this.scope).split(" "),appState:t.state}]}}))}))},t.prototype._persistLogoutData=function(t){return k(this,void 0,void 0,(function(){var e;return T(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){Z(t,B(["alg"],["iss","sub","aud","exp","iat"]),H(this.opts.issuer),V("RS256"),Q(e),X(!0),Y(!0))},t.prototype._assertIDToken=function(t,e){var n;return Z(t,B(["alg"],["iss","sub","aud","nonce","exp","iat"]),H(this.opts.issuer),(n=e,function(t){return $("Nonce (nonce)",n,t.payload.nonce)}),V("RS256"),Q([this.opts.client_id]),X(!0),Y(!1),(function(t){return I(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 F(e);case"session_storage":return new D(e);default:throw new Error('Invalid cache type "'+t+'"')}},t.prototype._cacheFactory=function(t){switch(t){case"memory":return new C;case"local_storage":return new F({purgeOnInit:!0});case"session_storage":return new D({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 a=this._cacheKey({tokType:t,client_id:n,audience:r,scope:o});this.cache.set(a,e,{ttl:i});var s=[r[0]||""],c=this.cache.get(E);c||(c={}),o=o.length?o:[""],s.forEach((function(t){c[t]||(c[t]={});var e=c[t];o.forEach((function(t){e[t]||(e[t]=[]),e[t].push(a)}))})),this.cache.set(E,c)},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(E)||{})[e[0]]||[""];if(!i)return[];for(var a=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:[]}},s=0,c=n;s<c.length;s++){var u=a(c[s]);if("object"==typeof u)return u.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(E);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],a=function(e,n){for(var r=[],i=0;i<n.length;i++)s.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]},s=this,c=0,u=Object.entries(i);c<u.length;c++){var l=u[c];a(l[0],l[1])}Object.keys(t[o]).length||delete t[o]}this.cache.set(E,t)}},t.prototype.getFinalAudience=function(t){return t||this.opts.audience},t.prototype.getFinalScope=function(t){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return P(t.join(" ").trim().split(/\s+/))}(void 0!==t?t:this.scope)},t}();function nt(t){return k(this,void 0,void 0,(function(){var e,n,r,o,i,a,s;return T(this,(function(c){switch(c.label){case 0:return e=t.tenant_id,n=t.region,r=t.auth_server,o=void 0===r?"default":r,i=b(t,["tenant_id","region","auth_server"]),a=i,[4,O({wellknown_endpoint:"https://"+e+"."+n+".crossid.io/oauth2/"+o+"/.well-known/openid-configuration"})];case 1:return s=c.sent(),a.authorization_endpoint=s.authorization_endpoint,a.token_endpoint=s.token_endpoint,a.issuer=s.issuer,a.logout_endpoint=a.issuer+"logout",a.signup_endpoint="https://"+e+"."+n+".crossid.io/auth/signup",[2,new et(a)]}}))}))}function rt(t){return k(this,void 0,void 0,(function(){var e,n,r;return T(this,(function(o){switch(o.label){case 0:return[4,O(t)];case 1:return e=o.sent(),n=b(t,["wellknown_endpoint"]),(r=n).authorization_endpoint=e.authorization_endpoint,r.token_endpoint=e.token_endpoint,r.issuer=e.issuer,[2,new et(r)]}}))}))}function ot(t){return k(this,void 0,void 0,(function(){return T(this,(function(e){return[2,new et(t)]}))}))}var it=function(t,e){switch(e.type){case"INITIALIZED":return c(c({},t),{loading:!1,idToken:e.idToken,error:void 0});case"LOGOUT_COMPLETED":return c(c({},t),{loading:!1,idToken:void 0,error:void 0});case"ERROR":return c(c({},t),{loading:!1,error:e.error})}},at=function(t,e){void 0===t&&(t=window.location);var n=t.origin,r=t.pathname;if(e.some((function(t){return t===n+r}))){var o=new URLSearchParams(t.search);if(o.get("error"))return S.create({error:o.get("error")||"",error_description:o.get("error_description")||""})}},st=function(t){return S.create({error:t.message,error_description:""})},ct=function(t){return u(void 0,void 0,void 0,(function(){var e,n,r,o;return l(this,(function(i){switch(i.label){case 0:return r=e=t,o=e,(n=e).tenant_id?[4,nt(n)]:[3,2];case 1:return[2,i.sent()];case 2:return r.wellknown_endpoint?[4,rt(r)]:[3,4];case 3:return[2,i.sent()];case 4:return o.authorization_endpoint&&o.token_endpoint&&o.issuer?[4,ot(o)]:[3,6];case 5:return[2,i.sent()];case 6:throw new Error("invalid props")}}))}))},ut=function(t){window.history.replaceState({},document.title,(null==t?void 0:t.return_to)||window.location.pathname)},lt=function(e){var n=i(),r=n[0],p=n[1],h=a(it,d),v=h[0],_=h[1],y=e.onRedirectTo,g=void 0===y?ut:y,w=e.redirect_uri,m=e.post_logout_redirect_uri,b=e.children;o((function(){u(void 0,void 0,void 0,(function(){var t,n;return l(this,(function(o){switch(o.label){case 0:if(r)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,ct(e)];case 2:return t=o.sent(),p(t),[3,4];case 3:return n=o.sent(),_({type:"ERROR",error:st(n)}),[3,4];case 4:return[2]}}))}))}),[r]),o((function(){u(void 0,void 0,void 0,(function(){var t,e,n,o,i;return l(this,(function(a){switch(a.label){case 0:if(!r)return[3,11];a.label=1;case 1:return a.trys.push([1,10,,11]),function(t,e){void 0===t&&(t=window.location);var n=t.origin,r=t.pathname,o=new URLSearchParams(t.search);return n+r===e&&o.has("code")&&!o.has("error")}(window.location,w)?[4,r.handleRedirectCallback()]:[3,4];case 2:return t=a.sent().state,[4,r.getUser({scope:"openid"})];case 3:return o=a.sent(),_({type:"INITIALIZED",idToken:o}),g(t),[3,9];case 4:return function(t,e){void 0===t&&(t=window.location);var n=t.origin,r=t.pathname,o=new URLSearchParams(t.search);return n+r===e&&o.has("state")&&!o.has("error")}(window.location,m)?[4,r.handleLogoutRedirectCallback()]:[3,6];case 5:return e=a.sent().state,_({type:"LOGOUT_COMPLETED"}),g(e),[3,9];case 6:return at(window.location,[w,m])?((n=at(window.location,[w,m]))&&_({type:"ERROR",error:n}),[3,9]):[3,7];case 7:return[4,r.getUser({scope:"openid"})];case 8:o=a.sent(),_({type:"INITIALIZED",idToken:o}),a.label=9;case 9:return[3,11];case 10:return i=a.sent(),_({type:"ERROR",error:st(i)}),[3,11];case 11:return[2]}}))}))}),[r]);var k=s((function(t){void 0===t&&(t={}),null==r||r.loginWithRedirect(t)}),[r]),T=s((function(t){void 0===t&&(t={}),t.post_logout_redirect_uri||(t.post_logout_redirect_uri=e.post_logout_redirect_uri),null==r||r.logoutWithRedirect(t)}),[r]),S=s((function(t){void 0===t&&(t={}),null==r||r.signupWithRedirect(t)}),[r]),O=s((function(t){return void 0===t&&(t={}),u(void 0,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return[4,null==r?void 0:r.getAccessToken(t)];case 1:return[2,e.sent()||""]}}))}))}),[r]),R=s((function(t){return void 0===t&&(t={}),u(void 0,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return[4,null==r?void 0:r.introspectAccessToken(t)];case 1:return[2,e.sent()]}}))}))}),[r]);return t.createElement(f.Provider,{value:c(c({},v),{signupWithRedirect:S,loginWithRedirect:k,logoutWithRedirect:T,getAccessToken:O,introspectAccessToken:R})},b)};export{lt as AuthProvider,v as useAuth,y as withAuth};
***************************************************************************** */var s=function(){return(s=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 c(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))}function l(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)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 a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}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,u])}}}function p(){throw new Error("Please wrap your app with <AuthProvider>")}var d={loading:!0},h={signupWithRedirect:p,loginWithRedirect:p,logoutWithRedirect:p,getAccessToken:p,introspectAccessToken:p},f=e(s(s({},d),h)),v=function(){return n(f)},_=function(){return""+window.location.pathname+window.location.search};function y(e,n){var i=this;void 0===n&&(n={});return function(a){var u=r(!1),p=v(),d=p.loading,h=p.loginWithRedirect,f=p.idToken,y=n.return_to,g=void 0===y?_:y,w=n.login_opts,m=!!f;return o((function(){if(u.current=!0,!d&&!m)return c(i,void 0,void 0,(function(){return l(this,(function(t){switch(t.label){case 0:return[4,h(s(s({},w),{state:{return_to:"function"==typeof g?g():g}}))];case 1:return t.sent(),[2]}}))})),function(){u.current=!1}}),[m,d,h,g]),m?t.createElement(e,s({},a)):t.createElement("div",null,"Loading...")}}var g=function(t,e){return(g=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,e)};function w(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}g(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var m=function(){return(m=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 b(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 k(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))}function T(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}var S=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 w(e,t),e.create=function(t){return new e(t.error,t.error_description)},e}(Error),O=function(t,e){return void 0===e&&(e={}),k(void 0,void 0,void 0,(function(){var n,r,o,i,a;return T(this,(function(u){switch(u.label){case 0:return n=e.timeout,r=void 0===n?5e3:n,o=new AbortController,i=setTimeout((function(){return o.abort()}),r),[4,fetch(t,m(m({},e),{signal:o.signal}))];case 1:return a=u.sent(),clearTimeout(i),[2,a]}}))}))};function R(t){var e=t.wellknown_endpoint;return k(this,void 0,void 0,(function(){var t;return T(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 E(t){var e=t.tokenEndpoint,n=t.timeout,r=b(t,["tokenEndpoint","timeout"]);return k(this,void 0,void 0,(function(){var t,o,i;return T(this,(function(a){switch(a.label){case 0:return t=new FormData,Object.keys(r).forEach((function(e){return t.append(e,r[e])})),[4,O(e,{timeout:n,method:"POST",body:t})];case 1:return[4,(o=a.sent()).json()];case 2:if(i=a.sent(),200!==o.status)throw S.create(i);return[2,i]}}))}))}var A="memory",I="local_storage",j="session_storage",x="__bearer",U="__",D="crossid-spa-js",F=D+"|index",L=function(t){return null!==t&&"Object"===(null==t?void 0:t.constructor.name)},C=function(t){return"number"==typeof t},P=function(t){return"string"==typeof t},K=String.fromCharCode(0),z=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={})[K]=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)&&K 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[K]: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)&&K 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}(),N=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 w(e,t),e}(z),W=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 w(e,t),e}(z),q=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}(),J=function(t){function e(e){return t.call(this,new q,e)||this}return w(e,t),e}(z),M=function(t){return Array.from(new Set(t))},G=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},Z=function(t){return btoa(t)},B=function(t){return atob(t)},H=function(t){var e={"+":"-","/":"_","=":""};return t.replace(/[+/=]/g,(function(t){return e[t]}))},V=function(t){var e={"-":"+",_:"/"};return t.replace(/[-_]/g,(function(t){return e[t]}))},Q=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,a=JSON.parse(B(V(r)));if(a.aud)if(P(a.aud))a.aud=[a.aud];else if(i=a.aud,!Array.isArray(i)||!i.every((function(t){return P(t)})))throw new Error("Audience (aud) must be a string or an array of strings");return{header:JSON.parse(B(V(n))),payload:a}},Y=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 w(e,t),e.prototype.getMissingFields=function(){return this.fields_},e}(Error),$=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 Y(r,r.join(","));return null},tt=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}},et=function(t){return function(e){return at("Issuer (iss)",t,e.payload.iss)}},nt=function(t){return function(e){return at("Issuer (iss) claim",t,e.header.alg)}},rt=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}},ot=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.exp)return null;if(!C(n.payload.exp))return"Expiration Time (exp) claim must be a present number";var r=ut(n.payload.exp,e);return new Date(Date.now())>r?"Expiration Time (exp) claim expired ("+r+")":null}},it=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e=40),function(n){if(!t&&!n.payload.nbf)return null;if(!C(n.payload.nbf))return"Not Before (nbf) claim must be a present number";var r=ut(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}},at=function(t,e,n){return e!==n?t+' mismatch: expected "'+e+'" but got "'+n+'"':null},ut=function(t,e){void 0===e&&(e=0);var n=new Date(0);return n.setUTCSeconds(t+e),n},st=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||j),this.cache=this._cacheFactory(this.opts.cache_type||A),this._purgeIndex()}return t.prototype.createRedirectURL=function(t){return void 0===t&&(t={}),k(this,void 0,void 0,(function(){var e;return T(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 k(this,void 0,void 0,(function(){var e;return T(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.createSignupUrl=function(t){return k(this,void 0,void 0,(function(){var e;return T(this,(function(n){switch(n.label){case 0:if(!this.opts.signup_endpoint)throw new Error("signup_endpoint not defiend");return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),[2,this.opts.signup_endpoint+"?"+Q({return_to:e})]}}))}))},t.prototype.signupWithRedirect=function(t){return k(this,void 0,void 0,(function(){var e;return T(this,(function(n){switch(n.label){case 0:return[4,this.createSignupUrl(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)),k(this,void 0,void 0,(function(){var e,n,r,o,i,a,u;return T(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,E({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=X(i.id_token)).payload[x]=i.id_token,this._assertIDToken(a,o.nonce)),u=X(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={}),k(this,void 0,void 0,(function(){var e,n,r,o;return T(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={}),k(this,void 0,void 0,(function(){var n,r,o,i;return T(this,(function(a){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={}),k(this,void 0,void 0,(function(){var e,n,r,o;return T(this,(function(i){return e=this.getFinalAudience(t.audience),n=this.getFinalScope(t.scope),r=this._getTokensKeysFromCache("access_token",e,n),(o=this._getNarrowedKey(r))?[2,m(m({active:!0},o.payload),{_raw:void 0})]:[2,void 0]}))}))},t.prototype.createLogoutRedirectURL=function(t){return void 0===t&&(t={}),k(this,void 0,void 0,(function(){var e;return T(this,(function(n){switch(n.label){case 0:return[4,this._createLogoutData(t)];case 1:return(e=n.sent()).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 k(this,void 0,void 0,(function(){var e;return T(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)),k(this,void 0,void 0,(function(){var e,n,r,o;return T(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 k(this,void 0,void 0,(function(){var e,n,r,o,i,a;return T(this,(function(u){switch(u.label){case 0:return e=H(Z(G())),n=H(Z(G())),r=G(),[4,(c=r,k(void 0,void 0,void 0,(function(){return T(this,(function(t){switch(t.label){case 0:return[4,window.crypto.subtle.digest({name:"SHA-256"},(new TextEncoder).encode(c))];case 1:return[2,t.sent()]}}))})))];case 1:return o=u.sent(),s=new Uint8Array(o),i=H(Z(String.fromCharCode.apply(String,Array.from(s)))),a={audience:t.audience,redirect_uri:t.redirect_uri,response_type:t.response_type,scope:t.scope,state:e,nonce:n,code_challenge:i},[2,{request:this._mergeAuthorizationCodeParams(a),code_verifier:r,appState:t.state}]}var s,c}))}))},t.prototype._persistAuthorizationData=function(t){return k(this,void 0,void 0,(function(){var e,n;return T(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 k(this,void 0,void 0,(function(){var e,n;return T(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[x]&&(e.id_token_hint=n[x]),r.label=2;case 2:return e.id_token_hint&&(e.state=H(Z(G()))),[2,{request:e,audience:t.audience||this.opts.audience,scopes:(t.scope||this.scope).split(" "),appState:t.state}]}}))}))},t.prototype._persistLogoutData=function(t){return k(this,void 0,void 0,(function(){var e;return T(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){$(t,tt(["alg"],["iss","sub","aud","exp","iat"]),et(this.opts.issuer),nt("RS256"),rt(e),ot(!0),it(!0))},t.prototype._assertIDToken=function(t,e){var n;return $(t,tt(["alg"],["iss","sub","aud","nonce","exp","iat"]),et(this.opts.issuer),(n=e,function(t){return at("Nonce (nonce)",n,t.payload.nonce)}),nt("RS256"),rt([this.opts.client_id]),ot(!0),it(!1),(function(t){return C(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+"?"+Q(t)},t.prototype._logoutUrl=function(t){var e=this.opts.logout_endpoint;return t&&(e=e+"?"+Q(t)),e},t.prototype._stateFactory=function(t){var e={ttl:300};switch(t){case I:return new W(e);case j:return new N(e);default:throw new Error('Invalid cache type "'+t+'"')}},t.prototype._cacheFactory=function(t){switch(t){case A:return new J;case I:return new W({purgeOnInit:!0});case j:return new N({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 a=this._cacheKey({tokType:t,client_id:n,audience:r,scope:o});this.cache.set(a,e,{ttl:i});var u=[r[0]||""],s=this.cache.get(F);s||(s={}),o=o.length?o:[""],u.forEach((function(t){s[t]||(s[t]={});var e=s[t];o.forEach((function(t){e[t]||(e[t]=[]),e[t].push(a)}))})),this.cache.set(F,s)},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(U)),["crossid-spa-js",n,r,o.join(U),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(U),scope:o.split(U)}},t.prototype._getTokensKeysFromCache=function(t,e,n){var r=this;void 0===e&&(e=[""]);var o,i=(this.cache.get(F)||{})[e[0]]||[""];if(!i)return[];for(var a=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:[]}},u=0,s=n;u<s.length;u++){var c=a(s[u]);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(F);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],a=function(e,n){for(var r=[],i=0;i<n.length;i++)u.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]},u=this,s=0,c=Object.entries(i);s<c.length;s++){var l=c[s];a(l[0],l[1])}Object.keys(t[o]).length||delete t[o]}this.cache.set(F,t)}},t.prototype.getFinalAudience=function(t){return t||this.opts.audience},t.prototype.getFinalScope=function(t){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return M(t.join(" ").trim().split(/\s+/))}(void 0!==t?t:this.scope)},t}();function ct(t){return k(this,void 0,void 0,(function(){var e,n,r,o,i,a;return T(this,(function(u){switch(u.label){case 0:return e=t.domain,n=t.auth_server,r=void 0===n?"default":n,o=b(t,["domain","auth_server"]),i=o,[4,R({wellknown_endpoint:"https://"+e+"/oauth2/"+r+"/.well-known/openid-configuration"})];case 1:return a=u.sent(),i.authorization_endpoint=a.authorization_endpoint,i.token_endpoint=a.token_endpoint,i.issuer=a.issuer,i.logout_endpoint=i.issuer+"logout",i.signup_endpoint="https://"+e+"/auth/signup",[2,new st(i)]}}))}))}function lt(t){return k(this,void 0,void 0,(function(){var e,n,r;return T(this,(function(o){switch(o.label){case 0:return[4,R(t)];case 1:return e=o.sent(),n=b(t,["wellknown_endpoint"]),(r=n).authorization_endpoint=e.authorization_endpoint,r.token_endpoint=e.token_endpoint,r.issuer=e.issuer,[2,new st(r)]}}))}))}function pt(t){return k(this,void 0,void 0,(function(){return T(this,(function(e){return[2,new st(t)]}))}))}var dt=function(t,e){switch(e.type){case"INITIALIZED":return s(s({},t),{loading:!1,idToken:e.idToken,error:void 0});case"LOGOUT_COMPLETED":return s(s({},t),{loading:!1,idToken:void 0,error:void 0});case"ERROR":return s(s({},t),{loading:!1,error:e.error})}},ht=function(t,e){void 0===t&&(t=window.location);var n=t.origin,r=t.pathname;if(e.some((function(t){return t===n+r}))){var o=new URLSearchParams(t.search);if(o.get("error"))return S.create({error:o.get("error")||"",error_description:o.get("error_description")||""})}},ft=function(t){return S.create({error:t.message,error_description:""})},vt=function(t){return c(void 0,void 0,void 0,(function(){var e,n,r,o;return l(this,(function(i){switch(i.label){case 0:return r=e=t,o=e,(n=e).domain?[4,ct(n)]:[3,2];case 1:return[2,i.sent()];case 2:return r.wellknown_endpoint?[4,lt(r)]:[3,4];case 3:return[2,i.sent()];case 4:return o.authorization_endpoint&&o.token_endpoint&&o.issuer?[4,pt(o)]:[3,6];case 5:return[2,i.sent()];case 6:throw new Error("invalid props")}}))}))},_t=function(t){window.history.replaceState({},document.title,(null==t?void 0:t.return_to)||window.location.pathname)},yt=function(e){var n=i(),r=n[0],p=n[1],h=a(dt,d),v=h[0],_=h[1],y=e.onRedirectTo,g=void 0===y?_t:y,w=e.redirect_uri,m=e.post_logout_redirect_uri,b=e.children;o((function(){c(void 0,void 0,void 0,(function(){var t,n;return l(this,(function(o){switch(o.label){case 0:if(r)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,vt(e)];case 2:return t=o.sent(),p(t),[3,4];case 3:return n=o.sent(),_({type:"ERROR",error:ft(n)}),[3,4];case 4:return[2]}}))}))}),[r]),o((function(){c(void 0,void 0,void 0,(function(){var t,e,n,o,i;return l(this,(function(a){switch(a.label){case 0:if(!r)return[3,11];a.label=1;case 1:return a.trys.push([1,10,,11]),function(t,e){void 0===t&&(t=window.location);var n=t.origin,r=t.pathname,o=new URLSearchParams(t.search);return n+r===e&&o.has("code")&&!o.has("error")}(window.location,w)?[4,r.handleRedirectCallback()]:[3,4];case 2:return t=a.sent().state,[4,r.getUser({scope:"openid"})];case 3:return o=a.sent(),_({type:"INITIALIZED",idToken:o}),g(t),[3,9];case 4:return function(t,e){void 0===t&&(t=window.location);var n=t.origin,r=t.pathname,o=new URLSearchParams(t.search);return n+r===e&&o.has("state")&&!o.has("error")}(window.location,m)?[4,r.handleLogoutRedirectCallback()]:[3,6];case 5:return e=a.sent().state,_({type:"LOGOUT_COMPLETED"}),g(e),[3,9];case 6:return ht(window.location,[w,m])?((n=ht(window.location,[w,m]))&&_({type:"ERROR",error:n}),[3,9]):[3,7];case 7:return[4,r.getUser({scope:"openid"})];case 8:o=a.sent(),_({type:"INITIALIZED",idToken:o}),a.label=9;case 9:return[3,11];case 10:return i=a.sent(),_({type:"ERROR",error:ft(i)}),[3,11];case 11:return[2]}}))}))}),[r]);var k=u((function(t){void 0===t&&(t={}),null==r||r.loginWithRedirect(t)}),[r]),T=u((function(t){void 0===t&&(t={}),t.post_logout_redirect_uri||(t.post_logout_redirect_uri=e.post_logout_redirect_uri),null==r||r.logoutWithRedirect(t)}),[r]),S=u((function(t){void 0===t&&(t={}),null==r||r.signupWithRedirect(t)}),[r]),O=u((function(t){return void 0===t&&(t={}),c(void 0,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return[4,null==r?void 0:r.getAccessToken(t)];case 1:return[2,e.sent()||""]}}))}))}),[r]),R=u((function(t){return void 0===t&&(t={}),c(void 0,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return[4,null==r?void 0:r.introspectAccessToken(t)];case 1:return[2,e.sent()]}}))}))}),[r]);return t.createElement(f.Provider,{value:s(s({},v),{signupWithRedirect:S,loginWithRedirect:k,logoutWithRedirect:T,getAccessToken:O,introspectAccessToken:R})},b)};export{yt as AuthProvider,v as useAuth,y as withAuth};
//# sourceMappingURL=index.js.map
{
"author": "Crossid",
"name": "@crossid/crossid-react",
"version": "0.2.4",
"version": "0.2.5",
"description": "Openid authentication hooks for React",

@@ -37,3 +37,3 @@ "main": "index.js",

"dependencies": {
"@crossid/crossid-spa-js": "^0.4.3"
"@crossid/crossid-spa-js": "^0.4.4"
},

@@ -40,0 +40,0 @@ "peerDependencies": {

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