@muze-nl/metro-oidc 0.5.4 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +259 -144
- package/dist/browser.js.map +4 -4
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +4 -4
- package/package.json +4 -4
package/dist/browser.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{var be=Object.defineProperty;var Se=(e,o)=>{for(var t in o)be(e,t,{get:o[t],enumerable:!0})};var M={};Se(M,{Client:()=>E,client:()=>U,deepClone:()=>I,formdata:()=>ie,metroError:()=>g,request:()=>T,response:()=>D,trace:()=>xe,url:()=>R});var j="https://metro.muze.nl/details/";Symbol.metroProxy||(Symbol.metroProxy=Symbol("isProxy"));Symbol.metroSource||(Symbol.metroSource=Symbol("source"));var E=class e{clientOptions={url:typeof window<"u"?window.location:"https://localhost",verbs:["get","post","put","delete","patch","head","options","query"]};static tracers={};constructor(...o){for(let t of o)if(typeof t=="string"||t instanceof String)this.clientOptions.url=""+t;else if(t instanceof Function)this.#e([t]);else if(t&&typeof t=="object")for(let r in t)r=="middlewares"?this.#e(t[r]):typeof t[r]=="function"?this.clientOptions[r]=t[r](this.clientOptions[r],this.clientOptions):this.clientOptions[r]=t[r];for(let t of this.clientOptions.verbs)this[t]=async function(...r){return this.fetch(T(this.clientOptions,...r,{method:t.toUpperCase()}))}}#e(o){typeof o=="function"&&(o=[o]);let t=o.findIndex(r=>typeof r!="function");if(t>=0)throw g("metro.client: middlewares must be a function or an array of functions "+j+"client/invalid-middlewares/",o[t]);Array.isArray(this.clientOptions.middlewares)||(this.clientOptions.middlewares=[]),this.clientOptions.middlewares=this.clientOptions.middlewares.concat(o)}fetch(o,t){if(o=T(o,t),!o.url)throw g("metro.client."+o.method.toLowerCase()+": Missing url parameter "+j+"client/fetch-missing-url/",o);if(t||(t={}),typeof t!="object"||t instanceof String)throw g("metro.client.fetch: Invalid options parameter "+j+"client/fetch-invalid-options/",t);let n=[async function(a){a[Symbol.metroProxy]&&(a=a[Symbol.metroSource]);let m=await fetch(a);return D(m)}].concat(this.clientOptions?.middlewares?.slice()||[]);t=Object.assign({},this.clientOptions,t);let i;for(let c of n)i=(function(a,m){return async function(y){let u,f=Object.values(e.tracers);for(let l of f)l.request&&l.request.call(l,y,m);u=await m(y,a);for(let l of f)l.response&&l.response.call(l,u,m);return u}})(i,c);return i(o)}with(...o){return new e(I(this.clientOptions),...o)}};function U(...e){return new E(...I(e))}function ke(e,o){let t=o||{};!t.url&&o.url&&(t.url=o.url);for(let r of["method","headers","body","mode","credentials","cache","redirect","referrer","referrerPolicy","integrity","keepalive","signal","priority","url"]){let n=e[r];if(!(typeof n>"u"||n==null))if(n?.[Symbol.metroProxy]&&(n=n[Symbol.metroSource]),typeof n=="function")t[r]=n(t[r],t);else if(r=="url")t.url=R(t.url,n);else if(r=="headers"){t.headers=new Headers(o.headers),n instanceof Headers||(n=new Headers(e.headers));for(let[i,c]of n.entries())t.headers.set(i,c)}else t[r]=n}return e instanceof Request&&e.data&&(t.body=e.data),t}function T(...e){let o={url:typeof window<"u"?window.location:"https://localhost/",duplex:"half"};for(let n of e)typeof n=="string"||n instanceof URL||n instanceof URLSearchParams?o.url=R(o.url,n):n&&(n instanceof FormData||n instanceof ReadableStream||n instanceof Blob||n instanceof ArrayBuffer||n instanceof DataView)?o.body=n:n&&typeof n=="object"&&Object.assign(o,ke(n,o));let t=new Request(o.url,o),r=o.body;return r&&typeof r=="object"&&!(r instanceof String)&&!(r instanceof ReadableStream)&&!(r instanceof Blob)&&!(r instanceof ArrayBuffer)&&!(r instanceof DataView)&&!(r instanceof FormData)&&!(r instanceof URLSearchParams)&&(typeof TypedArray>"u"||!(r instanceof TypedArray))&&typeof r.toString=="function"&&(o.body=r.toString({headers:t.headers}),t=new Request(o.url,o)),Object.freeze(t),new Proxy(t,{get(n,i,c){switch(i){case Symbol.metroSource:return n;case Symbol.metroProxy:return!0;case"with":return function(...a){return r&&a.unshift({body:r}),T(n,...a)};case"data":return r}return n[i]instanceof Function?n[i].bind(n):n[i]}})}function ne(e,o){let t=o||{};!t.url&&o.url&&(t.url=o.url);for(let r of["status","statusText","headers","body","url","type","redirected"]){let n=e[r];typeof n>"u"||n==null||(n?.[Symbol.metroProxy]&&(n=n[Symbol.metroSource]),typeof n=="function"?t[r]=n(t[r],t):r=="url"?t.url=new URL(n,t.url||"https://localhost/"):t[r]=n)}return e instanceof Response&&e.data&&(t.body=e.data),t}function D(...e){let o={};for(let n of e)typeof n=="string"?o.body=n:n instanceof Response?Object.assign(o,ne(n,o)):n&&typeof n=="object"&&(n instanceof FormData||n instanceof Blob||n instanceof ArrayBuffer||n instanceof DataView||n instanceof ReadableStream||n instanceof URLSearchParams||n instanceof String||typeof TypedArray<"u"&&n instanceof TypedArray?o.body=n:Object.assign(o,ne(n,o)));let t;o.body&&(t=o.body),[101,204,205,304].includes(o.status)&&(o.body=null);let r=new Response(o.body,o);return Object.freeze(r),new Proxy(r,{get(n,i,c){switch(i){case Symbol.metroProxy:return!0;case Symbol.metroSource:return n;case"with":return function(...a){return D(n,...a)};case"data":return t;case"ok":return n.status>=200&&n.status<400}return typeof n[i]=="function"?n[i].bind(n):n[i]}})}function oe(e,o){typeof o=="function"?o(e.searchParams,e):(o=new URLSearchParams(o),o.forEach((t,r)=>{e.searchParams.append(r,t)}))}function R(...e){let o=["hash","host","hostname","href","password","pathname","port","protocol","username","search","searchParams"],t=new URL("https://localhost/");for(let r of e)if(typeof r=="string"||r instanceof String)t=new URL(r,t);else if(r instanceof URL||typeof Location<"u"&&r instanceof Location)t=new URL(r);else if(r instanceof URLSearchParams)oe(t,r);else if(r&&typeof r=="object")for(let n in r)switch(n){case"search":typeof r.search=="function"?r.search(t.search,t):t.search=new URLSearchParams(r.search);break;case"searchParams":oe(t,r.searchParams);break;default:if(!o.includes(n))throw g("metro.url: unknown url parameter "+j+"url/unknown-param-name/",n);if(typeof r[n]=="function")r[n](t[n],t);else if(typeof r[n]=="string"||r[n]instanceof String||typeof r[n]=="number"||r[n]instanceof Number||typeof r[n]=="boolean"||r[n]instanceof Boolean)t[n]=""+r[n];else if(typeof r[n]=="object"&&r[n].toString)t[n]=r[n].toString();else throw g("metro.url: unsupported value for "+n+" "+j+"url/unsupported-param-value/",e[n]);break}else throw g("metro.url: unsupported option value "+j+"url/unsupported-option-value/",r);return Object.freeze(t),new Proxy(t,{get(r,n,i){let c;switch(n){case Symbol.metroProxy:return!0;case Symbol.metroSource:return r;case"with":return function(...a){return R(r,...a)};case"filename":return r.pathname.split("/").pop();case"folderpath":return r.pathname.substring(0,r.pathname.lastIndexOf("\\")+1);case"authority":return c=r.username??"",c+=r.password?":"+r.password:"",c+=c?"@":"",c+=r.hostname,c+=r.port?":"+r.port:"",c+="/",c=r.protocol+"//"+c,c;break;case"origin":return c=r.protocol+"//"+r.hostname,c+=r.port?":"+r.port:"",c+="/",c;break;case"fragment":return r.hash.substring(1);case"scheme":return r.protocol?r.protocol.substring(0,r.protocol.length-1):""}return r[n]instanceof Function?r[n].bind(r):r[n]}})}function ie(...e){var o=new FormData;for(let t of e)if(t instanceof HTMLFormElement&&(t=new FormData(t)),t instanceof FormData)for(let r of t.entries())o.append(r[0],r[1]);else if(t&&typeof t=="object")for(let r of Object.entries(t))if(Array.isArray(r[1]))for(let n of r[1])o.append(r[0],n);else o.append(r[0],r[1]);else throw new g("metro.formdata: unknown option type "+j+"formdata/unknown-option-value/",t);return Object.freeze(o),new Proxy(o,{get:(t,r,n)=>{switch(r){case Symbol.metroProxy:return!0;case Symbol.metroSource:return t;case"with":return function(...i){return ie(t,...i)}}return t[r]instanceof Function?t[r].bind(t):t[r]}})}var H={error:(e,...o)=>{console.error("\u24C2\uFE0F ",e,...o)},info:(e,...o)=>{console.info("\u24C2\uFE0F ",e,...o)},group:e=>{console.group("\u24C2\uFE0F "+e)},groupEnd:e=>{console.groupEnd("\u24C2\uFE0F "+e)}};function g(e,...o){return H.error(e,...o),new Error(e,...o)}var xe={add(e,o){E.tracers[e]=o},delete(e){delete E.tracers[e]},clear(){E.tracers={}},group(){let e=0;return{request:(o,t)=>{e++,H.group(e),H.info(o?.url,o,t)},response:(o,t)=>{H.info(o?.body?o.body[Symbol.metroSource]:null,o,t),H.groupEnd(e),e--}}}};function I(e){if(Array.isArray(e))return e.slice().map(I);if(e&&typeof e=="object")if(e.__proto__.constructor==Object||!e.__proto__){let o=Object.assign({},e);return Object.keys(o).forEach(t=>{o[t]=I(e[t])}),o}else return e;return e}function z(e){return e=Object.assign({mimetype:"application/json",reviver:null,replacer:null,space:""},e),async function(t,r){G(t.headers.get("Accept"))||(t=t.with({headers:{Accept:e.mimetype}})),["POST","PUT","PATCH","QUERY"].includes(t.method)&&t.data&&typeof t.data=="object"&&!(t.data instanceof ReadableStream)&&(G(t.headers.get("content-type"))||(t=t.with({headers:{"Content-Type":e.mimetype}})),t=t.with({body:JSON.stringify(t.data,e.replacer,e.space)}));let n=await r(t);if(G(n.headers.get("content-type"))){let c=await n.clone().text();try{let a=JSON.parse(c,e.reviver);return n.with({body:a})}catch{}}return n}}var ve=/^application\/([a-zA-Z0-9\-_]+\+)?json\b/;function G(e){return ve.exec(e)}function L(e){return async function(t,r){let n=await r(t);if(!n.ok)if(e&&typeof e[n.status]=="function")n=e[n.status].apply(n,t);else throw new Error(n.status+": "+n.statusText,{cause:n});return n}}var se=Object.assign({},M,{mw:{jsonmw:z,thrower:L}});globalThis.metro||(globalThis.metro=se);var A=se;globalThis.assertEnabled=!1;function w(e,o){if(globalThis.assertEnabled){let t=k(e,o);if(t)throw console.error("\u{1F170}\uFE0F Assertions failed because of:",t,"in this source:",e),new Error("Assertions failed",{cause:{problems:t,source:e}})}}function s(e){return function(t,r,n){if(typeof t<"u"&&t!=null&&typeof e<"u")return k(t,e,r,n)}}function p(e){return function(t,r,n){return t==null||typeof t>"u"?_("data is required",t,e||"any value",n):typeof e<"u"?k(t,e,r,n):!1}}function B(e){return function(t,r,n){return t==null||typeof t>"u"?(Ae("data does not contain recommended value",t,e,n),!1):k(t,e,r,n)}}function b(...e){return function(t,r,n){for(let i of e)if(!k(t,i,r,n))return!1;return _("data does not match oneOf patterns",t,e,n)}}function K(...e){return function(t,r,n){if(!Array.isArray(t))return _("data is not an array",t,"anyOf",n);for(let i of t)if(b(...e)(i))return _("data does not match anyOf patterns",i,e,n);return!1}}function ae(...e){return function(t,r,n){let i=[];for(let c of e)i=i.concat(k(t,c,r,n));if(i=i.filter(Boolean),i.length)return _("data does not match all given patterns",t,e,n,i)}}function d(e,o,t){try{e instanceof URL&&(e=e.href);let r=new URL(e);if(r.href!=e&&!(r.href+"/"==e||r.href==e+"/"))return _("data is not a valid url",e,"validURL",t)}catch{return _("data is not a valid url",e,"validURL",t)}}function ce(e,o,t){if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e))return _("data is not a valid email",e,"validEmail",t)}function C(e){return function(t,r,n){if(!(t instanceof e))return _("data is not an instanceof pattern",t,e,n)}}function N(e){return function(t,r,n){if(!k(t,e,r,n))return _("data matches pattern, when required not to",t,e,n)}}function k(e,o,t,r=""){t||(t=e);let n=[];if(o===Boolean)typeof e!="boolean"&&!(e instanceof Boolean)&&n.push(_("data is not a boolean",e,o,r));else if(o===Number)typeof e!="number"&&!(e instanceof Number)&&n.push(_("data is not a number",e,o,r));else if(o===String)typeof e!="string"&&!(e instanceof String)&&n.push(_("data is not a string",e,o,r)),e==""&&n.push(_("data is an empty string, which is not allowed",e,o,r));else if(o instanceof RegExp)if(Array.isArray(e)){let i=e.findIndex((c,a)=>k(c,o,t,r+"["+a+"]"));i>-1&&n.push(_("data["+i+"] does not match pattern",e[i],o,r+"["+i+"]"))}else typeof e>"u"?n.push(_("data is undefined, should match pattern",e,o,r)):o.test(e)||n.push(_("data does not match pattern",e,o,r));else if(o instanceof Function){let i=o(e,t,r);i&&(Array.isArray(i)?n=n.concat(i):n.push(i))}else if(Array.isArray(o)){Array.isArray(e)||n.push(_("data is not an array",e,[],r));for(let i of o)for(let c of e.keys()){let a=k(e[c],i,t,r+"["+c+"]");Array.isArray(a)?n=n.concat(a):a&&n.push(a)}}else if(o&&typeof o=="object")if(Array.isArray(e)){let i=e.findIndex((c,a)=>k(c,o,t,r+"["+a+"]"));i>-1&&n.push(_("data["+i+"] does not match pattern",e[i],o,r+"["+i+"]"))}else if(!e||typeof e!="object")n.push(_("data is not an object, pattern is",e,o,r));else if(e instanceof URLSearchParams&&(e=Object.fromEntries(e)),o instanceof Function){let i=k(e,o,t,r);i&&(n=n.concat(i))}else for(let[i,c]of Object.entries(o)){let a=k(e[i],c,t,r+"."+i);a&&(n=n.concat(a))}else o!=e&&n.push(_("data and pattern are not equal",e,o,r));return n.length?n:!1}function _(e,o,t,r,n){let i={path:r,message:e,found:o,expected:t};return n&&(i.problems=n),i}function Ae(e,o,t,r){console.warn("\u{1F170}\uFE0F Assert: "+r,e,t,o)}function ue(e){let o,t;if(typeof localStorage<"u")o={get:()=>localStorage.getItem("metro/state:"+e),set:r=>localStorage.setItem("metro/state:"+e,r),has:()=>localStorage.getItem("metro/state:"+e)!==null,delete:()=>localStorage.remoteItem("metro/state:"+e)},t={get:r=>JSON.parse(localStorage.getItem(e+":"+r)),set:(r,n)=>localStorage.setItem(e+":"+r,JSON.stringify(n)),has:r=>localStorage.getItem(e+":"+r)!==null,delete:r=>localStorage.removeItem(e+":"+r)};else{let r=new Map;o={get:()=>r.get("metro/state:"+e),set:n=>r.set("metro/state:"+e,n),has:()=>r.has("metro/state:"+e),delete:()=>r.delete("metro/state:"+e)},t=new Map}return{state:o,tokens:t}}function X(e){let o={client:U(),force_authorization:!1,site:"default",oauth2_configuration:{authorization_endpoint:"/authorize",token_endpoint:"/token",redirect_uri:globalThis.document?.location.href,grant_type:"authorization_code",code_verifier:Pe(64)},authorize_callback:async u=>(window.location.href!=u.href&&window.location.replace(u.href),!1)};w(e,{});let t=Object.assign({},o.oauth2_configuration,e?.oauth2_configuration);e=Object.assign({},o,e),e.oauth2_configuration=t;let r=ue(e.site);e.tokens||(e.tokens=r.tokens),e.state||(e.state=r.state),w(e,{oauth2_configuration:{client_id:p(/.+/),grant_type:"authorization_code",authorization_endpoint:p(d),token_endpoint:p(d),redirect_uri:p(d)}});for(let u in t)switch(u){case"access_token":case"authorization_code":case"refresh_token":e.tokens.set(u,t[u]);break}return async function(u,f){if(e.force_authorization)return n(u,f);let l;try{if(l=await f(u),l.ok)return l}catch(h){switch(l.status){case 400:case 401:return n(u,f)}throw h}if(!l.ok)switch(l.status){case 400:case 401:return n(u,f)}return l};async function n(u,f){i();let l=e.tokens.get("access_token"),h=e.tokens.get("refresh_token"),S=Re(l);if(!l||S&&!h){try{if(!await c())return D("false")}catch(v){throw v}return n(u,f)}else if(S&&h){try{if(!await a())return D("false")}catch(v){throw v}return n(u,f)}else return u=T(u,{headers:{Authorization:l.type+" "+l.value}}),f(u)}function i(){if(typeof window<"u"&&window?.location){let u=R(window.location),f,l,h;if(u.searchParams.has("code"))h=u.searchParams,u=u.with({search:""}),history.pushState({},"",u.href);else if(u.hash){let S=u.hash.substr(1);h=new URLSearchParams("?"+S),u=u.with({hash:""}),history.pushState({},"",u.href)}if(h){f=h.get("code"),l=h.get("state");let S=e.state.get("metro/state");if(!l||l!==S)return;f&&e.tokens.set("authorization_code",f)}}}async function c(){if(t.grant_type==="authorization_code"&&!e.tokens.has("authorization_code")){let h=await m();if(!e.authorize_callback||typeof e.authorize_callback!="function")throw g("oauth2mw: oauth2 with grant_type:authorization_code requires a callback function in client options.authorize_callback");let S=await e.authorize_callback(h);if(S)e.tokens.set("authorization_code",S);else return!1}let u=y(),f=await e.client.post(u);if(!f.ok){let h=await f.text();throw g("OAuth2mw: fetch access_token: "+f.status+": "+f.statusText,{cause:u})}let l=await f.json();if(e.tokens.set("access_token",{value:l.access_token,expires:le(l.expires_in),type:l.token_type,scope:l.scope}),l.refresh_token){let h={value:l.refresh_token};e.tokens.set("refresh_token",h)}return e.tokens.delete("authorization_code"),l}async function a(){let u=y("refresh_token"),f=await e.client.post(u);if(!f.ok)throw g("OAuth2mw: refresh access_token: "+f.status+": "+f.statusText,{cause:u});let l=await f.json();if(e.tokens.set("access_token",{value:l.access_token,expires:le(l.expires_in),type:l.token_type,scope:l.scope}),l.refresh_token){let h={value:l.refresh_token};e.tokens.set("refresh_token",h)}else return!1;return l}async function m(){if(!t.authorization_endpoint)throw g("oauth2mw: Missing options.oauth2_configuration.authorization_endpoint");let u=R(t.authorization_endpoint,{hash:""});w(t,{client_id:/.+/,redirect_uri:/.+/,scope:/.*/});let f={response_type:"code",client_id:t.client_id,redirect_uri:t.redirect_uri,state:t.state||je(40)};return t.response_type&&(f.response_type=t.response_type),t.response_mode&&(f.response_mode=t.response_mode),e.state.set(f.state),t.client_secret&&(f.client_secret=t.client_secret),t.code_verifier&&(e.tokens.set("code_verifier",t.code_verifier),f.code_challenge=await Oe(t.code_verifier),f.code_challenge_method="S256"),t.scope&&(f.scope=t.scope),t.prompt&&(f.prompt=t.prompt),R(u,{search:f})}function y(u=null){if(w(t,{client_id:/.+/,redirect_uri:/.+/}),!t.token_endpoint)throw g("oauth2mw: Missing options.endpoints.token url");let f=R(t.token_endpoint,{hash:""}),l={grant_type:u||t.grant_type,client_id:t.client_id};switch(t.client_secret&&(l.client_secret=t.client_secret),t.scope&&(l.scope=t.scope),l.grant_type){case"authorization_code":l.redirect_uri=t.redirect_uri,l.code=e.tokens.get("authorization_code");let h=e.tokens.get("code_verifier");h&&(l.code_verifier=h);break;case"client_credentials":break;case"refresh_token":let S=e.tokens.get("refresh_token");l.refresh_token=S.value;break;default:throw new Error("Unknown grant_type: ".oauth2.grant_type)}return T(f,{method:"POST",body:new URLSearchParams(l)})}}function Re(e){if(!e)return!0;let o=new Date(e.expires);return new Date().getTime()>o.getTime()}function le(e){if(e instanceof Date)return new Date(e.getTime());if(typeof e=="number"){let o=new Date;return o.setSeconds(o.getSeconds()+e),o}throw new TypeError("Unknown expires type "+e)}function Pe(e=64){let o=new Uint8Array(e);return globalThis.crypto.getRandomValues(o),fe(o)}async function Oe(e){let t=new TextEncoder().encode(e),r=await globalThis.crypto.subtle.digest("SHA-256",t);return fe(r)}function fe(e){let o=Array.from(new Uint8Array(e),t=>String.fromCharCode(t)).join("");return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function je(e){let o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="",r=0;for(;r<e;)t+=o.charAt(Math.floor(Math.random()*o.length)),r++;return t}function de(){let e=new URL(document.location.href);if(!e.searchParams.has("code")){if(e.hash){let o=e.hash.substr(1);if(params=new URLSearchParams("?"+o),params.has("code"))return!0}return!1}return!0}function q(){return new Promise((e,o)=>{let t=globalThis.indexedDB.open("metro",1);t.onupgradeneeded=()=>t.result.createObjectStore("keyPairs",{keyPath:"domain"}),t.onerror=r=>{o(r)},t.onsuccess=r=>{let n=r.target.result;e({set:function(i,c){return new Promise((a,m)=>{let y=n.transaction("keyPairs","readwrite",{durability:"strict"}),u=y.objectStore("keyPairs");y.oncomplete=()=>{a()},y.onerror=m,u.put(i,c)})},get:function(i){return new Promise((c,a)=>{let m=n.transaction("keyPairs","readonly"),u=m.objectStore("keyPairs").get(i);u.onsuccess=()=>{c(u.result)},u.onerror=a,m.onerror=a})},clear:function(){return new Promise((i,c)=>{let a=n.transaction("keyPairs","readwrite"),y=a.objectStore("keyPairs").clear();y.onsuccess=()=>{i()},y.onerror=c,a.onerror=c})}})}})}var Te=new TextEncoder,ze=new TextDecoder;function $(e){return typeof e=="string"?Te.encode(e):ze.decode(e)}function pe(e){if(typeof e.modulusLength!="number"||e.modulusLength<2048)throw new ee(`${e.name} modulusLength must be at least 2048 bits`)}function Le(e){switch(e.algorithm.name){case"ECDSA":return{name:e.algorithm.name,hash:"SHA-256"};case"RSA-PSS":return pe(e.algorithm),{name:e.algorithm.name,saltLength:32};case"RSASSA-PKCS1-v1_5":return pe(e.algorithm),{name:e.algorithm.name};case"Ed25519":return{name:e.algorithm.name}}throw new P}async function Ue(e,o,t){if(t.usages.includes("sign")===!1)throw new TypeError('private CryptoKey instances used for signing assertions must include "sign" in their "usages"');let r=`${J($(JSON.stringify(e)))}.${J($(JSON.stringify(o)))}`,n=J(await crypto.subtle.sign(Le(t),t,$(r)));return`${r}.${n}`}var he=32768;function De(e){e instanceof ArrayBuffer&&(e=new Uint8Array(e));let o=[];for(let t=0;t<e.byteLength;t+=he)o.push(String.fromCharCode.apply(null,e.subarray(t,t+he)));return btoa(o.join("")).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function J(e){return De(e)}function Ke(){return J(crypto.getRandomValues(new Uint8Array(32)))}var P=class extends Error{constructor(o){super(o??"operation not supported"),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}},ee=class extends Error{constructor(o){super(o),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}};function Ce(e){if(e.algorithm.hash.name==="SHA-256")return"PS256";throw new P("unsupported RsaHashedKeyAlgorithm hash name")}function He(e){if(e.algorithm.hash.name==="SHA-256")return"RS256";throw new P("unsupported RsaHashedKeyAlgorithm hash name")}function Ie(e){if(e.algorithm.namedCurve==="P-256")return"ES256";throw new P("unsupported EcKeyAlgorithm namedCurve")}function Me(e){switch(e.algorithm.name){case"RSA-PSS":return Ce(e);case"RSASSA-PKCS1-v1_5":return He(e);case"ECDSA":return Ie(e);case"Ed25519":return"EdDSA";default:throw new P("unsupported CryptoKey algorithm name")}}function me(e){return e instanceof CryptoKey}function Be(e){return me(e)&&e.type==="private"}function Ne(e){return me(e)&&e.type==="public"}function Je(){return Math.floor(Date.now()/1e3)}async function Z(e,o,t,r,n,i){let c=e?.privateKey,a=e?.publicKey;if(!Be(c))throw new TypeError('"keypair.privateKey" must be a private CryptoKey');if(!Ne(a))throw new TypeError('"keypair.publicKey" must be a public CryptoKey');if(a.extractable!==!0)throw new TypeError('"keypair.publicKey.extractable" must be true');if(typeof o!="string")throw new TypeError('"htu" must be a string');if(typeof t!="string")throw new TypeError('"htm" must be a string');if(r!==void 0&&typeof r!="string")throw new TypeError('"nonce" must be a string or undefined');if(n!==void 0&&typeof n!="string")throw new TypeError('"accessToken" must be a string or undefined');if(i!==void 0&&(typeof i!="object"||i===null||Array.isArray(i)))throw new TypeError('"additional" must be an object');return Ue({alg:Me(c),typ:"dpop+jwt",jwk:await Fe(a)},{...i,iat:Je(),jti:Ke(),htm:t,nonce:r,htu:o,ath:n?J(await crypto.subtle.digest("SHA-256",$(n))):void 0},c)}async function Fe(e){let{kty:o,e:t,n:r,x:n,y:i,crv:c}=await crypto.subtle.exportKey("jwk",e);return{kty:o,crv:c,e:t,n:r,x:n,y:i}}async function _e(e,o){let t;if(typeof e!="string"||e.length===0)throw new TypeError('"alg" must be a non-empty string');switch(e){case"PS256":t={name:"RSA-PSS",hash:"SHA-256",modulusLength:o?.modulusLength??2048,publicExponent:new Uint8Array([1,0,1])};break;case"RS256":t={name:"RSASSA-PKCS1-v1_5",hash:"SHA-256",modulusLength:o?.modulusLength??2048,publicExponent:new Uint8Array([1,0,1])};break;case"ES256":t={name:"ECDSA",namedCurve:"P-256"};break;case"EdDSA":t={name:"Ed25519"};break;default:throw new P}return crypto.subtle.generateKey(t,o?.extractable??!1,["sign","verify"])}function te(e){return w(e,{site:p(d),authorization_endpoint:p(d),token_endpoint:p(d),dpop_signing_alg_values_supported:s([])}),async(o,t)=>{let r=await q(),n=await r.get(e.site);if(!n){let a=await _e("ES256");n={domain:e.site,keyPair:a},await r.set(n)}let i=A.url(o.url);if(o.url.startsWith(e.authorization_endpoint)){let a=o.body;a instanceof URLSearchParams||a instanceof FormData?a.set("dpop_jkt",n.keyPair.publicKey):a.dpop_jkt=n.keyPair.publicKey}else if(o.url.startsWith(e.token_endpoint)){let a=await Z(n.keyPair,o.url,o.method);o=o.with({headers:{DPoP:a}})}else if(o.headers.has("Authorization")){let a=localStorage.getItem(i.host+":nonce")||void 0,m=o.headers.get("Authorization").split(" ")[1],y=await Z(n.keyPair,o.url,o.method,a,m);o=o.with({headers:{Authorization:"DPoP "+m,DPoP:y}})}let c=await t(o);return c.headers.get("DPoP-Nonce")&&localStorage.setItem(i.host+":nonce",c.headers.get("DPoP-Nonce")),c}}var F=(...e)=>(o,t)=>e.filter(r=>t.hasOwnKey(r)).length>0?!1:_("root data must have all of",t,e),O=(...e)=>o=>Array.isArray(o)&&e.filter(t=>!o.includes(t)).length==0?!1:_("data must be an array which includes",o,e);var x=["HS256","HS384","HS512","RS256","RS384","RS512","ES256","ES384","ES512"],Q=["client_secret_post","client_secret_basic","client_secret_jwt","private_key_jwt"];async function W(e={}){w(e,{client:s(C(A.client().constructor)),issuer:p(d)});let o={client:A.client().with(L()).with(z()),requireDynamicRegistration:!1};e=Object.assign({},o,e);let t=!1;function r(m){return t}let n={issuer:p(ae(e.issuer,r)),authorization_endpoint:p(d),token_endpoint:p(d),userinfo_endpoint:B(d),jwks_uri:p(d),registration_endpoint:e.requireDynamicRegistration?p(d):B(d),scopes_supported:B(O("openid")),response_types_supported:e.requireDynamicRegistration?p(O("code","id_token","id_token token")):p([]),response_modes_supported:s([]),grant_types_supported:e.requireDynamicRegistration?s(O("authorization_code")):s([]),acr_values_supported:s([]),subject_types_supported:p([]),id_token_signing_alg_values_supported:p(O("RS256")),id_token_encryption_alg_values_supported:s([]),id_token_encryption_enc_values_supported:s([]),userinfo_signing_alg_values_supported:s([]),userinfo_encryption_alg_values_supported:s([]),userinfo_encryption_enc_values_supported:s([]),request_object_signing_alg_values_supported:s(O("RS256")),request_object_encryption_alg_values_supported:s([]),request_object_encryption_enc_values_supported:s([]),token_endpoint_auth_methods_supported:s(K(...Q)),token_endpoint_auth_signing_alg_values_supported:s(O("RS256"),N(O("none"))),display_values_supported:s(K("page","popup","touch","wap")),claim_types_supported:s(K("normal","aggregated","distributed")),claims_supported:B([]),service_documentation:s(d),claims_locales_supported:s([]),ui_locales_supported:s([]),claims_parameter_supported:s(Boolean),request_parameter_supported:s(Boolean),request_uri_parameter_supported:s(Boolean),op_policy_uri:s(d),op_tos_uri:s(d)},i=A.url(e.issuer,".well-known/openid-configuration"),a=(await e.client.get(i)).data;return w(a,n),w(a.issuer,e.issuer),a}async function V(e){let o={redirect_uris:p([d]),response_types:s([]),grant_types:s(K("authorization_code","refresh_token")),application_type:s(b("native","web")),contacts:s([ce]),client_name:s(String),logo_uri:s(d),client_uri:s(d),policy_uri:s(d),tos_uri:s(d),jwks_uri:s(d,N(F("jwks"))),jwks:s(d,N(F("jwks_uri"))),sector_identifier_uri:s(d),subject_type:s(String),id_token_signed_response_alg:s(b(...x)),id_token_encrypted_response_alg:s(b(...x)),id_token_encrypted_response_enc:s(b(...x),F("id_token_encrypted_response_alg")),userinfo_signed_response_alg:s(b(...x)),userinfo_encrypted_response_alg:s(b(...x)),userinfo_encrypted_response_enc:s(b(...x),F("userinfo_encrypted_response_alg")),request_object_signing_alg:s(b(...x)),request_object_encryption_alg:s(b(...x)),request_object_encryption_enc:s(b(...x)),token_endpoint_auth_method:s(b(...Q)),token_endpoint_auth_signing_alg:s(b(...x)),default_max_age:s(Number),require_auth_time:s(Boolean),default_acr_values:s([String]),initiate_login_uri:s([d]),request_uris:s([d])};w(e,{client:s(C(A.client().constructor)),registration_endpoint:d,client_info:o});let t={client:A.client().with(L()).with(z()),client_info:{redirect_uris:[globalThis.document?.location.href]}};e=Object.assign({},t,e),e.client_info||(e.client_info={}),e.client_info.redirect_uris||(e.client_info.redirect_uris=[globalThis.document?.location.href]);let r=await e.client.post(e.registration_endpoint,{body:e.client_info}),n=r.data;if(!n.client_id||!n.client_secret)throw A.metroError("metro.oidc: Error: dynamic registration of client failed, no client_id or client_secret returned",r);return e.client_info=Object.assign(e.client_info,n),e.client_info}function Y(e){let o;if(typeof localStorage<"u")o={get:t=>JSON.parse(localStorage.getItem("metro/oidc:"+e+":"+t)),set:(t,r)=>localStorage.setItem("metro/oidc:"+e+":"+t,JSON.stringify(r)),has:t=>localStorage.getItem("metro/oidc:"+e+":"+t)!==null};else{let t=new Map;o={get:r=>JSON.parse(t.get("metro/oidc:"+e+":"+r)||null),set:(r,n)=>t.set("metro/oidc:"+e+":"+r,JSON.stringify(n)),has:r=>t.has("metro/oidc:"+e+":"+r)}}return o}function re(e={}){let o={client:U(),force_authorization:!1,use_dpop:!0,authorize_callback:async t=>(window.location.href!=t.href&&window.location.replace(t.href),!1)};return e=Object.assign({},o,e),w(e,{client:p(C(U().constructor)),client_info:p(),issuer:p(d),oauth2:s({}),openid_configuration:s()}),e.store||(e.store=Y(e.issuer)),!e.openid_configuration&&e.store.has("openid_configuration")&&(e.openid_configuration=e.store.get("openid_configuration")),!e.client_info?.client_id&&e.store.has("client_info")&&(e.client_info=e.store.get("client_info")),async(t,r)=>{let n;if(!e.force_authorization){try{n=await r(t)}catch(y){if(n.status!=401&&n.status!=403)throw y}if(n.ok||n.status!=401&&n.status!=403)return n}if(e.openid_configuration||(e.openid_configuration=await W({issuer:e.issuer}),e.store.set("openid_configuration",e.openid_configuration)),!e.client_info?.client_id){if(!e.openid_configuration.registration_endpoint)throw g("metro.oidcmw: Error: issuer "+e.issuer+" does not support dynamic client registration, but you haven't specified a client_id");e.client_info=await V({registration_endpoint:e.openid_configuration.registration_endpoint,client_info:e.client_info}),e.store.set("client_info",e.client_info)}let i=e.scope||"openid",c=Object.assign({site:e.issuer,client:e.client,force_authorization:!0,authorize_callback:e.authorize_callback,oauth2_configuration:{client_id:e.client_info?.client_id,client_secret:e.client_info?.client_secret,grant_type:"authorization_code",response_type:"code",response_mode:"query",authorization_endpoint:e.openid_configuration.authorization_endpoint,token_endpoint:e.openid_configuration.token_endpoint,scope:i,redirect_uri:e.client_info.redirect_uris[0]}}),a=async(y,u)=>{let f=await u(y);if(f.headers.get("content-type")?.startsWith("application/json")){let h=f.data?.id_token;if(!h){let S=f.clone();try{let v=await S.json();v&&v.id_token&&(h=v.id_token)}catch{}}h&&e.store.set("id_token",h)}return f},m=e.client.with(e.issuer).with(a);if(e.use_dpop){let y={site:e.issuer,authorization_endpoint:e.openid_configuration.authorization_endpoint,token_endpoint:e.openid_configuration.token_endpoint,dpop_signing_alg_values_supported:e.openid_configuration.dpop_signing_alg_values_supported};m=m.with(te(y)),c.client=m}return m=m.with(X(c)),n=await m.fetch(t),n}}function ye(){return de()}function ge(e){if(!e.store){if(!e.issuer)throw g("Must supply options.issuer or options.store to get the id_token");e.store=Y(e.issuer)}return e.store.get("id_token")}var we={oidcmw:re,discover:W,register:V,isRedirected:ye,idToken:ge};globalThis.metro.oidc||(globalThis.metro.oidc=we);var Kt=we;})();
|
|
1
|
+
(()=>{var Ae=Object.defineProperty;var Pe=(e,o)=>{for(var t in o)Ae(e,t,{get:o[t],enumerable:!0})};var I={};Pe(I,{Client:()=>v,client:()=>E,deepClone:()=>T,formdata:()=>ue,metroError:()=>g,request:()=>C,response:()=>H,trace:()=>je,url:()=>b});var L="https://metro.muze.nl/details/";Symbol.metroProxy||(Symbol.metroProxy=Symbol("isProxy"));Symbol.metroSource||(Symbol.metroSource=Symbol("source"));var v=class e{clientOptions={url:b(typeof window<"u"?window.location:"https://localhost"),verbs:["get","post","put","delete","patch","head","options","query"]};static tracers={};constructor(...o){for(let t of o)if(typeof t=="string"||t instanceof String)this.clientOptions.url=b(this.clientOptions.url.href,t);else if(t instanceof e)Object.assign(this.clientOptions,t.clientOptions);else if(t instanceof Function)this.#e([t]);else if(t&&typeof t=="object")for(let r in t)r=="middlewares"?this.#e(t[r]):r=="url"?this.clientOptions.url=b(this.clientOptions.url.href,t[r]):typeof t[r]=="function"?this.clientOptions[r]=t[r](this.clientOptions[r],this.clientOptions):this.clientOptions[r]=t[r];for(let t of this.clientOptions.verbs)this[t]=async function(...r){return this.fetch(C(this.clientOptions,...r,{method:t.toUpperCase()}))}}#e(o){typeof o=="function"&&(o=[o]);let t=o.findIndex(r=>typeof r!="function");if(t>=0)throw g("metro.client: middlewares must be a function or an array of functions "+L+"client/invalid-middlewares/",o[t]);Array.isArray(this.clientOptions.middlewares)||(this.clientOptions.middlewares=[]),this.clientOptions.middlewares=this.clientOptions.middlewares.concat(o)}fetch(o,t){if(o=C(o,t),!o.url)throw g("metro.client."+o.method.toLowerCase()+": Missing url parameter "+L+"client/fetch-missing-url/",o);if(t||(t={}),typeof t!="object"||t instanceof String)throw g("metro.client.fetch: Invalid options parameter "+L+"client/fetch-invalid-options/",t);let n=[async function(c){c[Symbol.metroProxy]&&(c=c[Symbol.metroSource]);let _=await fetch(c);return H(_)}].concat(this.clientOptions?.middlewares?.slice()||[]);t=Object.assign({},this.clientOptions,t);let i;for(let a of n)i=(function(c,_){return async function(y){let l,f=Object.values(e.tracers);for(let u of f)u.request&&u.request.call(u,y,_);l=await _(y,c);for(let u of f)u.response&&u.response.call(u,l,_);return l}})(i,a);return i(o)}with(...o){return new e(T(this.clientOptions),...o)}get location(){return this.clientOptions.url}};function E(...e){return new v(...T(e))}function Re(e,o){let t=o||{};!t.url&&o.url&&(t.url=o.url);for(let r of["method","headers","body","mode","credentials","cache","redirect","referrer","referrerPolicy","integrity","keepalive","signal","priority","url"]){let n=e[r];if(!(typeof n>"u"||n==null))if(n?.[Symbol.metroProxy]&&(n=n[Symbol.metroSource]),typeof n=="function")t[r]=n(t[r],t);else if(r=="url")t.url=b(t.url,n);else if(r=="headers"){t.headers=new Headers(o.headers),n instanceof Headers||(n=new Headers(e.headers));for(let[i,a]of n.entries())t.headers.set(i,a)}else t[r]=n}return e instanceof Request&&e.data&&(t.body=e.data),t}function C(...e){let o={url:b(typeof window<"u"?window.location:"https://localhost/"),duplex:"half"};for(let n of e)typeof n=="string"||n instanceof URL||n instanceof URLSearchParams?o.url=b(o.url,n):n&&(n instanceof FormData||n instanceof ReadableStream||n instanceof Blob||n instanceof ArrayBuffer||n instanceof DataView)?o.body=n:n&&typeof n=="object"&&Object.assign(o,Re(n,o));let t=new Request(o.url,o),r=o.body;return r&&typeof r=="object"&&!(r instanceof String)&&!(r instanceof ReadableStream)&&!(r instanceof Blob)&&!(r instanceof ArrayBuffer)&&!(r instanceof DataView)&&!(r instanceof FormData)&&!(r instanceof URLSearchParams)&&(typeof globalThis.TypedArray>"u"||!(r instanceof globalThis.TypedArray))&&typeof r.toString=="function"&&(o.body=r.toString({headers:t.headers}),t=new Request(o.url,o)),Object.freeze(t),new Proxy(t,{get(n,i){let a;switch(i){case Symbol.metroSource:a=n;break;case Symbol.metroProxy:a=!0;break;case"with":a=function(...c){return r&&c.unshift({body:r}),C(n,...c)};break;case"data":a=r;break;default:n[i]instanceof Function?a=n[i].bind(n):a=n[i];break}return a}})}function ce(e,o){let t=o||{};!t.url&&o.url&&(t.url=o.url);for(let r of["status","statusText","headers","body","url","type","redirected"]){let n=e[r];typeof n>"u"||n==null||(n?.[Symbol.metroProxy]&&(n=n[Symbol.metroSource]),typeof n=="function"?t[r]=n(t[r],t):r=="url"?t.url=new URL(n,t.url||"https://localhost/"):t[r]=n)}return e instanceof Response&&e.data&&(t.body=e.data),t}function H(...e){let o={};for(let n of e)typeof n=="string"?o.body=n:n instanceof Response?Object.assign(o,ce(n,o)):n&&typeof n=="object"&&(n instanceof FormData||n instanceof Blob||n instanceof ArrayBuffer||n instanceof DataView||n instanceof ReadableStream||n instanceof URLSearchParams||n instanceof String||typeof globalThis.TypedArray<"u"&&n instanceof globalThis.TypedArray?o.body=n:Object.assign(o,ce(n,o)));let t;o.body&&(t=o.body),[101,204,205,304].includes(o.status)&&(o.body=null);let r=new Response(o.body,o);return Object.freeze(r),new Proxy(r,{get(n,i){let a;switch(i){case Symbol.metroProxy:a=!0;break;case Symbol.metroSource:a=n;break;case"with":a=function(...c){return H(n,...c)};break;case"data":a=t;break;case"ok":a=n.status>=200&&n.status<400;break;default:typeof n[i]=="function"?a=n[i].bind(n):a=n[i];break}return a}})}function le(e,o){typeof o=="function"?o(e.searchParams,e):(o=new URLSearchParams(o),o.forEach((t,r)=>{e.searchParams.append(r,t)}))}function b(...e){let o=["hash","host","hostname","href","password","pathname","port","protocol","username","search","searchParams"],t=new URL("https://localhost/");for(let r of e)if(typeof r=="string"||r instanceof String)t=new URL(r,t);else if(r instanceof URL||typeof Location<"u"&&r instanceof Location)t=new URL(r);else if(r instanceof URLSearchParams)le(t,r);else if(r&&typeof r=="object")for(let n in r)switch(n){case"search":typeof r.search=="function"?r.search(t.search,t):t.search=new URLSearchParams(r.search);break;case"searchParams":le(t,r.searchParams);break;default:if(!o.includes(n))throw g("metro.url: unknown url parameter "+L+"url/unknown-param-name/",n);if(typeof r[n]=="function")r[n](t[n],t);else if(typeof r[n]=="string"||r[n]instanceof String||typeof r[n]=="number"||r[n]instanceof Number||typeof r[n]=="boolean"||r[n]instanceof Boolean)t[n]=""+r[n];else if(typeof r[n]=="object"&&r[n].toString)t[n]=r[n].toString();else throw g("metro.url: unsupported value for "+n+" "+L+"url/unsupported-param-value/",e[n]);break}else throw g("metro.url: unsupported option value "+L+"url/unsupported-option-value/",r);return Object.freeze(t),new Proxy(t,{get(r,n){let i;switch(n){case Symbol.metroProxy:i=!0;break;case Symbol.metroSource:i=r;break;case"with":i=function(...a){return b(r,...a)};break;case"filename":i=r.pathname.split("/").pop();break;case"folderpath":i=r.pathname.substring(0,r.pathname.lastIndexOf("\\")+1);break;case"authority":i=r.username??"",i+=r.password?":"+r.password:"",i+=i?"@":"",i+=r.hostname,i+=r.port?":"+r.port:"",i+="/",i=r.protocol+"//"+i;break;case"origin":i=r.protocol+"//"+r.hostname,i+=r.port?":"+r.port:"",i+="/";break;case"fragment":i=r.hash.substring(1);break;case"scheme":r.protocol?i=r.protocol.substring(0,r.protocol.length-1):i="";break;default:r[n]instanceof Function?i=r[n].bind(r):i=r[n];break}return i}})}function ue(...e){var o=new FormData;for(let t of e)if(t instanceof HTMLFormElement&&(t=new FormData(t)),t instanceof FormData)for(let r of t.entries())o.append(r[0],r[1]);else if(t&&typeof t=="object")for(let r of Object.entries(t))if(Array.isArray(r[1]))for(let n of r[1])o.append(r[0],n);else o.append(r[0],r[1]);else throw new g("metro.formdata: unknown option type "+L+"formdata/unknown-option-value/",t);return Object.freeze(o),new Proxy(o,{get(t,r){let n;switch(r){case Symbol.metroProxy:n=!0;break;case Symbol.metroSource:n=t;break;case"with":n=function(...i){return ue(t,...i)};break;default:t[r]instanceof Function?n=t[r].bind(t):n=t[r];break}return n}})}var J={error:(e,...o)=>{console.error("\u24C2\uFE0F ",e,...o)},info:(e,...o)=>{console.info("\u24C2\uFE0F ",e,...o)},group:e=>{console.group("\u24C2\uFE0F "+e)},groupEnd:e=>{console.groupEnd("\u24C2\uFE0F "+e)}};function g(e,...o){return J.error(e,...o),new Error(e,...o)}var je={add(e,o){v.tracers[e]=o},delete(e){delete v.tracers[e]},clear(){v.tracers={}},group(){let e=0;return{request:(o,t)=>{e++,J.group(e),J.info(o?.url,o,t)},response:(o,t)=>{J.info(o?.body?o.body[Symbol.metroSource]:null,o,t),J.groupEnd(e),e--}}}};function T(e){if(Array.isArray(e))return e.slice().map(T);if(e&&typeof e=="object")if(e.__proto__.constructor==Object||!e.__proto__){let o=Object.assign({},e);return Object.keys(o).forEach(t=>{o[t]=T(e[t])}),o}else return e;return e}function P(e){return e=Object.assign({contentType:"application/json",reviver:null,replacer:null,space:""},e),async function(t,r){if(t.headers.get("Accept")||(t=t.with({headers:{Accept:e.accept??e.contentType}})),t.method!=="GET"&&t.method!=="HEAD"&&t.data&&typeof t.data=="object"&&!(t.data instanceof ReadableStream)){let i=t.headers.get("Content-Type");(!i||Ee(i))&&(t=t.with({headers:{"Content-Type":e.contentType}})),fe(t.headers.get("Content-Type"))&&(t=t.with({body:JSON.stringify(t.data,e.replacer,e.space)}))}let n=await r(t);if(n&&fe(n.headers?.get("Content-Type"))){let a=await n.clone().text();try{let c=JSON.parse(a,e.reviver);return n.with({body:c})}catch{}}return n}}var Te=/^application\/([a-zA-Z0-9\-_]+\+)?json\b/;function fe(e){return Te.exec(e)}function Ee(e){return/^text\/plain\b/.exec(e)}function R(e){return async function(t,r){let n=await r(t);if(!n.ok)if(e&&typeof e[n.status]=="function")n=e[n.status].apply(n,t);else throw new Error(n.status+": "+n.statusText,{cause:n});return n}}function M(){return async function(o,t){let r=await t(o);return r.ok&&r.data?r.data:r}}var V=class extends v{constructor(o,t,r=null){o instanceof v?super(o.clientOptions,R(),M()):super(o,R(),M()),r||(r=this);for(let n in t)typeof t[n]=="function"?this[n]=t[n].bind(r):t[n]&&typeof t[n]=="object"?this[n]=new this.constructor(o,t[n],r):this[n]=t[n]}},Y=class extends V{constructor(o,t,r=null){o instanceof v?super(o.with(P()),t,r):super(E(o,P()),t,r)}};function de(...e){return new V(...T(e))}function pe(...e){return new Y(...T(e))}var he=Object.assign({},I,{mw:{json:P,thrower:R,getdata:M},api:de,jsonApi:pe});globalThis.metro||(globalThis.metro=he);var j=he;globalThis.assertEnabled=!1;function ze(){globalThis.assertEnabled=!0}function Ue(){globalThis.assertEnabled=!1}function w(e,o){if(globalThis.assertEnabled){let t=S(e,o);if(t)throw console.error("\u{1F170}\uFE0F Assertions failed because of:",t,"in this source:",e),new Error("Assertions failed",{cause:{problems:t,source:e}})}}function s(e){return function(t,r,n){if(typeof t<"u"&&t!=null&&typeof e<"u")return S(t,e,r,n)}}function p(e){return function(t,r,n){return t==null||typeof t>"u"?m("data is required",t,e||"any value",n):typeof e<"u"?S(t,e,r,n):!1}}function N(e){return function(t,r,n){return t==null||typeof t>"u"?(me("data does not contain recommended value",t,e,n),!1):S(t,e,r,n)}}function k(...e){return function(t,r,n){for(let i of e)if(!S(t,i,r,n))return!1;return m("data does not match oneOf patterns",t,e,n)}}function D(...e){return function(t,r,n){if(!Array.isArray(t))return m("data is not an array",t,"anyOf",n);for(let i of t)if(k(...e)(i))return m("data does not match anyOf patterns",i,e,n);return!1}}function q(...e){return function(t,r,n){let i=[];for(let a of e)i=i.concat(S(t,a,r,n));if(i=i.filter(Boolean),i.length)return m("data does not match all given patterns",t,e,n,i)}}function d(e,o,t){try{e instanceof URL&&(e=e.href);let r=new URL(e);if(r.href!=e&&!(r.href+"/"==e||r.href==e+"/"))return m("data is not a valid url",e,"validURL",t)}catch{return m("data is not a valid url",e,"validURL",t)}}function ee(e,o,t){if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e))return m("data is not a valid email",e,"validEmail",t)}function K(e){return function(t,r,n){if(!(t instanceof e))return m("data is not an instanceof pattern",t,e,n)}}function B(e){return function(t,r,n){if(!S(t,e,r,n))return m("data matches pattern, when required not to",t,e,n)}}function S(e,o,t,r=""){t||(t=e);let n=[];if(o===Boolean)typeof e!="boolean"&&!(e instanceof Boolean)&&n.push(m("data is not a boolean",e,o,r));else if(o===Number)typeof e!="number"&&!(e instanceof Number)&&n.push(m("data is not a number",e,o,r));else if(o===String)typeof e!="string"&&!(e instanceof String)&&n.push(m("data is not a string",e,o,r)),e==""&&n.push(m("data is an empty string, which is not allowed",e,o,r));else if(o instanceof RegExp)if(Array.isArray(e)){let i=e.findIndex((a,c)=>S(a,o,t,r+"["+c+"]"));i>-1&&n.push(m("data["+i+"] does not match pattern",e[i],o,r+"["+i+"]"))}else typeof e>"u"?n.push(m("data is undefined, should match pattern",e,o,r)):o.test(e)||n.push(m("data does not match pattern",e,o,r));else if(o instanceof Function){let i=o(e,t,r);i&&(Array.isArray(i)?n=n.concat(i):n.push(i))}else if(Array.isArray(o)){Array.isArray(e)||n.push(m("data is not an array",e,[],r));for(let i of o)for(let a of e.keys()){let c=S(e[a],i,t,r+"["+a+"]");Array.isArray(c)?n=n.concat(c):c&&n.push(c)}}else if(o&&typeof o=="object")if(Array.isArray(e)){let i=e.findIndex((a,c)=>S(a,o,t,r+"["+c+"]"));i>-1&&n.push(m("data["+i+"] does not match pattern",e[i],o,r+"["+i+"]"))}else if(!e||typeof e!="object")n.push(m("data is not an object, pattern is",e,o,r));else if(e instanceof URLSearchParams&&(e=Object.fromEntries(e)),o instanceof Function){let i=S(e,o,t,r);i&&(n=n.concat(i))}else for(let[i,a]of Object.entries(o)){let c=S(e[i],a,t,r+"."+i);c&&(n=n.concat(c))}else o!=e&&n.push(m("data and pattern are not equal",e,o,r));return n.length?n:!1}function m(e,o,t,r,n){let i={path:r,message:e,found:o,expected:t};return n&&(i.problems=n),i}function me(e,o,t,r){console.warn("\u{1F170}\uFE0F Assert: "+r,e,t,o)}globalThis.assert={warn:me,error:m,assert:w,enable:ze,disable:Ue,Required:p,Recommended:N,Optional:s,oneOf:k,anyOf:D,allOf:q,validURL:d,validEmail:ee,instanceOf:K,not:B,fails:S};function _e(e){let o,t;if(typeof localStorage<"u")o={get:()=>localStorage.getItem("metro/state:"+e),set:r=>localStorage.setItem("metro/state:"+e,r),has:()=>localStorage.getItem("metro/state:"+e)!==null,delete:()=>localStorage.remoteItem("metro/state:"+e)},t={get:r=>JSON.parse(localStorage.getItem(e+":"+r)),set:(r,n)=>localStorage.setItem(e+":"+r,JSON.stringify(n)),has:r=>localStorage.getItem(e+":"+r)!==null,delete:r=>localStorage.removeItem(e+":"+r)};else{let r=new Map;o={get:()=>r.get("metro/state:"+e),set:n=>r.set("metro/state:"+e,n),has:()=>r.has("metro/state:"+e),delete:()=>r.delete("metro/state:"+e)},t=new Map}return{state:o,tokens:t}}function te(e){let o={client:E(),force_authorization:!1,site:"default",oauth2_configuration:{authorization_endpoint:"/authorize",token_endpoint:"/token",redirect_uri:globalThis.document?.location.href,grant_type:"authorization_code",code_verifier:Ce(64)},authorize_callback:async l=>(window.location.href!=l.href&&window.location.replace(l.href),!1)};w(e,{});let t=Object.assign({},o.oauth2_configuration,e?.oauth2_configuration);e=Object.assign({},o,e),e.oauth2_configuration=t;let r=_e(e.site);e.tokens||(e.tokens=r.tokens),e.state||(e.state=r.state),w(e,{oauth2_configuration:{client_id:p(/.+/),grant_type:"authorization_code",authorization_endpoint:p(d),token_endpoint:p(d),redirect_uri:p(d)}});for(let l in t)switch(l){case"access_token":case"authorization_code":case"refresh_token":e.tokens.set(l,t[l]);break}return async function(l,f){if(e.force_authorization)return n(l,f);let u;try{if(u=await f(l),u.ok)return u}catch(h){switch(u?.status){case 400:case 401:return n(l,f)}throw h}if(!u.ok)switch(u.status){case 400:case 401:return n(l,f)}return u};async function n(l,f){i();let u=e.tokens.get("access_token"),h=e.tokens.get("refresh_token"),x=Le(u);if(!u||x&&!h){try{if(!await a())return H("false")}catch(A){throw A}return n(l,f)}else if(x&&h){try{if(!await c())return H("false")}catch(A){throw A}return n(l,f)}else return l=C(l,{headers:{Authorization:u.type+" "+u.value}}),f(l)}function i(){if(typeof window<"u"&&window?.location){let l=b(window.location),f,u,h;if(l.searchParams.has("code"))h=l.searchParams,l=l.with({search:""}),history.pushState({},"",l.href);else if(l.hash){let x=l.hash.substr(1);h=new URLSearchParams("?"+x),l=l.with({hash:""}),history.pushState({},"",l.href)}if(h){f=h.get("code"),u=h.get("state");let x=e.state.get("metro/state");if(!u||u!==x)return;f&&e.tokens.set("authorization_code",f)}}}async function a(){if(t.grant_type==="authorization_code"&&!e.tokens.has("authorization_code")){let h=await _();if(!e.authorize_callback||typeof e.authorize_callback!="function")throw g("oauth2mw: oauth2 with grant_type:authorization_code requires a callback function in client options.authorize_callback");let x=await e.authorize_callback(h);if(x)e.tokens.set("authorization_code",x);else return!1}let l=y(),f=await e.client.post(l);if(!f.ok){let h=await f.text();throw g("OAuth2mw: fetch access_token: "+f.status+": "+f.statusText+" ("+h+")",{cause:l})}let u=await f.json();if(e.tokens.set("access_token",{value:u.access_token,expires:ye(u.expires_in),type:u.token_type,scope:u.scope}),u.refresh_token){let h={value:u.refresh_token};e.tokens.set("refresh_token",h)}return e.tokens.delete("authorization_code"),u}async function c(){let l=y("refresh_token"),f=await e.client.post(l);if(!f.ok)throw g("OAuth2mw: refresh access_token: "+f.status+": "+f.statusText,{cause:l});let u=await f.json();if(e.tokens.set("access_token",{value:u.access_token,expires:ye(u.expires_in),type:u.token_type,scope:u.scope}),u.refresh_token){let h={value:u.refresh_token};e.tokens.set("refresh_token",h)}else return!1;return u}async function _(){if(!t.authorization_endpoint)throw g("oauth2mw: Missing options.oauth2_configuration.authorization_endpoint");let l=b(t.authorization_endpoint,{hash:""});w(t,{client_id:/.+/,redirect_uri:/.+/,scope:/.*/});let f={response_type:"code",client_id:t.client_id,redirect_uri:t.redirect_uri,state:t.state||Ke(40)};return t.response_type&&(f.response_type=t.response_type),t.response_mode&&(f.response_mode=t.response_mode),e.state.set(f.state),t.client_secret&&(f.client_secret=t.client_secret),t.code_verifier&&(e.tokens.set("code_verifier",t.code_verifier),f.code_challenge=await De(t.code_verifier),f.code_challenge_method="S256"),t.scope&&(f.scope=t.scope),t.prompt&&(f.prompt=t.prompt),b(l,{search:f})}function y(l=null){if(w(t,{client_id:/.+/,redirect_uri:/.+/}),!t.token_endpoint)throw g("oauth2mw: Missing options.endpoints.token url");let f=b(t.token_endpoint,{hash:""}),u={grant_type:l||t.grant_type,client_id:t.client_id};switch(t.client_secret&&(u.client_secret=t.client_secret),t.scope&&(u.scope=t.scope),u.grant_type){case"authorization_code":u.redirect_uri=t.redirect_uri,u.code=e.tokens.get("authorization_code");let h=e.tokens.get("code_verifier");h&&(u.code_verifier=h);break;case"client_credentials":break;case"refresh_token":u.refresh_token=e.tokens.get("refresh_token");break;default:throw new Error("Unknown grant_type: ".oauth2.grant_type)}return C(f,{method:"POST",body:new URLSearchParams(u)})}}function Le(e){if(!e)return!0;let o=new Date(e.expires);return new Date().getTime()>o.getTime()}function ye(e){if(e instanceof Date)return new Date(e.getTime());if(typeof e=="number"){let o=new Date;return o.setSeconds(o.getSeconds()+e),o}throw new TypeError("Unknown expires type "+e)}function Ce(e=64){let o=new Uint8Array(e);return globalThis.crypto.getRandomValues(o),ge(o)}async function De(e){let t=new TextEncoder().encode(e),r=await globalThis.crypto.subtle.digest("SHA-256",t);return ge(r)}function ge(e){let o=Array.from(new Uint8Array(e),t=>String.fromCharCode(t)).join("");return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Ke(e){let o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="",r=0;for(;r<e;)t+=o.charAt(Math.floor(Math.random()*o.length)),r++;return t}function we(){let e=new URL(document.location.href);if(!e.searchParams.has("code")){if(e.hash){let o=e.hash.substr(1);if(new URLSearchParams("?"+o).has("code"))return!0}return!1}return!0}function re(){return new Promise((e,o)=>{let t=globalThis.indexedDB.open("metro",1);t.onupgradeneeded=()=>t.result.createObjectStore("keyPairs",{keyPath:"domain"}),t.onerror=r=>{o(r)},t.onsuccess=r=>{let n=r.target.result;e({set:function(i,a){return new Promise((c,_)=>{let y=n.transaction("keyPairs","readwrite",{durability:"strict"}),l=y.objectStore("keyPairs");y.oncomplete=()=>{c()},y.onerror=_,l.put(i,a)})},get:function(i){return new Promise((a,c)=>{let _=n.transaction("keyPairs","readonly"),l=_.objectStore("keyPairs").get(i);l.onsuccess=()=>{a(l.result)},l.onerror=c,_.onerror=c})},clear:function(){return new Promise((i,a)=>{let c=n.transaction("keyPairs","readwrite"),y=c.objectStore("keyPairs").clear();y.onsuccess=()=>{i()},y.onerror=a,c.onerror=a})}})}})}var Ie=new TextEncoder,Me=new TextDecoder;function Z(e){return typeof e=="string"?Ie.encode(e):Me.decode(e)}function be(e){if(typeof e.modulusLength!="number"||e.modulusLength<2048)throw new oe(`${e.name} modulusLength must be at least 2048 bits`)}function Ne(e){switch(e.algorithm.name){case"ECDSA":return{name:e.algorithm.name,hash:"SHA-256"};case"RSA-PSS":return be(e.algorithm),{name:e.algorithm.name,saltLength:32};case"RSASSA-PKCS1-v1_5":return be(e.algorithm),{name:e.algorithm.name};case"Ed25519":return{name:e.algorithm.name}}throw new z}async function Be(e,o,t){if(t.usages.includes("sign")===!1)throw new TypeError('private CryptoKey instances used for signing assertions must include "sign" in their "usages"');let r=`${G(Z(JSON.stringify(e)))}.${G(Z(JSON.stringify(o)))}`,n=G(await crypto.subtle.sign(Ne(t),t,Z(r)));return`${r}.${n}`}var ne;Uint8Array.prototype.toBase64?ne=e=>(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),e.toBase64({alphabet:"base64url",omitPadding:!0})):ne=o=>{o instanceof ArrayBuffer&&(o=new Uint8Array(o));let t=[];for(let r=0;r<o.byteLength;r+=32768)t.push(String.fromCharCode.apply(null,o.subarray(r,r+32768)));return btoa(t.join("")).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")};function G(e){return ne(e)}var z=class extends Error{constructor(o){var t;super(o??"operation not supported"),this.name=this.constructor.name,(t=Error.captureStackTrace)===null||t===void 0||t.call(Error,this,this.constructor)}},oe=class extends Error{constructor(o){var t;super(o),this.name=this.constructor.name,(t=Error.captureStackTrace)===null||t===void 0||t.call(Error,this,this.constructor)}};function Je(e){if(e.algorithm.hash.name==="SHA-256")return"PS256";throw new z("unsupported RsaHashedKeyAlgorithm hash name")}function Fe(e){if(e.algorithm.hash.name==="SHA-256")return"RS256";throw new z("unsupported RsaHashedKeyAlgorithm hash name")}function We(e){if(e.algorithm.namedCurve==="P-256")return"ES256";throw new z("unsupported EcKeyAlgorithm namedCurve")}function $e(e){switch(e.algorithm.name){case"RSA-PSS":return Je(e);case"RSASSA-PKCS1-v1_5":return Fe(e);case"ECDSA":return We(e);case"Ed25519":return"Ed25519";default:throw new z("unsupported CryptoKey algorithm name")}}function ke(e){return e instanceof CryptoKey}function Ve(e){return ke(e)&&e.type==="private"}function Ze(e){return ke(e)&&e.type==="public"}function Ge(){return Math.floor(Date.now()/1e3)}async function ie(e,o,t,r,n,i){let a=e?.privateKey,c=e?.publicKey;if(!Ve(a))throw new TypeError('"keypair.privateKey" must be a private CryptoKey');if(!Ze(c))throw new TypeError('"keypair.publicKey" must be a public CryptoKey');if(c.extractable!==!0)throw new TypeError('"keypair.publicKey.extractable" must be true');if(typeof o!="string")throw new TypeError('"htu" must be a string');if(typeof t!="string")throw new TypeError('"htm" must be a string');if(r!==void 0&&typeof r!="string")throw new TypeError('"nonce" must be a string or undefined');if(n!==void 0&&typeof n!="string")throw new TypeError('"accessToken" must be a string or undefined');if(i!==void 0&&(typeof i!="object"||i===null||Array.isArray(i)))throw new TypeError('"additional" must be an object');return Be({alg:$e(a),typ:"dpop+jwt",jwk:await Qe(c)},Object.assign(Object.assign({},i),{iat:Ge(),jti:crypto.randomUUID(),htm:t,nonce:r,htu:o,ath:n?G(await crypto.subtle.digest("SHA-256",Z(n))):void 0}),a)}async function Qe(e){let{kty:o,e:t,n:r,x:n,y:i,crv:a}=await crypto.subtle.exportKey("jwk",e);return{kty:o,crv:a,e:t,n:r,x:n,y:i}}async function Se(e,o){var t;let r;if(typeof e!="string"||e.length===0)throw new TypeError('"alg" must be a non-empty string');switch(e){case"PS256":r={name:"RSA-PSS",hash:"SHA-256",modulusLength:2048,publicExponent:new Uint8Array([1,0,1])};break;case"RS256":r={name:"RSASSA-PKCS1-v1_5",hash:"SHA-256",modulusLength:2048,publicExponent:new Uint8Array([1,0,1])};break;case"ES256":r={name:"ECDSA",namedCurve:"P-256"};break;case"Ed25519":r={name:"Ed25519"};break;default:throw new z}return crypto.subtle.generateKey(r,(t=o?.extractable)!==null&&t!==void 0?t:!1,["sign","verify"])}function se(e){return w(e,{site:p(d),authorization_endpoint:p(d),token_endpoint:p(d),dpop_signing_alg_values_supported:s([])}),async(o,t)=>{let r=await re(),n=await r.get(e.site);if(!n){let c=await Se("ES256");n={domain:e.site,keyPair:c},await r.set(n)}let i=j.url(o.url);if(o.url.startsWith(e.authorization_endpoint)){let c=o.body;c instanceof URLSearchParams||c instanceof FormData?c.set("dpop_jkt",n.keyPair.publicKey):c.dpop_jkt=n.keyPair.publicKey}else if(o.url.startsWith(e.token_endpoint)){let c=await ie(n.keyPair,o.url,o.method);o=o.with({headers:{DPoP:c}})}else if(o.headers.has("Authorization")){let c=localStorage.getItem(i.host+":nonce")||void 0,_=o.headers.get("Authorization").split(" ")[1],y=await ie(n.keyPair,o.url,o.method,c,_);o=o.with({headers:{Authorization:"DPoP "+_,DPoP:y}})}let a=await t(o);return a.headers.get("DPoP-Nonce")&&localStorage.setItem(i.host+":nonce",a.headers.get("DPoP-Nonce")),a}}var F=(...e)=>(o,t)=>e.filter(r=>t.hasOwnKey(r)).length>0?!1:m("root data must have all of",t,e),U=(...e)=>o=>Array.isArray(o)&&e.filter(t=>!o.includes(t)).length==0?!1:m("data must be an array which includes",o,e);var O=["HS256","HS384","HS512","RS256","RS384","RS512","ES256","ES384","ES512"],Q=["client_secret_post","client_secret_basic","client_secret_jwt","private_key_jwt"];async function W(e={}){w(e,{client:s(K(j.client().constructor)),issuer:p(d)});let o={client:j.client().with(R()).with(P()),requireDynamicRegistration:!1};e=Object.assign({},o,e);let t=!1;function r(_){return t}let n={issuer:p(q(e.issuer,r)),authorization_endpoint:p(d),token_endpoint:p(d),userinfo_endpoint:N(d),jwks_uri:p(d),registration_endpoint:e.requireDynamicRegistration?p(d):N(d),scopes_supported:N(U("openid")),response_types_supported:e.requireDynamicRegistration?p(U("code","id_token","id_token token")):p([]),response_modes_supported:s([]),grant_types_supported:e.requireDynamicRegistration?s(U("authorization_code")):s([]),acr_values_supported:s([]),subject_types_supported:p([]),id_token_signing_alg_values_supported:p(U("RS256")),id_token_encryption_alg_values_supported:s([]),id_token_encryption_enc_values_supported:s([]),userinfo_signing_alg_values_supported:s([]),userinfo_encryption_alg_values_supported:s([]),userinfo_encryption_enc_values_supported:s([]),request_object_signing_alg_values_supported:s(U("RS256")),request_object_encryption_alg_values_supported:s([]),request_object_encryption_enc_values_supported:s([]),token_endpoint_auth_methods_supported:s(D(...Q)),token_endpoint_auth_signing_alg_values_supported:s(U("RS256"),B(U("none"))),display_values_supported:s(D("page","popup","touch","wap")),claim_types_supported:s(D("normal","aggregated","distributed")),claims_supported:N([]),service_documentation:s(d),claims_locales_supported:s([]),ui_locales_supported:s([]),claims_parameter_supported:s(Boolean),request_parameter_supported:s(Boolean),request_uri_parameter_supported:s(Boolean),op_policy_uri:s(d),op_tos_uri:s(d)},i=j.url(e.issuer,".well-known/openid-configuration"),c=(await e.client.get(i)).data;return w(c,n),w(c.issuer,e.issuer),c}async function $(e){let o={redirect_uris:p([d]),response_types:s([]),grant_types:s(D("authorization_code","refresh_token")),application_type:s(k("native","web")),contacts:s([ee]),client_name:s(String),logo_uri:s(d),client_uri:s(d),policy_uri:s(d),tos_uri:s(d),jwks_uri:s(d,B(F("jwks"))),jwks:s(d,B(F("jwks_uri"))),sector_identifier_uri:s(d),subject_type:s(String),id_token_signed_response_alg:s(k(...O)),id_token_encrypted_response_alg:s(k(...O)),id_token_encrypted_response_enc:s(k(...O),F("id_token_encrypted_response_alg")),userinfo_signed_response_alg:s(k(...O)),userinfo_encrypted_response_alg:s(k(...O)),userinfo_encrypted_response_enc:s(k(...O),F("userinfo_encrypted_response_alg")),request_object_signing_alg:s(k(...O)),request_object_encryption_alg:s(k(...O)),request_object_encryption_enc:s(k(...O)),token_endpoint_auth_method:s(k(...Q)),token_endpoint_auth_signing_alg:s(k(...O)),default_max_age:s(Number),require_auth_time:s(Boolean),default_acr_values:s([String]),initiate_login_uri:s([d]),request_uris:s([d])};w(e,{client:s(K(j.client().constructor)),registration_endpoint:d,client_info:o});let t={client:j.client().with(R()).with(P()),client_info:{redirect_uris:[globalThis.document?.location.href]}};e=Object.assign({},t,e),e.client_info||(e.client_info={}),e.client_info.redirect_uris||(e.client_info.redirect_uris=[globalThis.document?.location.href]);let r=await e.client.post(e.registration_endpoint,{body:e.client_info}),n=r.data;if(!n.client_id||!n.client_secret)throw j.metroError("metro.oidc: Error: dynamic registration of client failed, no client_id or client_secret returned",r);return e.client_info=Object.assign(e.client_info,n),e.client_info}function X(e){let o;if(typeof localStorage<"u")o={get:t=>JSON.parse(localStorage.getItem("metro/oidc:"+e+":"+t)),set:(t,r)=>localStorage.setItem("metro/oidc:"+e+":"+t,JSON.stringify(r)),has:t=>localStorage.getItem("metro/oidc:"+e+":"+t)!==null};else{let t=new Map;o={get:r=>JSON.parse(t.get("metro/oidc:"+e+":"+r)||null),set:(r,n)=>t.set("metro/oidc:"+e+":"+r,JSON.stringify(n)),has:r=>t.has("metro/oidc:"+e+":"+r)}}return o}function ae(e={}){let o={client:E(),force_authorization:!1,use_dpop:!0,authorize_callback:async t=>(window.location.href!=t.href&&window.location.replace(t.href),!1)};return e=Object.assign({},o,e),w(e,{client:p(K(E().constructor)),client_info:p(),issuer:p(d),oauth2:s({}),openid_configuration:s()}),e.store||(e.store=X(e.issuer)),!e.openid_configuration&&e.store.has("openid_configuration")&&(e.openid_configuration=e.store.get("openid_configuration")),!e.client_info?.client_id&&e.store.has("client_info")&&(e.client_info=e.store.get("client_info")),async(t,r)=>{let n;if(!e.force_authorization){try{n=await r(t)}catch(y){if(n.status!=401&&n.status!=403)throw y}if(n.ok||n.status!=401&&n.status!=403)return n}if(e.openid_configuration||(e.openid_configuration=await W({issuer:e.issuer}),e.store.set("openid_configuration",e.openid_configuration)),!e.client_info?.client_id){if(!e.openid_configuration.registration_endpoint)throw g("metro.oidcmw: Error: issuer "+e.issuer+" does not support dynamic client registration, but you haven't specified a client_id");e.client_info=await $({registration_endpoint:e.openid_configuration.registration_endpoint,client_info:e.client_info}),e.store.set("client_info",e.client_info)}let i=e.scope||"openid",a=Object.assign({site:e.issuer,client:e.client,force_authorization:!0,authorize_callback:e.authorize_callback,oauth2_configuration:{client_id:e.client_info?.client_id,client_secret:e.client_info?.client_secret,grant_type:"authorization_code",response_type:"code",response_mode:"query",authorization_endpoint:e.openid_configuration.authorization_endpoint,token_endpoint:e.openid_configuration.token_endpoint,scope:i,redirect_uri:e.client_info.redirect_uris[0]}}),c=async(y,l)=>{let f=await l(y);if(f.headers.get("content-type")?.startsWith("application/json")){let h=f.data?.id_token;if(!h){let x=f.clone();try{let A=await x.json();A&&A.id_token&&(h=A.id_token)}catch{}}h&&e.store.set("id_token",h)}return f},_=e.client.with(e.issuer).with(c);if(e.use_dpop){let y={site:e.issuer,authorization_endpoint:e.openid_configuration.authorization_endpoint,token_endpoint:e.openid_configuration.token_endpoint,dpop_signing_alg_values_supported:e.openid_configuration.dpop_signing_alg_values_supported};_=_.with(se(y)),a.client=_}return _=_.with(te(a)),n=await _.fetch(t),n}}function xe(){return we()}function ve(e){if(!e.store){if(!e.issuer)throw g("Must supply options.issuer or options.store to get the id_token");e.store=X(e.issuer)}return e.store.get("id_token")}var Oe={oidcmw:ae,discover:W,register:$,isRedirected:xe,idToken:ve};globalThis.metro.oidc||(globalThis.metro.oidc=Oe);var Qt=Oe;})();
|
|
2
2
|
//# sourceMappingURL=browser.min.js.map
|