UNPKG

@azure/msal-browser

Version:
3 lines (2 loc) 6.46 kB
/*! @azure/msal-browser v5.7.0 2026-04-16 */ "use strict";!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).msalRedirectBridge={})}(this,(function(t){const e="common",r="organizations";class n extends Error{constructor(t,e,r){const o=e||(t?`See https://aka.ms/msal.js.errors#${t} for details`:"");super(o?`${t}: ${o}`:t),Object.setPrototypeOf(this,n.prototype),this.errorCode=t||"",this.errorMessage=o||"",this.subError=r||"",this.name="AuthError"}setCorrelationId(t){this.correlationId=t}}class o extends n{constructor(t){super(t),this.name="ClientConfigurationError",Object.setPrototypeOf(this,o.prototype)}}function s(t){return new o(t)}class i{static isEmptyObj(t){if(t)try{const e=JSON.parse(t);return 0===Object.keys(e).length}catch(t){}return!0}static startsWith(t,e){return 0===t.indexOf(e)}static endsWith(t,e){return t.length>=e.length&&t.lastIndexOf(e)===t.length-e.length}static queryStringToObject(t){const e={},r=t.split("&"),n=t=>decodeURIComponent(t.replace(/\+/g," "));return r.forEach((t=>{if(t.trim()){const[r,o]=t.split(/=(.+)/g,2);r&&o&&(e[n(r)]=n(o))}})),e}static trimArrayEntries(t){return t.map((t=>t.trim()))}static removeEmptyStringsFromArray(t){return t.filter((t=>!!t))}static jsonParseHelper(t){try{return JSON.parse(t)}catch(t){return null}}}class a extends n{constructor(t,e){super(t,e),this.name="ClientAuthError",Object.setPrototypeOf(this,a.prototype)}}function c(t,e){return new a(t,e)}const l="url_parse_error",u="invalid_state";class h{get urlString(){return this._urlString}constructor(t){if(this._urlString=t,!this._urlString)throw s("empty_url_error");t.includes("#")||(this._urlString=h.canonicalizeUri(t))}static canonicalizeUri(t){if(t){let e=t.toLowerCase();return i.endsWith(e,"?")?e=e.slice(0,-1):i.endsWith(e,"?/")&&(e=e.slice(0,-2)),i.endsWith(e,"/")||(e+="/"),e}return t}validateAsUri(){let t;try{t=this.getUrlComponents()}catch(t){throw s(l)}if(!t.HostNameAndPort||!t.PathSegments)throw s(l);if(!t.Protocol||"https:"!==t.Protocol.toLowerCase())throw s("authority_uri_insecure")}static appendQueryString(t,e){return e?t.indexOf("?")<0?`${t}?${e}`:`${t}&${e}`:t}static removeHashFromUrl(t){return h.canonicalizeUri(t.split("#")[0])}replaceTenantPath(t){const n=this.getUrlComponents(),o=n.PathSegments;return!t||0===o.length||o[0]!==e&&o[0]!==r||(o[0]=t),h.constructAuthorityUriFromObject(n)}getUrlComponents(){const t=RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"),e=this.urlString.match(t);if(!e)throw s(l);const r={Protocol:e[1],HostNameAndPort:e[4],AbsolutePath:e[5],QueryString:e[7]};let n=r.AbsolutePath.split("/");return n=n.filter((t=>t&&t.length>0)),r.PathSegments=n,r.QueryString&&r.QueryString.endsWith("/")&&(r.QueryString=r.QueryString.substring(0,r.QueryString.length-1)),r}static getDomainFromUrl(t){const e=RegExp("^([^:/?#]+://)?([^/?#]*)"),r=t.match(e);if(!r)throw s(l);return r[2]}static getAbsoluteUrl(t,e){if("/"===t[0]){const r=new h(e).getUrlComponents();return r.Protocol+"//"+r.HostNameAndPort+t}return t}static constructAuthorityUriFromObject(t){return new h(t.Protocol+"//"+t.HostNameAndPort+"/"+t.PathSegments.join("/"))}}const d="invalid_base64_string";class p extends n{constructor(t,e){super(t,`See https://aka.ms/msal.js.errors#${t} for details`,e),Object.setPrototypeOf(this,p.prototype),this.name="BrowserAuthError"}}function g(t,e){return new p(t,e)}const w="signout",f="request.origin",m="urlHash",y="interaction.status",S=865,b=961;var P;function _(t){return(new TextDecoder).decode(function(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw g(d)}const r=atob(e);return Uint8Array.from(r,(t=>t.codePointAt(0)||0))}(t))}function $(){const t=window.location.hash,e=window.location.search;let r,n=!1,o=!1,s="";if(t&&t.length>1){const e="#"===t.charAt(0)?t.substring(1):t,o=new URLSearchParams(e);o.has("state")&&(n=!0,s=e,r=o)}if(e&&e.length>1){const t="?"===e.charAt(0)?e.substring(1):e,n=new URLSearchParams(t);n.has("state")&&(o=!0,s=t,r=n)}if(n&&o){s=`${"?"===e.charAt(0)?e.substring(1):e}${"#"===t.charAt(0)?t.substring(1):t}`,r=new URLSearchParams(s)}if(!s||!r)throw g("empty_response");const i=r.get("state");if(!i)throw g("no_state_in_hash");const{libraryState:a}=function(t,e){if(!t)throw c("no_crypto_object");if(!e)throw c(u);try{const r=e.split("|"),n=r[0],o=r.length>1?r.slice(1).join("|"):"",s=t(n);return{userRequestState:o||"",libraryState:JSON.parse(s)}}catch(t){throw c(u)}}(_,i),{id:l,meta:h}=a;if(!l||!h)throw g("unable_to_parse_state","missing_library_state");return{params:r,payload:s,urlHash:t,urlQuery:e,hasResponseInHash:n,hasResponseInQuery:o,libraryState:{id:l,meta:h}}}!function(t){t.Redirect="redirect",t.Popup="popup",t.Silent="silent",t.None="none"}(P||(P={}));class A{navigateInternal(t,e){return A.defaultNavigateWindow(t,e)}navigateExternal(t,e){return A.defaultNavigateWindow(t,e)}static defaultNavigateWindow(t,e){return e.noHistory?window.location.replace(t):window.location.assign(t),new Promise(((t,r)=>{setTimeout((()=>{r(g("timed_out","failed_to_redirect"))}),e.timeout)}))}}const O="msal";t.broadcastResponseToMainFrame=async function(t){let e;try{e=$()}catch(t){throw"function"==typeof window.history.replaceState&&window.history.replaceState(null,"",`${window.location.origin}${window.location.pathname}`),t}const{payload:r,urlHash:n,urlQuery:o,hasResponseInHash:s,hasResponseInQuery:i,libraryState:a}=e,{id:c,meta:l}=a;if(l.interactionType===P.Redirect){const e=t||new A;let n="",o="",s="";const i=`${O}.${y}`;try{const t=window.sessionStorage.getItem(i),e=JSON.parse(t||"");if(o=e.clientId||"",s=e.type,o){const t=`${O}.${o}.${f}`;n=window.sessionStorage.getItem(t)||""}}catch{}const a={apiId:s===w?b:S,noHistory:!0,timeout:3e4};if(o)try{window.sessionStorage.setItem(`${O}.${o}.${m}`,r)}catch{}const c=n||function(){const t=new h(window.location.href).getUrlComponents();return`${t.Protocol}//${t.HostNameAndPort}/`}(),l=c.endsWith("?")?c.slice(0,-1):c;return void await e.navigateInternal(l,a)}if("function"==typeof window.history.replaceState){let t=`${window.location.origin}${window.location.pathname}`;!s&&n&&(t+=n),!i&&o&&(t+=o),window.history.replaceState(null,"",t)}const u=new BroadcastChannel(c);u.postMessage({v:1,payload:r}),u.close();try{window.close()}catch{}}}));