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