@crossid/crossid-react
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -0,1 +1,11 @@ | ||
## 0.2.4 | ||
[All Changes](https://github.com/crossid/crossid-spa-js/compare/v0.2.3...v0.2.4) | ||
### Major Changes | ||
- Support for crossid tenant's region configuration. | ||
- `signupWithRedirect()` method | ||
- upgrade `@crossid/crossid-spa-js` to v0.4.3 | ||
## 0.2.3 | ||
@@ -2,0 +12,0 @@ |
@@ -15,3 +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={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}; | ||
***************************************************************************** */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}; | ||
/*! ***************************************************************************** | ||
@@ -31,3 +31,3 @@ Copyright (c) Microsoft Corporation. | ||
***************************************************************************** */ | ||
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)},O=function(t){return"number"==typeof t},E=function(t){return"string"==typeof t},S=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={})[S]=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)&&S 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[S]: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)&&S 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(E(a.aud))a.aud=[a.aud];else if(i=a.aud,!Array.isArray(i)||!i.every((function(t){return E(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(!O(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(!O(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.createRegistrationUrl=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.registration_endpoint)throw new Error("registration_endpoint not defiend");return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),[2,this.opts.registration_endpoint+"?"+z({return_to:e})]}}))}))},t.prototype.registerWithRedirect=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.createRegistrationUrl(t)];case 1:return e=n.sent(),window.location.replace(e),[2]}}))}))},t.prototype.handleRedirectCallback=function(t){return void 0===t&&(t=new URL(window.location.href)),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 O(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;return w(this,(function(s){switch(s.label){case 0:return e=t.tenant_id,n=t.auth_server,r=void 0===n?"default":n,o=y(t,["tenant_id","auth_server"]),i=o,[4,b({wellknown_endpoint:"https://"+e+".crossid.io/oauth2/"+r+"/.well-known/openid-configuration"})];case 1:return a=s.sent(),i.authorization_endpoint=a.authorization_endpoint,i.token_endpoint=a.token_endpoint,i.issuer=a.issuer,i.logout_endpoint=i.issuer+"logout",i.registration_endpoint="https://"+e+".crossid.io/auth/register",[2,new X(i)]}}))}))}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){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]),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.introspectAccessToken(t)];case 1:return[2,e.sent()]}}))}))}),[s]);return r.default.createElement(d.Provider,{value:o(o({},p),{loginWithRedirect:w,logoutWithRedirect:m,getAccessToken:b,introspectAccessToken:k})},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})})); | ||
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})})); | ||
//# sourceMappingURL=crossid-react.js.map |
@@ -15,3 +15,3 @@ 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"; | ||
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 d(){throw new Error("Please wrap your app with <AuthProvider>")}var p={loading:!0},h={loginWithRedirect:d,logoutWithRedirect:d,getAccessToken:d,introspectAccessToken:d},f=e(c(c({},p),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),d=v(),p=d.loading,h=d.loginWithRedirect,f=d.idToken,y=n.return_to,g=void 0===y?_:y,w=n.login_opts,m=!!f;return o((function(){if(s.current=!0,!p&&!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,p,h,g]),m?t.createElement(e,c({},a)):t.createElement("div",null,"Loading...")}} | ||
***************************************************************************** */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...")}} | ||
/*! ***************************************************************************** | ||
@@ -30,3 +30,3 @@ Copyright (c) Microsoft Corporation. | ||
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 O=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 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 S(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 O.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.createRegistrationUrl=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.registration_endpoint)throw new Error("registration_endpoint not defiend");return[4,this.createRedirectURL(t)];case 1:return e=n.sent(),[2,this.opts.registration_endpoint+"?"+J({return_to:e})]}}))}))},t.prototype.registerWithRedirect=function(t){return k(this,void 0,void 0,(function(){var e;return T(this,(function(n){switch(n.label){case 0:return[4,this.createRegistrationUrl(t)];case 1:return e=n.sent(),window.location.replace(e),[2]}}))}))},t.prototype.handleRedirectCallback=function(t){return void 0===t&&(t=new URL(window.location.href)),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,S({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;return T(this,(function(s){switch(s.label){case 0:return e=t.tenant_id,n=t.auth_server,r=void 0===n?"default":n,o=b(t,["tenant_id","auth_server"]),i=o,[4,R({wellknown_endpoint:"https://"+e+".crossid.io/oauth2/"+r+"/.well-known/openid-configuration"})];case 1:return a=s.sent(),i.authorization_endpoint=a.authorization_endpoint,i.token_endpoint=a.token_endpoint,i.issuer=a.issuer,i.logout_endpoint=i.issuer+"logout",i.registration_endpoint="https://"+e+".crossid.io/auth/register",[2,new et(i)]}}))}))}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,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 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 O.create({error:o.get("error")||"",error_description:o.get("error_description")||""})}},st=function(t){return O.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],d=n[1],h=a(it,p),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(),d(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]),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),{loginWithRedirect:k,logoutWithRedirect:T,getAccessToken:O,introspectAccessToken:R})},b)};export{lt as AuthProvider,v as useAuth,y as withAuth}; | ||
***************************************************************************** */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}; | ||
//# sourceMappingURL=index.js.map |
@@ -22,2 +22,11 @@ /// <reference types="react" /> | ||
/** | ||
* Sign user up. | ||
* | ||
* ```ts | ||
* signupWithRedirect({redirectUri: "/home"}) | ||
* ``` | ||
* | ||
*/ | ||
signupWithRedirect: (opts: AuthorizationOpts) => void; | ||
/** | ||
* Logs user in. | ||
@@ -24,0 +33,0 @@ * |
{ | ||
"author": "Crossid", | ||
"name": "@crossid/crossid-react", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Openid authentication hooks for React", | ||
@@ -37,3 +37,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@crossid/crossid-spa-js": "^0.4.1" | ||
"@crossid/crossid-spa-js": "^0.4.3" | ||
}, | ||
@@ -40,0 +40,0 @@ "peerDependencies": { |
@@ -27,2 +27,3 @@ # @crossid/crossid-react [![npm version](https://img.shields.io/npm/v/@crossid/crossid-react?style=flat)](https://www.npmjs.com/package/@crossid/crossid-react) [![Test](https://github.com/crossid/crossid-react/actions/workflows/test.yml/badge.svg)](https://github.com/crossid/crossid-react/actions/workflows/test.yml) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://reactjs.org/docs/how-to-contribute.html#your-first-pull-request) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/crossid/crossid-react/blob/main/LICENSE) | ||
tenant_id="<tenant>" | ||
region="us" | ||
client_id="<client_id>" | ||
@@ -44,2 +45,7 @@ redirect_uri={`${window.location.origin}/`} | ||
{!idToken && ( | ||
<button type="button" onClick={() => signupWithRedirect({ state: { return_to: '/home' } })}> | ||
Signup | ||
</button> | ||
)} | ||
{!idToken && ( | ||
<button | ||
@@ -46,0 +52,0 @@ type="button" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
232927
446
125