UNPKG

@azure/msal-browser

Version:
3 lines (2 loc) • 7.02 kB
/*! @azure/msal-browser v5.30.0 2026-11-18 */ "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 o extends Error{constructor(t,e,r,n){const s=r||(t?`See https://aka.ms/msal.js.errors#${t} for details`:"");super(s?`${t}: ${s}`:t),Object.setPrototypeOf(this,o.prototype),this.errorCode=t||"",this.errorMessage=s||"",this.subError=n||"",this.correlationId=e,this.name="AuthError"}}class n extends o{constructor(t,e,r){super(t,e,r),this.name="ClientAuthError",Object.setPrototypeOf(this,n.prototype)}}function s(t,e,r){return new n(t,e,r)}const i="invalid_state";class a extends o{constructor(t,e){super(t,e),this.name="ClientConfigurationError",Object.setPrototypeOf(this,a.prototype)}}function c(t,e){return new a(t,e)}const l="url_parse_error";class h{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("&"),o=t=>decodeURIComponent(t.replace(/\+/g," "));return r.forEach(t=>{if(t.trim()){const[r,n]=t.split(/=(.+)/g,2);r&&n&&(e[o(r)]=o(n))}}),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}}}const u=/[\x00-\x20\x7f\\@]/,d={"https:":":443","http:":":80"};class p{get urlString(){return this._urlString}constructor(t,e){if(this._urlString=t,this.correlationId=e,!this._urlString)throw c("empty_url_error",e);t.includes("#")||(this._urlString=p.canonicalizeUri(t))}static canonicalizeUri(t){if(t){let e=t.toLowerCase();return h.endsWith(e,"?")?e=e.slice(0,-1):h.endsWith(e,"?/")&&(e=e.slice(0,-2)),h.endsWith(e,"/")||(e+="/"),e}return t}validateAsUri(){let t;try{t=this.getUrlComponents()}catch(t){throw c(l,this.correlationId)}if(!t.HostNameAndPort||!t.PathSegments)throw c(l,this.correlationId);if(!t.Protocol||"https:"!==t.Protocol.toLowerCase())throw c("authority_uri_insecure",this.correlationId)}static appendQueryString(t,e){return e?t.indexOf("?")<0?`${t}?${e}`:`${t}&${e}`:t}static removeHashFromUrl(t){return p.canonicalizeUri(t.split("#")[0])}replaceTenantPath(t){const o=this.getUrlComponents(),n=o.PathSegments;return!t||0===n.length||n[0]!==e&&n[0]!==r||(n[0]=t),p.constructAuthorityUriFromObject(o,this.correlationId)}getUrlComponents(){const t=RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"),e=this.urlString.match(t);if(!e)throw c(l,this.correlationId);const r={Protocol:e[1],HostNameAndPort:e[4],AbsolutePath:e[5],QueryString:e[7]};let o;try{o=new URL(this.urlString)}catch{throw c(l,this.correlationId)}const n=r.HostNameAndPort?.toLowerCase(),s=`${r.Protocol}//${n}`,i=d[o.protocol]??"",a=n===o.host||n===`${o.host}${i}`||n?.startsWith("[")&&new URL(`${r.Protocol}//${n}`).host===o.host;if(u.test(s)||!a)throw c(l,this.correlationId);let h=r.AbsolutePath.split("/");return h=h.filter(t=>t&&t.length>0),r.PathSegments=h,r.QueryString&&r.QueryString.endsWith("/")&&(r.QueryString=r.QueryString.substring(0,r.QueryString.length-1)),r}static getDomainFromUrl(t,e){const r=RegExp("^([^:/?#]+://)?([^/?#]*)"),o=t.match(r);if(!o)throw c(l,e);return o[2]}static getAbsoluteUrl(t,e,r){if("/"===t[0]){const o=new p(e,r).getUrlComponents();return o.Protocol+"//"+o.HostNameAndPort+t}return t}static constructAuthorityUriFromObject(t,e){return new p(t.Protocol+"//"+t.HostNameAndPort+"/"+t.PathSegments.join("/"),e)}}const g="invalid_base64_string";class f extends o{constructor(t,e,r){super(t,e,`See https://aka.ms/msal.js.errors#${t} for details`,r),Object.setPrototypeOf(this,f.prototype),this.name="BrowserAuthError"}}function m(t,e,r){return new f(t,e,r)}function w(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 m(g,"")}const r=atob(e);return Uint8Array.from(r,t=>t.codePointAt(0)||0)}(t))}const y="signout",S="request.origin",b="urlHash",P="interaction.status",$=865,_=961;var A;function I(){const t=window.location.hash,e=window.location.search;let r,o=!1,n=!1,a="";if(t&&t.length>1){const e="#"===t.charAt(0)?t.substring(1):t,n=new URLSearchParams(e);n.has("state")&&(o=!0,a=e,r=n)}if(e&&e.length>1){const t="?"===e.charAt(0)?e.substring(1):e,o=new URLSearchParams(t);o.has("state")&&(n=!0,a=t,r=o)}if(o&&n){a=`${"?"===e.charAt(0)?e.substring(1):e}${"#"===t.charAt(0)?t.substring(1):t}`,r=new URLSearchParams(a)}if(!a||!r)throw m("empty_response","");const c=r.get("state");if(!c)throw m("no_state_in_hash","");const{libraryState:l}=function(t,e,r){if(!t)throw s("no_crypto_object",r);if(!e)throw s(i,r);try{const r=e.split("|"),o=r[0],n=r.length>1?r.slice(1).join("|"):"",s=t(o);return{userRequestState:n||"",libraryState:JSON.parse(s)}}catch(t){throw s(i,r)}}(w,c,""),{id:h,meta:u}=l;if(!h||!u)throw m("unable_to_parse_state","","missing_library_state");return{params:r,payload:a,urlHash:t,urlQuery:e,hasResponseInHash:o,hasResponseInQuery:n,libraryState:{id:h,meta:u}}}!function(t){t.Redirect="redirect",t.Popup="popup",t.Silent="silent",t.None="none"}(A||(A={}));class U{navigateInternal(t,e){return U.defaultNavigateWindow(t,e)}navigateExternal(t,e){return U.defaultNavigateWindow(t,e)}static defaultNavigateWindow(t,e){return e.noHistory?window.location.replace(t):window.location.assign(t),new Promise((t,r)=>{setTimeout(()=>{r(m("timed_out","","failed_to_redirect"))},e.timeout)})}}const O="msal";t.broadcastResponseToMainFrame=async function(t){let e;document.title="Microsoft Authentication";try{e=I()}catch(t){throw r=window,"function"==typeof r.history?.replaceState&&r.history.replaceState(null,"",`${r.location.origin}${r.location.pathname}`),t}var r;const{payload:o,urlHash:n,urlQuery:s,hasResponseInHash:i,hasResponseInQuery:a,libraryState:c}=e,{id:l,meta:h}=c;if(h.interactionType===A.Redirect){const e=t||new U;let r="",n="",s="";const i=`${O}.${P}`;try{const t=window.sessionStorage.getItem(i),e=JSON.parse(t||"");if(n=e.clientId||"",s=e.type,n){const t=`${O}.${n}.${S}`;r=window.sessionStorage.getItem(t)||""}}catch{}const a={apiId:s===y?_:$,noHistory:!0,timeout:3e4};if(n)try{window.sessionStorage.setItem(`${O}.${n}.${b}`,o)}catch{}const c=r||function(){const t=new p(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}`;!i&&n&&(t+=n),!a&&s&&(t+=s),window.history.replaceState(null,"",t)}const u=new BroadcastChannel(l);u.postMessage({v:1,payload:o}),u.close();try{window.close()}catch{}}});