@openpass/openpass-js-sdk
Advanced tools
Comparing version 4.5.6-pre-release to 4.6.0
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.openpass=t():e.openpass=t()}(self,(()=>(()=>{"use strict";var e={d:(t,i)=>{for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.d(t,{default:()=>ie});var i={};e.r(i),e.d(i,{AuthError:()=>s,OpenPassClient:()=>X,SdkError:()=>n});class n extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}class s extends n{constructor(e,t,i,n){super(t||e),this.error=e,this.errorDescription=t,this.errorUri=i,this.clientState=n}}class o extends n{constructor(e){super(e)}}function r(e,t,i){const n=e.split("."),s=n.pop();if(void 0===s)throw Error("Function name not provided");for(let e=0;e<n.length;e++)t=t[n[e]];const o=t[s];if(void 0===o)throw Error(`Function '${s}' not found`);return o.apply(t,i)}function a(e){return e.map((e=>{const t=e.endsWith("/")?e.substring(0,e.length-1):e;return t.startsWith("/")?t.substring(1):t})).join("/")}const d="openpass-js-sdk",p="OpenPass-SDK-Name",l="OpenPass-SDK-Version",c="state",h="S256",u="https://auth.myopenpass.com",g="/v1/api/authorize",w=e=>e||u,m=async(e,t)=>{if(t.timeout)return await b(e,t);const i=await fetch(e,t);return{status:i.status,json:await f(i)}},b=async(e,t)=>{let i;try{const n=new AbortController;i=setTimeout((()=>n.abort()),t.timeout);const s=await fetch(e,{...t,signal:n.signal});return{status:s.status,json:await f(s)}}finally{i&&clearTimeout(i)}},v=e=>{const t=[];return Object.keys(e).forEach((i=>{if(e[i]){const n=encodeURIComponent(i),s=encodeURIComponent(e[i]);t.push(n+"="+s)}})),t.length>0?t.join("&"):""},f=async e=>{var t;return(null===(t=e.headers.get("content-type"))||void 0===t?void 0:t.toLowerCase().includes("application/json"))?await e.json():null},k="invalid_redirect";function I(e){this.message=e}I.prototype=new Error,I.prototype.name="InvalidCharacterError";var y="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new I("'atob' failed: The string to be decoded is not correctly encoded.");for(var i,n,s=0,o=0,r="";n=t.charAt(o++);~n&&(i=s%4?64*i+n:n,s++%4)?r+=String.fromCharCode(255&i>>(-2*s&6)):0)n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return r};function _(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(y(e).replace(/(.)/g,(function(e,t){var i=t.charCodeAt(0).toString(16).toUpperCase();return i.length<2&&(i="0"+i),"%"+i})))}(t)}catch(e){return y(t)}}function x(e){this.message=e}x.prototype=new Error,x.prototype.name="InvalidTokenError";const P=e=>function(e,t){if("string"!=typeof e)throw new x("Invalid token specified");var i=!0===(t=t||{}).header?0:1;try{return JSON.parse(_(e.split(".")[i]))}catch(e){throw new x("Invalid token specified: "+e.message)}}(e),A=JSON.parse('{"i8":"4.5.6-pre-release"}');class S{constructor(e){this.options=e,this.validateOptions(e)}async exchangeAuthCodeForTokens(e,t){var i,n,o;const r={grant_type:"authorization_code",client_id:t.clientId,redirect_uri:t.redirectUrl,code:e,code_verifier:t.codeVerifier},a={};a[p]=d,a[l]=A.i8,a["Content-Type"]="application/x-www-form-urlencoded; charset=UTF-8";const c=(await m(this.resolveUri("/v1/api/token"),{method:"POST",headers:a,body:v(r),timeout:6e4})).json;if(this.isErrorResponse(c))throw new s(null!==(i=c.error)&&void 0!==i?i:"token_oidc_id_request_failed",null!==(n=c.error_description)&&void 0!==n?n:"Error retrieving token",null!==(o=c.error_uri)&&void 0!==o?o:"",t.clientState);const h=c.id_token,u=P(h);if(!u)throw new s("decode_jwt","Unable to decode jwt","",t.clientState);const g=c.access_token,w=c.refresh_token;if(!g)throw new s("no_access_token","No access token was returned","",t.clientState);return{idToken:u,rawIdToken:h,accessToken:g,refreshToken:w,rawAccessToken:g,tokenType:c.token_type,expiresIn:c.expires_in}}async authorizeDevice(e,t,i){var n,o,r;const a={scope:"openid",client_id:e};t&&(a.login_hint=t),i&&(a.disable_login_hint_editing=i);const c={};c[p]=d,c[l]=A.i8,c["Content-Type"]="application/x-www-form-urlencoded; charset=UTF-8";const h=(await m(this.resolveUri("/v1/api/authorize-device"),{method:"POST",headers:c,body:v(a),timeout:6e4})).json;if(this.isErrorResponse(h))throw new s(null!==(n=h.error)&&void 0!==n?n:"authorize_device_request_failed",null!==(o=h.error_description)&&void 0!==o?o:"Error authorizing device",null!==(r=h.error_uri)&&void 0!==r?r:"");return h}async deviceToken(e,t){var i,n,o;const r={client_id:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code",device_code:t},a={};a[p]=d,a[l]=A.i8,a["Content-Type"]="application/x-www-form-urlencoded; charset=UTF-8";const c=(await m(this.resolveUri("/v1/api/device-token"),{method:"POST",headers:a,body:v(r),timeout:6e4})).json;if(this.isErrorResponse(c)){if("authorization_pending"===c.error)return{status:"authorization_pending"};if("slow_down"===c.error)return{status:"slow_down"};throw new s(null!==(i=c.error)&&void 0!==i?i:"device_token_request_failed",null!==(n=c.error_description)&&void 0!==n?n:"Error getting device token",null!==(o=c.error_uri)&&void 0!==o?o:"")}return{status:"ok",tokensResponse:c}}async sendTelemetryEvent(e){const t={};t[p]=d,t[l]=A.i8,t["Content-Type"]="application/json";const i={client_id:this.options.clientId,event_type:e};await m(this.resolveUri("/v1/api/telemetry/event"),{method:"POST",headers:t,body:JSON.stringify(i)})}resolveUri(e){return a([this.options.baseUrl||u,e])}isErrorResponse(e){return void 0!==e.error}validateOptions(e){if(!e.clientId)throw new n("Error clientId is invalid. Please use a valid clientId")}}const C="__openpass__client_session";class O{constructor(e){this.signInStateStorage=e}add(e){this.signInStateStorage.set(C,JSON.stringify(e))}get(){const e=this.signInStateStorage.get(C,"");return e?JSON.parse(e):null}remove(){this.signInStateStorage.remove(C)}}class E{set(e,t){sessionStorage.setItem(e,t)}get(e,t){return sessionStorage.getItem(e)||t}remove(e){sessionStorage.removeItem(e)}}const U=e=>{const t=new URLSearchParams(e);return{code:j("code",t),state:j(c,t),error:j("error",t),errorDescription:j("error_description",t),errorUri:j("error_uri",t)}},T=(e,t,i,n,s)=>{const o=new URLSearchParams;if(o.set("response_type","code"),o.set("client_id",i.clientId),o.set("scope","openid"),o.set(c,i.state),o.set("sdk_name",d),o.set("sdk_version",A.i8),o.set("op_auth_session_source",n),i.redirectUrl&&o.set("redirect_uri",i.redirectUrl),i.codeChallengeMethod&&o.set("code_challenge_method",i.codeChallengeMethod),i.codeChallenge&&o.set("code_challenge",i.codeChallenge),i.responseMode&&o.set("response_mode",i.responseMode),i.loginHint&&o.set("login_hint",i.loginHint),i.consentJwt&&o.set("consent_jwt",i.consentJwt),i.disableLoginHintEditing&&o.set("disable_login_hint_editing",i.disableLoginHintEditing?"true":"false"),s)for(let e=0;e<s.length;e++){const t=s[e];q(t),o.set(t.name,t.value)}return`${a([e,t])}?${o.toString()}`},q=e=>{if(!e.name||!e.value)throw new n("Custom query parameters must have both name and value");if(e.name.length>100||e.value.length>100)throw new n("Custom query parameters' name and value must be under 100 characters");if(!/^[\x20-\x7E]*$/.test(e.name)||!/^[\x20-\x7E]*$/.test(e.value))throw new n("Custom query parameter contains invalid characters. Only printable ASCII characters are allowed")},j=(e,t)=>{const i=t.get(e);return i?decodeURIComponent(i):null},z=(e,t)=>e===t||!!(t.endsWith("/")&&t.length>1)&&e===t.substring(0,t.length-1);class R{constructor(e,t,i,n){this.isRedirectingForAuth=!1,this.openPassOptions=e,this.popupAuth=i,this.redirectAuth=t,this.apiClient=n}renderInlineSignInForm(e){var t;if(!e.parentContainerElementId)throw new n("inlineSignInOptions.parentContainerElementId is required for inline sign-in method.");e.signinButtonTextOption=null!==(t=e.signinButtonTextOption)&&void 0!==t?t:"continue";const i=document.getElementById(e.parentContainerElementId),s=e.authenticationMode,o=e.signinButtonBorderRadiusInPixels;if(!i)throw new n(`Cannot locate parent container element "${e.parentContainerElementId}" for inline sign-in form.`);if("popup"!=s&&"redirect"!=s)throw new n(`Invalid authentication mode: ${s}.`);if("popup"==s&&!e.popupSuccessCallback)throw new n("Must provide popupSuccessCallback for inline sign-in form when authentication mode is popup.");if(e.widthInPixels&&e.widthInPixels<250)throw new n("Inline sign-in form width must be at least 250 pixels.");if(e.heightInPixels&&e.heightInPixels<500)throw new n("Inline sign-in form width must be at least 500 pixels.");if(!["boolean","undefined"].includes(typeof e.darkModeEnabled))throw new n("Invalid darkModeEnabled value. Must be true or false.");if(void 0!==o){if(!/^[0-9]+$/.test(String(o)))throw new n("Invalid signinButtonBorderRadiusInPixels value. Must be an integer number greater than or equal to 0.");if(o>2147483647)throw new n("Invalid signinButtonBorderRadiusInPixels value. Must be less than or equal to 2147483647.")}const r=e.popupSuccessCallback,a=e.popupFailureCallback;window.addEventListener("message",(async t=>{var i;const o=w(this.openPassOptions.baseUrl);if(!z(t.origin,o)||!t.data||"inline-sign-in-message"!=t.data.type)return;const{data:p}=t,l={clientState:e.clientState,disableLoginHintEditing:!1,loginHint:p.loginHint,consentJwt:p.consentJwt,customQueryParameters:e.customQueryParameters};switch(s){case"popup":try{if(this.currentLoginHint===p.loginHint&&this.popupAuth.refocusIfPopupExists())break;this.currentLoginHint=p.loginHint;const t=await this.popupAuth.signInWithPopup({...l,redirectUrl:e.redirectUrl,source:"SignInWithOpenPassInlineForm"});r&&r(t)}catch(e){e instanceof n?a&&a(e):console.error(e)}break;case"redirect":if(this.isRedirectingForAuth)break;this.isRedirectingForAuth=!0;try{await this.redirectAuth.signIn({...l,redirectUrl:e.redirectUrl,source:"SignInWithOpenPassInlineForm"})}catch(e){null===(i=d.contentWindow)||void 0===i||i.postMessage({type:"openpass-redirect-sign-in-failure"},o),console.error(e)}finally{this.isRedirectingForAuth=!1}break;default:console.log("Invalid authentication mode: "+s)}}));const d=this.createIframeElement(this.openPassOptions.clientId,e);i.appendChild(d),this.apiClient.sendTelemetryEvent("SignInWithOpenPassInlineFormShown")}createIframeElement(e,t){var i,n,s,o,r,a;const d=document.createElement("iframe"),p=w(this.openPassOptions.baseUrl),l=new URL("/inline-sign-in",p);return l.searchParams.append("client_id",e),l.searchParams.append("submit_button_text",null!==(n=null===(i=t.signinButtonTextOption)||void 0===i?void 0:i.toString())&&void 0!==n?n:"continue"),l.searchParams.append("auth_mode",t.authenticationMode),t.hideSignInFormApplicationLogo&&l.searchParams.append("hide_client_application_logo",t.hideSignInFormApplicationLogo.toString()),t.hideSignInFormHeaderText&&l.searchParams.append("hide_header_text",t.hideSignInFormHeaderText.toString()),t.signinButtonBackgroundColorHex&&l.searchParams.append("sign_in_button_background_hex_colour",t.signinButtonBackgroundColorHex),void 0!==t.signinButtonBorderRadiusInPixels&&l.searchParams.append("sign_in_button_border_radius_px",String(t.signinButtonBorderRadiusInPixels)),t.darkModeEnabled&&l.searchParams.append("dark_mode_enabled",t.darkModeEnabled.toString()),d.src=l.toString(),d.width=null!==(o=null===(s=t.widthInPixels)||void 0===s?void 0:s.toString())&&void 0!==o?o:"100%",d.height=null!==(a=null===(r=t.heightInPixels)||void 0===r?void 0:r.toString())&&void 0!==a?a:"100%",d}}class F{constructor(e,t,i,s){this.quickAuthSignInOptions=null,this.isInitialized=!1,this.showInstantly=(e=!1)=>{var t;if(!this.isInitialized)throw new n("Quick Auth is not initialized. Call `render` first.");(e||!0!==this.isVisible)&&(this.isVisible=!0,this.quickAuthDialogIFrame.style.display="block",(null===(t=this.quickAuthSignInOptions)||void 0===t?void 0:t.visibilityChangedCallback)&&this.quickAuthSignInOptions.visibilityChangedCallback({visibility:"visible"}),this.apiClient.sendTelemetryEvent("SignInWithOpenPassQuickSignShown"))},this.hideInstantly=()=>{var e;if(!this.isInitialized)throw new n("Quick Auth is not initialized. Call `render` first.");!1!==this.isVisible&&(this.isVisible=!1,this.quickAuthDialogIFrame.style.display="none",(null===(e=this.quickAuthSignInOptions)||void 0===e?void 0:e.visibilityChangedCallback)&&this.quickAuthSignInOptions.visibilityChangedCallback({visibility:"hidden"}))},this.openPassOptions=e,this.popupAuth=i,this.redirectAuth=t,this.apiClient=s}render(e){this.quickAuthSignInOptions=e;const{redirectUrl:t,show:i,visibility:s,parentContainerElementId:o,authenticationMode:r,popupSuccessCallback:a}=e;if(void 0===s&&(this.quickAuthSignInOptions.visibility=void 0===i||!0===i?"displayOnInit":"hideOnInit"),!o)throw new n("parentContainerElementId is required for quick-auth sign-in method.");const d=document.getElementById(o);if(!d)throw new n(`Cannot locate parent container element "${o}" for quick-auth`);if(this.parentContainer=d,"popup"!==r&&"redirect"!==r)throw new n(`Invalid authentication mode: ${r}.`);if("popup"===r&&!a)throw new n("Must provide popupSuccessCallback for quick-auth when authentication mode is popup.");if("redirect"===r&&!t)throw new n("Must provide redirectUrl for quick-auth when authentication mode is redirect.");this.quickAuthDialogIFrame=this.createHiddenQuickAuthIframe(this.openPassOptions.clientId,this.parentContainer),window.addEventListener("message",(t=>this.messageHandler(t,e,this.quickAuthDialogIFrame))),this.parentContainer.appendChild(this.quickAuthDialogIFrame)}showWithDelay(){var e,t;if(!this.isInitialized)throw new n("Quick Auth is not initialized. Call `render` first.");if(!0===this.isVisible)return;this.isVisible=!0;const i=setTimeout((()=>{this.showInstantly(!0),clearTimeout(i)}),null!==(t=null===(e=this.quickAuthSignInOptions)||void 0===e?void 0:e.delayMs)&&void 0!==t?t:1e3)}messageHandler(e,t,i){if(z(e.origin,w(this.openPassOptions.baseUrl))&&e.data&&e.data.type)switch(e.data.type){case"openpass-quick-auth-initialized-message":this.handleInitializedMessage(e,t);break;case"openpass-quick-auth-continue-button-message":this.handleContinueButtonMessage(e,t);break;case"openpass-quick-auth-close-button-message":this.handleCloseButtonMessage(i)}}handleInitializedMessage(e,t){const{data:{hasSession:i,popupWidth:n,popupHeight:s}}=e;switch(this.setupQuickAuthIframeHeight({width:n,height:s}),this.isInitialized=!0,t.visibility){case"displayOnInit":this.showWithDelay();break;case"displayOnInitIfSessionActive":i?this.showWithDelay():this.hideInstantly();break;case"hideOnInit":this.hideInstantly()}}async handleContinueButtonMessage(e,t){const{data:i}=e,s=t.popupSuccessCallback,o=t.popupFailureCallback,r=t.authenticationMode,a={clientState:t.clientState,disableLoginHintEditing:!1,loginHint:i.loginHint,consentJwt:i.consentJwt,customQueryParameters:t.customQueryParameters};switch(r){case"popup":try{if(this.popupAuth.refocusIfPopupExists())break;const e=await this.popupAuth.signInWithPopup({...a,redirectUrl:t.redirectUrl,source:"SignInWithOpenPassQuickAuth"});s&&(this.hideInstantly(),s(e))}catch(e){e instanceof n?o&&o(e):console.error(e)}break;case"redirect":this.redirectAuth.signIn({...a,redirectUrl:t.redirectUrl,source:"SignInWithOpenPassQuickAuth"});break;default:console.error("Invalid authentication mode: "+r)}}handleCloseButtonMessage(e){this.hideInstantly(),this.apiClient.sendTelemetryEvent("SignInWithOpenPassQuickSignDismissed")}createHiddenQuickAuthIframe(e,t){const i=document.createElement("iframe"),n=w(this.openPassOptions.baseUrl),s=new URL("/quick-auth",n);return s.searchParams.append("client_id",e),t.style.zIndex="9999",i.src=s.toString(),i.width="100%",i.style.display="none",i.style.border="none",i.style.overflow="hidden",window.innerWidth>640?(t.style.position="fixed",t.style.top="120px",t.style.right="20px"):(t.style.width="100%",t.style.position="fixed",t.style.bottom="0px",t.style.left="0px"),i}setupQuickAuthIframeHeight({width:e,height:t}){if(!this.quickAuthDialogIFrame||!this.parentContainer)throw new n("Quick Auth is not rendered. Call `render` first.");this.quickAuthDialogIFrame.height=`${t}px`,this.parentContainer.style.height=`${t}px`,this.quickAuthDialogIFrame.style.minWidth=`${e}px`}}const M=()=>window.crypto||window.msCrypto,L=(e=43)=>{const t=new Uint32Array(e);return M().getRandomValues(t),Array.from(t,(e=>`0${e.toString(16)}`.slice(-2))).join("")},H=(e=43)=>L(e),$=async e=>{const t=await(async e=>{const t=(new TextEncoder).encode(e);return await(()=>{const e=M();return e.subtle||e.webkitSubtle})().digest("SHA-256",t)})(e);return n=t,i=String.fromCharCode.apply(null,new Uint8Array(n)),btoa(i).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");var i,n},B=(e=16)=>L(e);class W{constructor(e,t,i){this.openPassOptions=e,this.openPassApiClient=i,this.signInStateRepository=t}async signIn(e){var t;if(!e.redirectUrl)throw new n("Error redirectUrl is invalid. Please use a valid redirectUrl");const i=H(),s={clientState:e.clientState,clientId:this.openPassOptions.clientId,redirectUrl:e.redirectUrl,codeVerifier:i,codeChallenge:await $(i),codeChallengeMethod:h,state:B(),loginHint:e.loginHint,consentJwt:e.consentJwt,disableLoginHintEditing:e.disableLoginHintEditing,originatingUri:null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.href};this.signInStateRepository.add(s);const o=T(w(this.openPassOptions.baseUrl),g,s,e.source,e.customQueryParameters);window.location.href=o}isAuthenticationRedirect(){const e=this.signInStateRepository.get();return e?((e,t,i)=>{if(!e||!i)return!1;const n=-1!=e.toLowerCase().indexOf(i.toLowerCase()),s=null!==t.state&&null!==t.code,o=null!==t.error||null!==t.errorDescription;return n&&(s||o)})(window.location.href,U(window.location.search),e.redirectUrl):(console.warn("Unable to authenticate, a login session may not have being started. Possibly a call to login is required"),!1)}async handleAuthenticationRedirect(){const e=this.signInStateRepository.get();if(!e)throw new s("invalid_auth_session","Unable to authenticate, a login session may not have being started. Possibly a call to login is required","");try{if(!this.isAuthenticationRedirect())throw new s(k,"Unable to validate the redirect response","",e.clientState);const t=U(window.location.search);if(!this.isRedirectUrlValid(e,t)||!t.code)throw new s(t.error?t.error:k,t.errorDescription?t.errorDescription:"Unable to validate the redirect response",t.errorUri?t.errorUri:"",e.clientState);const i=await this.openPassApiClient.exchangeAuthCodeForTokens(t.code,e),{idToken:n,rawIdToken:o,accessToken:r,refreshToken:a,tokenType:d,expiresIn:p}=i;return{clientState:e.clientState,originatingUri:e.originatingUri,idToken:n,rawIdToken:o,accessToken:r,rawAccessToken:r,refreshToken:a,tokenType:d,expiresIn:p}}finally{this.signInStateRepository.remove()}}isRedirectUrlValid(e,t){return!!e&&(!(!t.code||!t.state)&&e.state===t.state)}}const N=(e,t,i,n)=>{const s=(window.outerWidth-i)/2+window.screenX,o=`scrollbars=yes,resizable=yes,toolbar=no,top=${(window.outerHeight-n)/2+window.screenY},left=${s},width=${i},height=${n}`;return window.open(e,t,o)};class D extends Promise{constructor(e){let t;super(((i,n)=>e(i,n,(e=>t=e)))),this.onAbort=t}abort(){this.onAbort&&this.onAbort()}}const V="openpass:popup:login";class Q{constructor(e,t,i){this.openPassOptions=e,this.openPassClient=i,this.redirectApi=t}refocusIfPopupExists(){return!(!this.popupWindow||this.popupWindow.window.closed||(this.popupWindow.window.focus(),0))}async signInWithPopup(e){let t;this.closePopupIfExists(this.popupWindow);let i=null;try{t=this.openPopup()}catch(e){t=null,i=null==e?void 0:e.message}if(!t){if(e.redirectUrl)throw this.redirectApi.signIn({...e,redirectUrl:e.redirectUrl}),new n("Using redirect instead of popup. This error should not be thrown because the redirect happens first.");let t="Popup window did not open correctly.";throw i&&(t+=` Error: ${i}`),new n(t)}const s={window:t};return this.popupWindow=s,this.doLogin(s,e)}async doLogin(e,t){var i;const n=()=>{this.closePopupIfExists(e)};window.addEventListener("beforeunload",n);try{const n=H(),s={clientState:null==t?void 0:t.clientState,clientId:this.openPassOptions.clientId,redirectUrl:null==t?void 0:t.redirectUrl,codeVerifier:n,codeChallenge:await $(n),codeChallengeMethod:h,state:B(),responseMode:"post_message",loginHint:null==t?void 0:t.loginHint,consentJwt:null==t?void 0:t.consentJwt,disableLoginHintEditing:null==t?void 0:t.disableLoginHintEditing,originatingUri:null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.href},o=t?t.source:"Custom",r=T(w(this.openPassOptions.baseUrl),g,s,o,null==t?void 0:t.customQueryParameters);return e.window.location.replace(r),await this.waitForPopupResponse(e,s)}catch(t){throw t instanceof o||this.closePopupIfExists(e),t}finally{window.removeEventListener("beforeunload",n)}}async waitForPopupResponse(e,t){const i=await this.listenForPopupResponse(e);if(!this.isAuthCodeValid(i,t)||!i.code)throw new s(i.error?i.error:"invalid_redirect",i.errorDescription?i.errorDescription:"Error, invalid authorization code response",i.errorUri?i.errorUri:"",t.clientState);const n=await this.openPassClient.exchangeAuthCodeForTokens(i.code,t);return await this.completeAuthentication(e,n,t)}async completeAuthentication(e,t,i){const{idToken:s,rawIdToken:o,rawAccessToken:r,refreshToken:a,expiresIn:d,tokenType:p}=t;return new Promise(((t,l)=>{setTimeout((()=>{l(new n("No Response received from popup"))}),1e4),(async()=>{try{this.closePopupIfExists(e),t({clientState:i.clientState,originatingUri:i.originatingUri,idToken:s,rawIdToken:o,accessToken:r,rawAccessToken:r,refreshToken:a,expiresIn:d,tokenType:p})}catch(t){this.closePopupIfExists(e),l(t)}})()}))}async listenForPopupResponse(e){let t,i,s;const r=new D(((r,a,d)=>{t=setInterval((()=>{e.window&&e.window.closed&&(clearInterval(t),window.removeEventListener("message",s),this.closePopupIfExists(e),a(new n("Popup closed, authentication response not available")))}),100),s=e=>{if(!z(e.origin,w(this.openPassOptions.baseUrl))||!e.data)return;const{data:t}=e;t.source&&"openpass-authorize-message"===t.source&&r(t)},window.addEventListener("message",s,!1),i=setInterval((()=>{clearInterval(i),a(new n("No Response received from popup"))}),6e5),d((()=>{clearInterval(t),clearTimeout(i),window.removeEventListener("message",s),a(new o("Popup window was closed"))}))}));return e.listener=r,r.finally((()=>{clearInterval(t),clearTimeout(i),window.removeEventListener("message",s)}))}openPopup(){return"undefined"!=typeof window&&"undefined"!=typeof document&&void 0!==typeof window.postMessage&&null!==window.postMessage?window.matchMedia("screen and (min-width:960px)").matches?N("",V,428,586):((e,t,i)=>{{const e=`scrollbars=yes,resizable=yes,toolbar=no,top=${window.screenY},left=${window.screenX},width=${window.outerWidth},height=${window.outerHeight}`;return window.open("",t,e)}})(0,V):null}isAuthCodeValid(e,t){return!(!e.code||!e.state)&&t.state===e.state}closePopupIfExists(e){if(e){if(e.window&&!e.window.closed)try{e.window.close()}catch(e){console.warn("Error closing the openpass popup window",e)}if(e.listener)try{e.listener.abort(),e.listener=void 0}catch(e){console.warn("Error aborting the openpass popup listener",e)}e==this.popupWindow&&(this.popupWindow=void 0)}}}const J=e=>{switch(e){case"x-large":return 22;case"large":return 18;case"medium":return 14;case"small":return 10}},Z="openpass-sign-in-button-stylesheet";class G{constructor(e,t,i){this.popupAuth=t,this.redirectAuth=e,this.apiClient=i}renderSignInButton(e){if(!e.parentContainerElementId)throw new n("No parent container element id provided for OpenPass sign-in button");if(e.authenticationMode&&"redirect"!==e.authenticationMode&&"popup"!==e.authenticationMode)throw new n("Invalid authentication mode provided for OpenPass sign-in button, please choose either 'redirect' or 'popup'");if("redirect"==e.authenticationMode&&!e.redirectUrl)throw new n("No redirect url provided for OpenPass sign-in button");if("popup"==e.authenticationMode&&!e.popupSuccessCallback)throw new n("No popup success callback provided for OpenPass sign-in button");if(e.shape&&"standard"!==e.shape&&"icon"!==e.shape)throw new n("Invalid shape provided for OpenPass sign-in button, please choose either 'standard' or 'icon'");if(e.shapeVariant&&"pill"!==e.shapeVariant&&"rectangle"!==e.shapeVariant&&"circle"!==e.shapeVariant&&"square"!==e.shapeVariant)throw new n("Invalid shape variant provided for OpenPass sign-in button, please choose either 'pill', 'rectangle', 'circle' or 'square'");if("standard"==e.shape&&void 0!==e.shapeVariant&&"pill"!==e.shapeVariant&&"rectangle"!==e.shapeVariant)throw new n("Invalid shape variant provided for OpenPass sign-in button, please choose either 'pill' or 'rectangle'");if("icon"==e.shape&&void 0!==e.shapeVariant&&"circle"!==e.shapeVariant&&"square"!==e.shapeVariant)throw new n("Invalid shape variant provided for OpenPass sign-in button, please choose either 'circle' or 'square'");if(e.additionalWidth&&e.additionalWidth<0)throw new n("Invalid width override provided for OpenPass sign-in button, please provide a positive number");if(e.size&&"x-large"!==e.size&&"large"!==e.size&&"medium"!==e.size&&"small"!==e.size)throw new n("Invalid size provided for OpenPass sign-in button, please choose either 'x-large', 'large', 'medium' or 'small'");if(e.theme&&"openpass"!==e.theme&&"light"!==e.theme&&"dark"!==e.theme)throw new n("Invalid theme provided for OpenPass sign-in button, please choose either 'openpass', 'light' or 'dark'");if(e.text&&"signin"!==e.text&&"signin_with"!==e.text&&"continue_with"!==e.text)throw new n("Invalid text type provided for OpenPass sign-in button, please choose either 'signin', 'signin_with' or 'continue_with'");const t=document.getElementById(e.parentContainerElementId);if(!t)throw new n(`No button container found with id '${e.parentContainerElementId}' for OpenPass sign-in button`);var i;i=Z,null===document.querySelector(`style[id=${i}]`)&&((e,t)=>{const i=document.createElement("style");i.innerHTML=e,i.id=t,document.getElementsByTagName("head")[0].appendChild(i)})("\n .op-js-sdk-siwopb__root {\n border: none;\n cursor: pointer;\n display: flex;\n font-family: Poppins, sans-serif;\n text-align: center;\n align-items: center;\n justify-content: center;\n vertical-align: middle;\n }\n \n .op-js-sdk-siwopb__inner {\n display: flex;\n align-items: center;\n }\n \n .op-js-sdk-siwopb__inner > svg {\n flex-shrink: 0;\n }\n\n .op-js-sdk-siwopb__theme-openpass {\n background-color: #012359;\n color: #FFFFFF;\n }\n\n .op-js-sdk-siwopb__theme-light {\n background-color: #FFFFFF;\n color: #3C4043;\n\n border-style: solid;\n border-color: #DADCE0;\n border-width: 1px;\n }\n\n .op-js-sdk-siwopb__theme-dark {\n background-color: #202124;\n color: #FFFFFF;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-x-large {\n font-weight: 400;\n font-size: 16px;\n \n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 16px;\n padding-right: 16px;\n\n height: 48px;\n min-height: 48px;\n max-height: 48px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-pill-x-large {\n border-radius: 100px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-rectangle-x-large {\n border-radius: 4px;\n }\n \n .op-js-sdk-siwopb__size-shape-standard-large {\n font-weight: 400;\n font-size: 14px;\n \n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 12px;\n padding-right: 12px;\n\n height: 40px;\n min-height: 40px;\n max-height: 40px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-pill-large {\n border-radius: 20px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-rectangle-large {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-medium {\n font-weight: 400;\n font-size: 12px;\n\n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 12px;\n padding-right: 12px;\n \n height: 32px;\n min-height: 32px;\n max-height: 32px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-pill-medium {\n border-radius: 16px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-rectangle-medium {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-small {\n font-weight: 300;\n font-size: 11px;\n\n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 8px;\n padding-right: 8px;\n \n height: 20px;\n min-height: 20px;\n max-height: 20px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-pill-small {\n border-radius: 10px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-rectangle-small {\n border-radius: 4px;\n }\n\n\n .op-js-sdk-siwopb__size-shape-icon-x-large {\n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 12px;\n padding-right: 12px;\n\n height: 48px;\n min-height: 48px;\n max-height: 48px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-square-x-large {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-circle-x-large {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-large {\n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 10px;\n padding-right: 10px;\n\n height: 40px;\n min-height: 40px;\n max-height: 40px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-square-large {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-circle-large {\n border-radius: 20px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-medium {\n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 8px;\n padding-right: 8px;\n\n height: 32px;\n min-height: 32px;\n max-height: 32px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-square-medium {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-circle-medium {\n border-radius: 16px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-small {\n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 4px;\n padding-right: 4px;\n \n height: 20px;\n min-height: 20px;\n max-height: 20px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-square-small {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-circle-small {\n border-radius: 10px;\n }\n\n .op-js-sdk-siwopb__logo-x-large {\n height: 22px;\n width: 22px;\n }\n\n .op-js-sdk-siwopb__logo-large {\n height: 18px;\n width: 18px;\n }\n\n .op-js-sdk-siwopb__logo-medium {\n height: 14px;\n width: 14px;\n }\n\n .op-js-sdk-siwopb__logo-small {\n height: 10px;\n width: 10px;\n }\n\n .op-js-sdk-siwopb__logo-shape-standard-x-large {\n margin-right: 10px;\n }\n\n .op-js-sdk-siwopb__logo-shape-standard-large {\n margin-right: 10px;\n }\n\n .op-js-sdk-siwopb__logo-shape-standard-medium {\n margin-right: 10px;\n }\n\n .op-js-sdk-siwopb__logo-shape-standard-small {\n margin-right: 10px;\n }\n\n .op-js-sdk-siwopb__logo-shape-icon-x-large {\n margin-left: auto;\n margin-right: auto;\n vertical-align: middle;\n }\n\n .op-js-sdk-siwopb__logo-shape-icon-large {\n margin-left: auto;\n margin-right: auto;\n vertical-align: middle;\n }\n\n .op-js-sdk-siwopb__logo-shape-icon-medium {\n margin-left: auto;\n margin-right: auto;\n vertical-align: middle;\n }\n\n .op-js-sdk-siwopb__logo-shape-icon-small {\n margin-left: auto;\n margin-right: auto;\n vertical-align: middle;\n }\n ",Z),(e=>{const t=document.getElementsByTagName("head")[0].getElementsByTagName("link");for(let e=0;e<t.length;e++)if(t[e].href.includes("Poppins"))return!0;return!1})()||(e=>{const t=document.createElement("link");t.href="https://fonts.googleapis.com/css?family=Poppins",t.rel="stylesheet",document.getElementsByTagName("head")[0].appendChild(t)})();const s=(e=>{var t,i,n,s,o;const r=null!==(t=e.text)&&void 0!==t?t:"signin_with",a=null!==(i=e.size)&&void 0!==i?i:"large",d=null!==(n=e.theme)&&void 0!==n?n:"openpass",p=null!==(s=e.shape)&&void 0!==s?s:"standard",l=null!==(o=e.shapeVariant)&&void 0!==o?o:"pill",c=document.createElement("button");c.setAttribute("type","button"),c.setAttribute("aria-label","Sign in with OpenPass Button"),c.classList.add("op-js-sdk-siwopb__root"),c.classList.add(`op-js-sdk-siwopb__size-shape-${p}-${a}`),c.classList.add(`op-js-sdk-siwopb__size-shape-${p}-${l}-${a}`),c.classList.add(`op-js-sdk-siwopb__theme-${d}`);const h=document.createElement("div");if(h.classList.add("op-js-sdk-siwopb__inner"),c.appendChild(h),e.additionalWidth&&e.additionalWidth>0){const t=e.additionalWidth/2;h.style.marginLeft=`${t}px`,h.style.marginRight=`${t}px`}const u="light"===d?(e=>{const t=J(e),i=document.createElementNS("http://www.w3.org/2000/svg","svg");return i.setAttribute("role","img"),i.setAttribute("title","OpenPass Logo"),i.setAttribute("fill","none"),i.setAttribute("width",`${t}`),i.setAttribute("height",`${t}`),i.setAttribute("viewBox","5 4 40 40"),i.setAttribute("xmlns","http://www.w3.org/2000/svg"),i.innerHTML='\n<path d="M21.97 44c.95 0 1.87-.09 2.78-.26l.37-.08.12-.03.23-.05.19-.05.15-.04.23-.06.11-.03.24-.07.1-.03.25-.08c.03 0 .05-.02.08-.03a4.7 4.7 0 0 0 .33-.12l.28-.1h.02a17.05 17.05 0 0 0 1.51-.7h.02l.27-.14.03-.01.26-.15a.21.21 0 0 0 .05-.03l.23-.14a.2.2 0 0 0 .06-.04l.24-.14.03-.02c.37-.24.74-.5 1.09-.76l.24-.18.02-.02.22-.18c.02 0 .03-.03.05-.04l.2-.17.07-.05.2-.18.05-.04c.41-.37.8-.77 1.2-1.18a23.3 23.3 0 0 0 2.63-3.61c-.02.02.01-.02 0 0-.02.03 0 .02 0 0 .22-.39.41-.77.6-1.17l.54-1.23c-.01.01 0 0 0 0 1.1-2.7 1.58-5.65 1.58-8.56 0-7.58-5.53-15.41-14.35-13.13 5.05 1.45 8.8 6.77 8.8 13.13 0 6.35-3.74 11.7-8.8 13.15-8.13 1.57-14.32-4.59-14.32-13.47 0-5.73 1.81-11.28 6.19-15.13.5-.4.95-.85 1.47-1.24l.23-.17.08-.06.17-.11.03-.02.12-.08.13-.09.04-.03.15-.1.1-.07.2-.12.34-.2.32-.19c.03 0 .05-.03.08-.04.05-.01.09-.04.14-.06l.07-.04a3.02 3.02 0 0 1 .28-.15l.1-.06.42-.2.1-.03.1-.05c.02 0 .04-.02.05-.03l.08-.04.27-.12.36-.14c.17-.07.34-.12.51-.17l.67-.22.64-.18c1.32-.3 2.53-.77 3.9-.77h-5.55C12.51 4 4.84 12.96 4.84 24s7.67 20 17.12 20h.01Z" fill="#00A997"/>\n<path d="M27.82 44c9.4 0 17.02-8.95 17.02-20S37.22 4 27.82 4c-3.4 0-6.86 1.43-9.59 3.45-.8.66-1.55 1.36-2.24 2.15a21.2 21.2 0 0 0-5.09 12.6 25 25 0 0 0-.06 1.73c0 7.47 5.04 15.01 14.25 13.1-5.02-1.44-8.75-6.77-8.75-13.12 0-6.59 4.64-13.52 11.52-13.52 6.3 0 10 5.06 11.08 9.88.45 2.03.51 4.1.29 6.16-.07.66-.16 1.33-.29 1.98a20.25 20.25 0 0 1-8.71 13.27c-1.6.9-3.25 1.6-5.05 1.95-.9.17-1.82.37-2.76.37h5.4Z" fill="#030A40"/>\n',i})(a):(e=>{const t=J(e),i=document.createElementNS("http://www.w3.org/2000/svg","svg");return i.setAttribute("role","img"),i.setAttribute("title","OpenPass Logo"),i.setAttribute("fill","none"),i.setAttribute("width",`${t}`),i.setAttribute("height",`${t}`),i.setAttribute("viewBox","5 4 40 40"),i.setAttribute("xmlns","http://www.w3.org/2000/svg"),i.innerHTML='\n<path d="M21.97 44c.95 0 1.87-.09 2.78-.26l.37-.08.12-.03.23-.05.19-.05.15-.04.23-.06.11-.03.24-.07.1-.03.25-.08c.03 0 .05-.02.08-.03a4.7 4.7 0 0 0 .33-.12l.28-.1h.02a17.05 17.05 0 0 0 1.51-.7h.02l.27-.14.03-.01.26-.15a.21.21 0 0 0 .05-.03l.23-.14a.2.2 0 0 0 .06-.04l.24-.14.03-.02c.37-.24.74-.5 1.09-.76l.24-.18.02-.02.22-.18c.02 0 .03-.03.05-.04l.2-.17.07-.05.2-.18.05-.04c.41-.37.8-.77 1.2-1.18a23.3 23.3 0 0 0 2.63-3.61c-.02.02.01-.02 0 0-.02.03 0 .02 0 0 .22-.39.41-.77.6-1.17l.54-1.23c-.01.01 0 0 0 0 1.1-2.7 1.58-5.65 1.58-8.56 0-7.58-5.53-15.41-14.35-13.13 5.05 1.45 8.8 6.77 8.8 13.13 0 6.35-3.74 11.7-8.8 13.15-8.13 1.57-14.32-4.59-14.32-13.47 0-5.73 1.81-11.28 6.19-15.13.5-.4.95-.85 1.47-1.24l.23-.17.08-.06.17-.11.03-.02.12-.08.13-.09.04-.03.15-.1.1-.07.2-.12.34-.2.32-.19c.03 0 .05-.03.08-.04.05-.01.09-.04.14-.06l.07-.04a3.02 3.02 0 0 1 .28-.15l.1-.06.42-.2.1-.03.1-.05c.02 0 .04-.02.05-.03l.08-.04.27-.12.36-.14c.17-.07.34-.12.51-.17l.67-.22.64-.18c1.32-.3 2.53-.77 3.9-.77h-5.55C12.51 4 4.84 12.96 4.84 24s7.67 20 17.12 20h.01Z" fill="#00A997"/>\n<path d="M27.82 44c9.4 0 17.02-8.95 17.02-20S37.22 4 27.82 4c-3.4 0-6.86 1.43-9.59 3.45-.8.66-1.55 1.36-2.24 2.15a21.2 21.2 0 0 0-5.09 12.6 25 25 0 0 0-.06 1.73c0 7.47 5.04 15.01 14.25 13.1-5.02-1.44-8.75-6.77-8.75-13.12 0-6.59 4.64-13.52 11.52-13.52 6.3 0 10 5.06 11.08 9.88.45 2.03.51 4.1.29 6.16-.07.66-.16 1.33-.29 1.98a20.25 20.25 0 0 1-8.71 13.27c-1.6.9-3.25 1.6-5.05 1.95-.9.17-1.82.37-2.76.37h5.4Z" fill="#fff"/>\n ',i})(a);if(u.classList.add(`op-js-sdk-siwopb__logo-${a}`),u.classList.add(`op-js-sdk-siwopb__logo-shape-${p}-${a}`),h.appendChild(u),"standard"===p){const e=document.createElement("span");e.innerText=(e=>{switch(e){case"signin":return"Sign in";case"continue_with":return"Continue with OpenPass";default:return"Sign in with OpenPass"}})(r),h.appendChild(e)}return c})(e);s.addEventListener("click",(async t=>{var i;if(t.preventDefault(),"redirect"==e.authenticationMode)await this.redirectAuth.signIn({redirectUrl:e.redirectUrl,source:"SignInWithOpenPassButton",clientState:e.clientState,loginHint:e.loginHint,customQueryParameters:e.customQueryParameters});else if("popup"==e.authenticationMode)try{const t=await this.popupAuth.signInWithPopup({redirectUrl:e.redirectUrl,source:"SignInWithOpenPassButton",clientState:e.clientState,loginHint:e.loginHint,customQueryParameters:e.customQueryParameters});try{null===(i=e.popupSuccessCallback)||void 0===i||i.call(e,t)}catch(e){console.error(`Error executing popup success callback, error: ${e}`)}}catch(t){if(e.popupFailedCallback)try{e.popupFailedCallback(t)}catch(e){console.error(`Error executing popup failed callback, error: ${e}`)}}})),t.appendChild(s),this.apiClient.sendTelemetryEvent("SignInWithOpenPassButtonShown")}}class K{constructor(e,t){this.openPassOptions=e,this.openPassApiClient=t}async authorizeDevice(e){const t=await this.openPassApiClient.authorizeDevice(this.openPassOptions.clientId,e.loginHint,e.disableLoginHintEditing);return{deviceCode:t.device_code,userCode:t.user_code,verificationUri:t.verification_uri,verificationUriComplete:t.verification_uri_complete,expiresIn:t.expires_in,interval:t.interval}}async deviceToken(e){const t=await this.openPassApiClient.deviceToken(this.openPassOptions.clientId,e),i={status:t.status};if(t.tokensResponse){const e=P(t.tokensResponse.id_token);i.tokens={idToken:e,rawIdToken:t.tokensResponse.id_token,accessToken:t.tokensResponse.access_token,rawAccessToken:t.tokensResponse.access_token,refreshToken:t.tokensResponse.refresh_token,tokenType:t.tokensResponse.token_type,expiresIn:t.tokensResponse.expires_in}}return i}}class X{constructor(e){this.showQuickAuthSignIn=()=>this.quickAuth.showInstantly(),this.hideQuickAuthSignIn=()=>this.quickAuth.hideInstantly(),this.openPassOptions=e,this.openPassApiClient=new S(this.openPassOptions),this.redirect=new W(this.openPassOptions,new O(new E),this.openPassApiClient),this.popup=new Q(this.openPassOptions,this.redirect,this.openPassApiClient),this.inlineSigninform=new R(this.openPassOptions,this.redirect,this.popup,this.openPassApiClient),this.signInButton=new G(this.redirect,this.popup,this.openPassApiClient),this.quickAuth=new F(this.openPassOptions,this.redirect,this.popup,this.openPassApiClient),this.deviceAuthGrant=new K(this.openPassOptions,this.openPassApiClient)}async signInWithRedirect(e){return this.redirect.signIn({...e,source:"Custom"})}isAuthenticationRedirect(){return this.redirect.isAuthenticationRedirect()}async handleAuthenticationRedirect(){return this.redirect.handleAuthenticationRedirect()}async signInWithPopup(e){return this.popup.signInWithPopup({...e,source:"Custom"})}renderInlineSignInForm(e){this.inlineSigninform.renderInlineSignInForm(e)}renderQuickAuth(e){this.quickAuth.render(e)}renderSignInButton(e){this.signInButton.renderSignInButton(e)}async authorizeDevice(e){return await this.deviceAuthGrant.authorizeDevice(e)}async deviceToken(e){return await this.deviceAuthGrant.deviceToken(e.deviceCode)}}const Y=e=>null===e||""===e?void 0:e,ee=(e,t)=>{console.error(t),te(e,t)},te=(e,t)=>{e.setAttribute("data-error",t),e.style.display="none"};document.addEventListener("DOMContentLoaded",(()=>{void 0!==window&&((()=>{var e,t;const i=document.getElementById("openpass-quick-auth");if(!i)return;const n=i.getAttribute("data-openpass-quick-auth-mode"),s=i.getAttribute("data-openpass-quick-auth-client-id"),o=i.getAttribute("data-openpass-quick-auth-show"),a=i.getAttribute("data-openpass-quick-auth-visibility"),d=Y(i.getAttribute("data-openpass-quick-auth-redirect-uri")),p=Y(i.getAttribute("data-openpass-quick-auth-popup-success-callback")),l=Y(i.getAttribute("data-openpass-quick-auth-popup-failed-callback")),c=Y(i.getAttribute("data-openpass-quick-auth-sso-base-uri")),h=Y(i.getAttribute("data-openpass-quick-auth-visibility-changed-callback"));if(n&&"redirect"!==n&&"popup"!==n)return void ee(i,"Invalid mode provided for OpenPass quick-auth, please choose either 'redirect' or 'popup'");const u=null!==(e=n)&&void 0!==e?e:"redirect";if(!s)return void ee(i,"No client id provided for OpenPass quick-auth, please add a 'data-client-id' attribute to the quick-auth container");if(o&&"false"!==o&&"true"!==o)return void ee(i,"Show parameter must be either 'true' or 'false' in the data-openpass-quick-auth-show attribute");const g=void 0===o?void 0:"true"===o;if(a&&"displayOnInit"!==a&&"displayOnInitIfSessionActive"!==a&&"hideOnInit"!==a)return void ee(i,"Visibility parameter must be either 'displayOnInit', 'displayOnInitIfSessionActive', or 'hideOnInit' in the data-openpass-quick-auth-visibility attribute");const w=null!==(t=a)&&void 0!==t?t:"displayOnInit";if("redirect"===u&&!d)return void ee(i,"No redirect URI provided for OpenPass quick-auth, please add a 'data-redirect-uri' attribute to the quick-auth container");if("popup"===u&&!p)return void ee(i,"No popup success callback provided for OpenPass quick-auth, please add a 'data-popup-success-callback' attribute to the quick-auth container");if(c)try{new URL(c)}catch(e){return void ee(i,"Invalid URI provided for 'data-sso-base-uri' attribute, please provide a valid OpenPass Auth API URI")}new MutationObserver((e=>{e.forEach((e=>{if("data-openpass-quick-auth-show"===e.attributeName){if(!i)return;const e=i.getAttribute("data-openpass-quick-auth-show");"true"===e?m.showQuickAuthSignIn():"false"===e?m.hideQuickAuthSignIn():ee(i,`Unexpected value ${e} found in 'data-openpass-quick-auth-show' attribute, please report this to the OpenPass support. Expected value range: true, false.`)}}))})).observe(i,{subtree:!1,childList:!1,attributeFilter:["data-openpass-quick-auth-show"]});const m=new X({clientId:s,baseUrl:c}),b={parentContainerElementId:"openpass-quick-auth",authenticationMode:u,redirectUrl:d,popupSuccessCallback:e=>{p&&r(p,window,[e])},popupFailureCallback:e=>{l&&r(l,window,[e])},show:g,visibility:w,visibilityChangedCallback:e=>{h&&r(h,window,[e])}};try{m.renderQuickAuth(b)}catch(e){const t=e instanceof Error?e.message:"Error rendering quick-auth";ee(i,t)}})(),(()=>{var e;const t=document.getElementById("sign-in-with-openpass-button");if(!t)return;const i=t.getAttribute("data-mode"),n=t.getAttribute("data-client-id"),s=Y(t.getAttribute("data-redirect-uri")),o=Y(t.getAttribute("data-popup-success-callback")),a=Y(t.getAttribute("data-popup-failed-callback")),d=t.getAttribute("data-shape"),p=t.getAttribute("data-shape-variant"),l=t.getAttribute("data-size"),c=t.getAttribute("data-text"),h=t.getAttribute("data-theme"),u=t.getAttribute("data-additional-width"),g=Y(t.getAttribute("data-sso-base-uri"));if(i&&"redirect"!==i&&"popup"!==i)return void ee(t,"Invalid mode provided for OpenPass sign-in button, please choose either 'redirect' or 'popup'");const w=null!==(e=i)&&void 0!==e?e:"redirect";if(!n)return void ee(t,"No client id provided for OpenPass sign-in button, please add a 'data-client-id' attribute to the button container");if(c&&"signin"!==c&&"signin_with"!==c&&"continue_with"!==c)return void ee(t,"Invalid text type provided for OpenPass sign-in button, please choose either 'signin', 'signin_with' or 'continue_with'");if("redirect"==w&&!s)return void ee(t,"No redirect URI provided for OpenPass sign-in button, please add a 'data-redirect-uri' attribute to the button container");if("popup"==w&&!o)return void ee(t,"No popup success callback provided for OpenPass sign-in button, please add a 'data-popup-success-callback' attribute to the button container");if(g)try{new URL(g)}catch(e){return void ee(t,"Invalid URI provided for 'data-sso-base-uri' attribute, please provide a valid OpenPass Auth API URI")}if(d&&"standard"!==d&&"icon"!==d)return void ee(t,"Invalid shape provided for OpenPass sign-in button, please choose either 'standard' or 'icon'");if(p&&"pill"!==p&&"rectangle"!==p&&"circle"!==p&&"square"!==p)return void ee(t,"Invalid shape variant provided for OpenPass sign-in button, please choose either 'pill', 'rectangle', 'circle' or 'square'");if("standard"==d&&void 0!==p&&"pill"!==p&&"rectangle"!==p)return void ee(t,"Invalid shape variant provided for OpenPass sign-in button, please choose either 'pill' or 'rectangle'");if("icon"==d&&void 0!==p&&"circle"!==p&&"square"!==p)return void ee(t,"Invalid shape variant provided for OpenPass sign-in button, please choose either 'circle' or 'square'");if(u){const e=Number.parseInt(u);if(Number.isNaN(e)||e<0)return void ee(t,"Invalid additional width provided for OpenPass sign-in button, please provide a positive number")}if(l&&"x-large"!==l&&"large"!==l&&"medium"!==l&&"small"!==l)return void ee(t,"Invalid size provided for OpenPass sign-in button, please choose either 'x-large', 'large', 'medium' or 'small'");if(h&&"openpass"!==h&&"light"!==h&&"dark"!==h)return void ee(t,"Invalid theme provided for OpenPass sign-in button, please choose either 'openpass', 'light' or 'dark'");const m=d||void 0,b=p||void 0,v=h||void 0,f=l||void 0,k=c||void 0,I=u?Number.parseInt(u):void 0,y=new X({clientId:n,baseUrl:g}),_={parentContainerElementId:"sign-in-with-openpass-button",authenticationMode:w,redirectUrl:s,popupSuccessCallback:e=>{r(o,window,[e])},popupFailedCallback:e=>{a&&r(a,window,[e])},text:k,shape:m,shapeVariant:b,size:f,theme:v,additionalWidth:I};try{y.renderSignInButton(_)}catch(e){const i=e instanceof Error?e.message:"Error renering OpenPass sign-in button";ee(t,i)}})())}),{once:!0});const ie=i;return t.default})())); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.openpass=t():e.openpass=t()}(self,(()=>(()=>{"use strict";var e={d:(t,i)=>{for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.d(t,{default:()=>ie});var i={};e.r(i),e.d(i,{AuthError:()=>s,OpenPassClient:()=>X,SdkError:()=>n});class n extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}class s extends n{constructor(e,t,i,n){super(t||e),this.error=e,this.errorDescription=t,this.errorUri=i,this.clientState=n}}class o extends n{constructor(e){super(e)}}function r(e,t,i){const n=e.split("."),s=n.pop();if(void 0===s)throw Error("Function name not provided");for(let e=0;e<n.length;e++)t=t[n[e]];const o=t[s];if(void 0===o)throw Error(`Function '${s}' not found`);return o.apply(t,i)}function a(e){return e.map((e=>{const t=e.endsWith("/")?e.substring(0,e.length-1):e;return t.startsWith("/")?t.substring(1):t})).join("/")}const d="openpass-js-sdk",p="OpenPass-SDK-Name",l="OpenPass-SDK-Version",c="state",h="S256",u="https://auth.myopenpass.com",g="/v1/api/authorize",w=e=>e||u,m=async(e,t)=>{if(t.timeout)return await b(e,t);const i=await fetch(e,t);return{status:i.status,json:await f(i)}},b=async(e,t)=>{let i;try{const n=new AbortController;i=setTimeout((()=>n.abort()),t.timeout);const s=await fetch(e,{...t,signal:n.signal});return{status:s.status,json:await f(s)}}finally{i&&clearTimeout(i)}},v=e=>{const t=[];return Object.keys(e).forEach((i=>{if(e[i]){const n=encodeURIComponent(i),s=encodeURIComponent(e[i]);t.push(n+"="+s)}})),t.length>0?t.join("&"):""},f=async e=>{var t;return(null===(t=e.headers.get("content-type"))||void 0===t?void 0:t.toLowerCase().includes("application/json"))?await e.json():null},k="invalid_redirect";function I(e){this.message=e}I.prototype=new Error,I.prototype.name="InvalidCharacterError";var y="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new I("'atob' failed: The string to be decoded is not correctly encoded.");for(var i,n,s=0,o=0,r="";n=t.charAt(o++);~n&&(i=s%4?64*i+n:n,s++%4)?r+=String.fromCharCode(255&i>>(-2*s&6)):0)n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return r};function _(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(y(e).replace(/(.)/g,(function(e,t){var i=t.charCodeAt(0).toString(16).toUpperCase();return i.length<2&&(i="0"+i),"%"+i})))}(t)}catch(e){return y(t)}}function x(e){this.message=e}x.prototype=new Error,x.prototype.name="InvalidTokenError";const P=e=>function(e,t){if("string"!=typeof e)throw new x("Invalid token specified");var i=!0===(t=t||{}).header?0:1;try{return JSON.parse(_(e.split(".")[i]))}catch(e){throw new x("Invalid token specified: "+e.message)}}(e),A="4.6.0";class S{constructor(e){this.options=e,this.validateOptions(e)}async exchangeAuthCodeForTokens(e,t){var i,n,o;const r={grant_type:"authorization_code",client_id:t.clientId,redirect_uri:t.redirectUrl,code:e,code_verifier:t.codeVerifier},a={};a[p]=d,a[l]=A,a["Content-Type"]="application/x-www-form-urlencoded; charset=UTF-8";const c=(await m(this.resolveUri("/v1/api/token"),{method:"POST",headers:a,body:v(r),timeout:6e4})).json;if(this.isErrorResponse(c))throw new s(null!==(i=c.error)&&void 0!==i?i:"token_oidc_id_request_failed",null!==(n=c.error_description)&&void 0!==n?n:"Error retrieving token",null!==(o=c.error_uri)&&void 0!==o?o:"",t.clientState);const h=c.id_token,u=P(h);if(!u)throw new s("decode_jwt","Unable to decode jwt","",t.clientState);const g=c.access_token,w=c.refresh_token;if(!g)throw new s("no_access_token","No access token was returned","",t.clientState);return{idToken:u,rawIdToken:h,accessToken:g,refreshToken:w,rawAccessToken:g,tokenType:c.token_type,expiresIn:c.expires_in}}async authorizeDevice(e,t,i){var n,o,r;const a={scope:"openid",client_id:e};t&&(a.login_hint=t),i&&(a.disable_login_hint_editing=i);const c={};c[p]=d,c[l]=A,c["Content-Type"]="application/x-www-form-urlencoded; charset=UTF-8";const h=(await m(this.resolveUri("/v1/api/authorize-device"),{method:"POST",headers:c,body:v(a),timeout:6e4})).json;if(this.isErrorResponse(h))throw new s(null!==(n=h.error)&&void 0!==n?n:"authorize_device_request_failed",null!==(o=h.error_description)&&void 0!==o?o:"Error authorizing device",null!==(r=h.error_uri)&&void 0!==r?r:"");return h}async deviceToken(e,t){var i,n,o;const r={client_id:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code",device_code:t},a={};a[p]=d,a[l]=A,a["Content-Type"]="application/x-www-form-urlencoded; charset=UTF-8";const c=(await m(this.resolveUri("/v1/api/device-token"),{method:"POST",headers:a,body:v(r),timeout:6e4})).json;if(this.isErrorResponse(c)){if("authorization_pending"===c.error)return{status:"authorization_pending"};if("slow_down"===c.error)return{status:"slow_down"};throw new s(null!==(i=c.error)&&void 0!==i?i:"device_token_request_failed",null!==(n=c.error_description)&&void 0!==n?n:"Error getting device token",null!==(o=c.error_uri)&&void 0!==o?o:"")}return{status:"ok",tokensResponse:c}}async sendTelemetryEvent(e){const t={};t[p]=d,t[l]=A,t["Content-Type"]="application/json";const i={client_id:this.options.clientId,event_type:e};await m(this.resolveUri("/v1/api/telemetry/event"),{method:"POST",headers:t,body:JSON.stringify(i)})}resolveUri(e){return a([this.options.baseUrl||u,e])}isErrorResponse(e){return void 0!==e.error}validateOptions(e){if(!e.clientId)throw new n("Error clientId is invalid. Please use a valid clientId")}}const C="__openpass__client_session";class O{constructor(e){this.signInStateStorage=e}add(e){this.signInStateStorage.set(C,JSON.stringify(e))}get(){const e=this.signInStateStorage.get(C,"");return e?JSON.parse(e):null}remove(){this.signInStateStorage.remove(C)}}class E{set(e,t){sessionStorage.setItem(e,t)}get(e,t){return sessionStorage.getItem(e)||t}remove(e){sessionStorage.removeItem(e)}}const U=e=>{const t=new URLSearchParams(e);return{code:j("code",t),state:j(c,t),error:j("error",t),errorDescription:j("error_description",t),errorUri:j("error_uri",t)}},T=(e,t,i,n,s)=>{const o=new URLSearchParams;if(o.set("response_type","code"),o.set("client_id",i.clientId),o.set("scope","openid"),o.set(c,i.state),o.set("sdk_name",d),o.set("sdk_version",A),o.set("op_auth_session_source",n),i.redirectUrl&&o.set("redirect_uri",i.redirectUrl),i.codeChallengeMethod&&o.set("code_challenge_method",i.codeChallengeMethod),i.codeChallenge&&o.set("code_challenge",i.codeChallenge),i.responseMode&&o.set("response_mode",i.responseMode),i.loginHint&&o.set("login_hint",i.loginHint),i.consentJwt&&o.set("consent_jwt",i.consentJwt),i.disableLoginHintEditing&&o.set("disable_login_hint_editing",i.disableLoginHintEditing?"true":"false"),s)for(let e=0;e<s.length;e++){const t=s[e];q(t),o.set(t.name,t.value)}return`${a([e,t])}?${o.toString()}`},q=e=>{if(!e.name||!e.value)throw new n("Custom query parameters must have both name and value");if(e.name.length>100||e.value.length>100)throw new n("Custom query parameters' name and value must be under 100 characters");if(!/^[\x20-\x7E]*$/.test(e.name)||!/^[\x20-\x7E]*$/.test(e.value))throw new n("Custom query parameter contains invalid characters. Only printable ASCII characters are allowed")},j=(e,t)=>{const i=t.get(e);return i?decodeURIComponent(i):null},z=(e,t)=>e===t||!!(t.endsWith("/")&&t.length>1)&&e===t.substring(0,t.length-1);class R{constructor(e,t,i,n){this.isRedirectingForAuth=!1,this.openPassOptions=e,this.popupAuth=i,this.redirectAuth=t,this.apiClient=n}renderInlineSignInForm(e){var t;if(!e.parentContainerElementId)throw new n("inlineSignInOptions.parentContainerElementId is required for inline sign-in method.");e.signinButtonTextOption=null!==(t=e.signinButtonTextOption)&&void 0!==t?t:"continue";const i=document.getElementById(e.parentContainerElementId),s=e.authenticationMode,o=e.signinButtonBorderRadiusInPixels;if(!i)throw new n(`Cannot locate parent container element "${e.parentContainerElementId}" for inline sign-in form.`);if("popup"!=s&&"redirect"!=s)throw new n(`Invalid authentication mode: ${s}.`);if("popup"==s&&!e.popupSuccessCallback)throw new n("Must provide popupSuccessCallback for inline sign-in form when authentication mode is popup.");if(e.widthInPixels&&e.widthInPixels<250)throw new n("Inline sign-in form width must be at least 250 pixels.");if(e.heightInPixels&&e.heightInPixels<500)throw new n("Inline sign-in form width must be at least 500 pixels.");if(!["boolean","undefined"].includes(typeof e.darkModeEnabled))throw new n("Invalid darkModeEnabled value. Must be true or false.");if(void 0!==o){if(!/^[0-9]+$/.test(String(o)))throw new n("Invalid signinButtonBorderRadiusInPixels value. Must be an integer number greater than or equal to 0.");if(o>2147483647)throw new n("Invalid signinButtonBorderRadiusInPixels value. Must be less than or equal to 2147483647.")}const r=e.popupSuccessCallback,a=e.popupFailureCallback;window.addEventListener("message",(async t=>{var i;const o=w(this.openPassOptions.baseUrl);if(!z(t.origin,o)||!t.data||"inline-sign-in-message"!=t.data.type)return;const{data:p}=t,l={clientState:e.clientState,disableLoginHintEditing:!1,loginHint:p.loginHint,consentJwt:p.consentJwt,customQueryParameters:e.customQueryParameters};switch(s){case"popup":try{if(this.currentLoginHint===p.loginHint&&this.popupAuth.refocusIfPopupExists())break;this.currentLoginHint=p.loginHint;const t=await this.popupAuth.signInWithPopup({...l,redirectUrl:e.redirectUrl,source:"SignInWithOpenPassInlineForm"});r&&r(t)}catch(e){e instanceof n?a&&a(e):console.error(e)}break;case"redirect":if(this.isRedirectingForAuth)break;this.isRedirectingForAuth=!0;try{await this.redirectAuth.signIn({...l,redirectUrl:e.redirectUrl,source:"SignInWithOpenPassInlineForm"})}catch(e){null===(i=d.contentWindow)||void 0===i||i.postMessage({type:"openpass-redirect-sign-in-failure"},o),console.error(e)}finally{this.isRedirectingForAuth=!1}break;default:console.log("Invalid authentication mode: "+s)}}));const d=this.createIframeElement(this.openPassOptions.clientId,e);i.appendChild(d),this.apiClient.sendTelemetryEvent("SignInWithOpenPassInlineFormShown")}createIframeElement(e,t){var i,n,s,o,r,a;const d=document.createElement("iframe"),p=w(this.openPassOptions.baseUrl),l=new URL("/inline-sign-in",p);return l.searchParams.append("client_id",e),l.searchParams.append("submit_button_text",null!==(n=null===(i=t.signinButtonTextOption)||void 0===i?void 0:i.toString())&&void 0!==n?n:"continue"),l.searchParams.append("auth_mode",t.authenticationMode),t.hideSignInFormApplicationLogo&&l.searchParams.append("hide_client_application_logo",t.hideSignInFormApplicationLogo.toString()),t.hideSignInFormHeaderText&&l.searchParams.append("hide_header_text",t.hideSignInFormHeaderText.toString()),t.signinButtonBackgroundColorHex&&l.searchParams.append("sign_in_button_background_hex_colour",t.signinButtonBackgroundColorHex),void 0!==t.signinButtonBorderRadiusInPixels&&l.searchParams.append("sign_in_button_border_radius_px",String(t.signinButtonBorderRadiusInPixels)),t.darkModeEnabled&&l.searchParams.append("dark_mode_enabled",t.darkModeEnabled.toString()),d.src=l.toString(),d.width=null!==(o=null===(s=t.widthInPixels)||void 0===s?void 0:s.toString())&&void 0!==o?o:"100%",d.height=null!==(a=null===(r=t.heightInPixels)||void 0===r?void 0:r.toString())&&void 0!==a?a:"100%",d}}class F{constructor(e,t,i,s){this.quickAuthSignInOptions=null,this.isInitialized=!1,this.showInstantly=(e=!1)=>{var t;if(!this.isInitialized)throw new n("Quick Auth is not initialized. Call `render` first.");(e||!0!==this.isVisible)&&(this.isVisible=!0,this.quickAuthDialogIFrame.style.display="block",(null===(t=this.quickAuthSignInOptions)||void 0===t?void 0:t.visibilityChangedCallback)&&this.quickAuthSignInOptions.visibilityChangedCallback({visibility:"visible"}),this.apiClient.sendTelemetryEvent("SignInWithOpenPassQuickSignShown"))},this.hideInstantly=()=>{var e;if(!this.isInitialized)throw new n("Quick Auth is not initialized. Call `render` first.");!1!==this.isVisible&&(this.isVisible=!1,this.quickAuthDialogIFrame.style.display="none",(null===(e=this.quickAuthSignInOptions)||void 0===e?void 0:e.visibilityChangedCallback)&&this.quickAuthSignInOptions.visibilityChangedCallback({visibility:"hidden"}))},this.openPassOptions=e,this.popupAuth=i,this.redirectAuth=t,this.apiClient=s}render(e){this.quickAuthSignInOptions=e;const{redirectUrl:t,show:i,visibility:s,parentContainerElementId:o,authenticationMode:r,popupSuccessCallback:a}=e;if(void 0===s&&(this.quickAuthSignInOptions.visibility=void 0===i||!0===i?"displayOnInit":"hideOnInit"),!o)throw new n("parentContainerElementId is required for quick-auth sign-in method.");const d=document.getElementById(o);if(!d)throw new n(`Cannot locate parent container element "${o}" for quick-auth`);if(this.parentContainer=d,"popup"!==r&&"redirect"!==r)throw new n(`Invalid authentication mode: ${r}.`);if("popup"===r&&!a)throw new n("Must provide popupSuccessCallback for quick-auth when authentication mode is popup.");if("redirect"===r&&!t)throw new n("Must provide redirectUrl for quick-auth when authentication mode is redirect.");this.quickAuthDialogIFrame=this.createHiddenQuickAuthIframe(this.openPassOptions.clientId,this.parentContainer),window.addEventListener("message",(t=>this.messageHandler(t,e,this.quickAuthDialogIFrame))),this.parentContainer.appendChild(this.quickAuthDialogIFrame)}showWithDelay(){var e,t;if(!this.isInitialized)throw new n("Quick Auth is not initialized. Call `render` first.");if(!0===this.isVisible)return;this.isVisible=!0;const i=setTimeout((()=>{this.showInstantly(!0),clearTimeout(i)}),null!==(t=null===(e=this.quickAuthSignInOptions)||void 0===e?void 0:e.delayMs)&&void 0!==t?t:1e3)}messageHandler(e,t,i){if(z(e.origin,w(this.openPassOptions.baseUrl))&&e.data&&e.data.type)switch(e.data.type){case"openpass-quick-auth-initialized-message":this.handleInitializedMessage(e,t);break;case"openpass-quick-auth-continue-button-message":this.handleContinueButtonMessage(e,t);break;case"openpass-quick-auth-close-button-message":this.handleCloseButtonMessage(i)}}handleInitializedMessage(e,t){const{data:{hasSession:i,popupWidth:n,popupHeight:s}}=e;switch(this.setupQuickAuthIframeHeight({width:n,height:s}),this.isInitialized=!0,t.visibility){case"displayOnInit":this.showWithDelay();break;case"displayOnInitIfSessionActive":i?this.showWithDelay():this.hideInstantly();break;case"hideOnInit":this.hideInstantly()}}async handleContinueButtonMessage(e,t){const{data:i}=e,s=t.popupSuccessCallback,o=t.popupFailureCallback,r=t.authenticationMode,a={clientState:t.clientState,disableLoginHintEditing:!1,loginHint:i.loginHint,consentJwt:i.consentJwt,customQueryParameters:t.customQueryParameters};switch(r){case"popup":try{if(this.popupAuth.refocusIfPopupExists())break;const e=await this.popupAuth.signInWithPopup({...a,redirectUrl:t.redirectUrl,source:"SignInWithOpenPassQuickAuth"});s&&(this.hideInstantly(),s(e))}catch(e){e instanceof n?o&&o(e):console.error(e)}break;case"redirect":this.redirectAuth.signIn({...a,redirectUrl:t.redirectUrl,source:"SignInWithOpenPassQuickAuth"});break;default:console.error("Invalid authentication mode: "+r)}}handleCloseButtonMessage(e){this.hideInstantly(),this.apiClient.sendTelemetryEvent("SignInWithOpenPassQuickSignDismissed")}createHiddenQuickAuthIframe(e,t){const i=document.createElement("iframe"),n=w(this.openPassOptions.baseUrl),s=new URL("/quick-auth",n);return s.searchParams.append("client_id",e),t.style.zIndex="9999",i.src=s.toString(),i.width="100%",i.style.display="none",i.style.border="none",i.style.overflow="hidden",window.innerWidth>640?(t.style.position="fixed",t.style.top="120px",t.style.right="20px"):(t.style.width="100%",t.style.position="fixed",t.style.bottom="0px",t.style.left="0px"),i}setupQuickAuthIframeHeight({width:e,height:t}){if(!this.quickAuthDialogIFrame||!this.parentContainer)throw new n("Quick Auth is not rendered. Call `render` first.");this.quickAuthDialogIFrame.height=`${t}px`,this.parentContainer.style.height=`${t}px`,this.quickAuthDialogIFrame.style.minWidth=`${e}px`}}const M=()=>window.crypto||window.msCrypto,L=(e=43)=>{const t=new Uint32Array(e);return M().getRandomValues(t),Array.from(t,(e=>`0${e.toString(16)}`.slice(-2))).join("")},H=(e=43)=>L(e),$=async e=>{const t=await(async e=>{const t=(new TextEncoder).encode(e);return await(()=>{const e=M();return e.subtle||e.webkitSubtle})().digest("SHA-256",t)})(e);return n=t,i=String.fromCharCode.apply(null,new Uint8Array(n)),btoa(i).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");var i,n},B=(e=16)=>L(e);class W{constructor(e,t,i){this.openPassOptions=e,this.openPassApiClient=i,this.signInStateRepository=t}async signIn(e){var t;if(!e.redirectUrl)throw new n("Error redirectUrl is invalid. Please use a valid redirectUrl");const i=H(),s={clientState:e.clientState,clientId:this.openPassOptions.clientId,redirectUrl:e.redirectUrl,codeVerifier:i,codeChallenge:await $(i),codeChallengeMethod:h,state:B(),loginHint:e.loginHint,consentJwt:e.consentJwt,disableLoginHintEditing:e.disableLoginHintEditing,originatingUri:null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.href};this.signInStateRepository.add(s);const o=T(w(this.openPassOptions.baseUrl),g,s,e.source,e.customQueryParameters);window.location.href=o}isAuthenticationRedirect(){const e=this.signInStateRepository.get();return e?((e,t,i)=>{if(!e||!i)return!1;const n=-1!=e.toLowerCase().indexOf(i.toLowerCase()),s=null!==t.state&&null!==t.code,o=null!==t.error||null!==t.errorDescription;return n&&(s||o)})(window.location.href,U(window.location.search),e.redirectUrl):(console.warn("Unable to authenticate, a login session may not have being started. Possibly a call to login is required"),!1)}async handleAuthenticationRedirect(){const e=this.signInStateRepository.get();if(!e)throw new s("invalid_auth_session","Unable to authenticate, a login session may not have being started. Possibly a call to login is required","");try{if(!this.isAuthenticationRedirect())throw new s(k,"Unable to validate the redirect response","",e.clientState);const t=U(window.location.search);if(!this.isRedirectUrlValid(e,t)||!t.code)throw new s(t.error?t.error:k,t.errorDescription?t.errorDescription:"Unable to validate the redirect response",t.errorUri?t.errorUri:"",e.clientState);const i=await this.openPassApiClient.exchangeAuthCodeForTokens(t.code,e),{idToken:n,rawIdToken:o,accessToken:r,refreshToken:a,tokenType:d,expiresIn:p}=i;return{clientState:e.clientState,originatingUri:e.originatingUri,idToken:n,rawIdToken:o,accessToken:r,rawAccessToken:r,refreshToken:a,tokenType:d,expiresIn:p}}finally{this.signInStateRepository.remove()}}isRedirectUrlValid(e,t){return!!e&&(!(!t.code||!t.state)&&e.state===t.state)}}const D=(e,t,i,n)=>{const s=(window.outerWidth-i)/2+window.screenX,o=`scrollbars=yes,resizable=yes,toolbar=no,top=${(window.outerHeight-n)/2+window.screenY},left=${s},width=${i},height=${n}`;return window.open(e,t,o)};class N extends Promise{constructor(e){let t;super(((i,n)=>e(i,n,(e=>t=e)))),this.onAbort=t}abort(){this.onAbort&&this.onAbort()}}const V="openpass:popup:login";class Q{constructor(e,t,i){this.openPassOptions=e,this.openPassClient=i,this.redirectApi=t}refocusIfPopupExists(){return!(!this.popupWindow||this.popupWindow.window.closed||(this.popupWindow.window.focus(),0))}async signInWithPopup(e){let t;this.closePopupIfExists(this.popupWindow);let i=null;try{t=this.openPopup()}catch(e){t=null,i=null==e?void 0:e.message}if(!t){if(e.redirectUrl)throw this.redirectApi.signIn({...e,redirectUrl:e.redirectUrl}),new n("Using redirect instead of popup. This error should not be thrown because the redirect happens first.");let t="Popup window did not open correctly.";throw i&&(t+=` Error: ${i}`),new n(t)}const s={window:t};return this.popupWindow=s,this.doLogin(s,e)}async doLogin(e,t){var i;const n=()=>{this.closePopupIfExists(e)};window.addEventListener("beforeunload",n);try{const n=H(),s={clientState:null==t?void 0:t.clientState,clientId:this.openPassOptions.clientId,redirectUrl:null==t?void 0:t.redirectUrl,codeVerifier:n,codeChallenge:await $(n),codeChallengeMethod:h,state:B(),responseMode:"post_message",loginHint:null==t?void 0:t.loginHint,consentJwt:null==t?void 0:t.consentJwt,disableLoginHintEditing:null==t?void 0:t.disableLoginHintEditing,originatingUri:null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.href},o=t?t.source:"Custom",r=T(w(this.openPassOptions.baseUrl),g,s,o,null==t?void 0:t.customQueryParameters);return e.window.location.replace(r),await this.waitForPopupResponse(e,s)}catch(t){throw t instanceof o||this.closePopupIfExists(e),t}finally{window.removeEventListener("beforeunload",n)}}async waitForPopupResponse(e,t){const i=await this.listenForPopupResponse(e);if(!this.isAuthCodeValid(i,t)||!i.code)throw new s(i.error?i.error:"invalid_redirect",i.errorDescription?i.errorDescription:"Error, invalid authorization code response",i.errorUri?i.errorUri:"",t.clientState);const n=await this.openPassClient.exchangeAuthCodeForTokens(i.code,t);return await this.completeAuthentication(e,n,t)}async completeAuthentication(e,t,i){const{idToken:s,rawIdToken:o,rawAccessToken:r,refreshToken:a,expiresIn:d,tokenType:p}=t;return new Promise(((t,l)=>{setTimeout((()=>{l(new n("No Response received from popup"))}),1e4),(async()=>{try{this.closePopupIfExists(e),t({clientState:i.clientState,originatingUri:i.originatingUri,idToken:s,rawIdToken:o,accessToken:r,rawAccessToken:r,refreshToken:a,expiresIn:d,tokenType:p})}catch(t){this.closePopupIfExists(e),l(t)}})()}))}async listenForPopupResponse(e){let t,i,s;const r=new N(((r,a,d)=>{t=setInterval((()=>{e.window&&e.window.closed&&(clearInterval(t),window.removeEventListener("message",s),this.closePopupIfExists(e),a(new n("Popup closed, authentication response not available")))}),100),s=e=>{if(!z(e.origin,w(this.openPassOptions.baseUrl))||!e.data)return;const{data:t}=e;t.source&&"openpass-authorize-message"===t.source&&r(t)},window.addEventListener("message",s,!1),i=setInterval((()=>{clearInterval(i),a(new n("No Response received from popup"))}),6e5),d((()=>{clearInterval(t),clearTimeout(i),window.removeEventListener("message",s),a(new o("Popup window was closed"))}))}));return e.listener=r,r.finally((()=>{clearInterval(t),clearTimeout(i),window.removeEventListener("message",s)}))}openPopup(){return"undefined"!=typeof window&&"undefined"!=typeof document&&void 0!==typeof window.postMessage&&null!==window.postMessage?window.matchMedia("screen and (min-width:960px)").matches?D("",V,428,586):((e,t,i)=>{{const e=`scrollbars=yes,resizable=yes,toolbar=no,top=${window.screenY},left=${window.screenX},width=${window.outerWidth},height=${window.outerHeight}`;return window.open("",t,e)}})(0,V):null}isAuthCodeValid(e,t){return!(!e.code||!e.state)&&t.state===e.state}closePopupIfExists(e){if(e){if(e.window&&!e.window.closed)try{e.window.close()}catch(e){console.warn("Error closing the openpass popup window",e)}if(e.listener)try{e.listener.abort(),e.listener=void 0}catch(e){console.warn("Error aborting the openpass popup listener",e)}e==this.popupWindow&&(this.popupWindow=void 0)}}}const J=e=>{switch(e){case"x-large":return 22;case"large":return 18;case"medium":return 14;case"small":return 10}},Z="openpass-sign-in-button-stylesheet";class G{constructor(e,t,i){this.popupAuth=t,this.redirectAuth=e,this.apiClient=i}renderSignInButton(e){if(!e.parentContainerElementId)throw new n("No parent container element id provided for OpenPass sign-in button");if(e.authenticationMode&&"redirect"!==e.authenticationMode&&"popup"!==e.authenticationMode)throw new n("Invalid authentication mode provided for OpenPass sign-in button, please choose either 'redirect' or 'popup'");if("redirect"==e.authenticationMode&&!e.redirectUrl)throw new n("No redirect url provided for OpenPass sign-in button");if("popup"==e.authenticationMode&&!e.popupSuccessCallback)throw new n("No popup success callback provided for OpenPass sign-in button");if(e.shape&&"standard"!==e.shape&&"icon"!==e.shape)throw new n("Invalid shape provided for OpenPass sign-in button, please choose either 'standard' or 'icon'");if(e.shapeVariant&&"pill"!==e.shapeVariant&&"rectangle"!==e.shapeVariant&&"circle"!==e.shapeVariant&&"square"!==e.shapeVariant)throw new n("Invalid shape variant provided for OpenPass sign-in button, please choose either 'pill', 'rectangle', 'circle' or 'square'");if("standard"==e.shape&&void 0!==e.shapeVariant&&"pill"!==e.shapeVariant&&"rectangle"!==e.shapeVariant)throw new n("Invalid shape variant provided for OpenPass sign-in button, please choose either 'pill' or 'rectangle'");if("icon"==e.shape&&void 0!==e.shapeVariant&&"circle"!==e.shapeVariant&&"square"!==e.shapeVariant)throw new n("Invalid shape variant provided for OpenPass sign-in button, please choose either 'circle' or 'square'");if(e.additionalWidth&&e.additionalWidth<0)throw new n("Invalid width override provided for OpenPass sign-in button, please provide a positive number");if(e.size&&"x-large"!==e.size&&"large"!==e.size&&"medium"!==e.size&&"small"!==e.size)throw new n("Invalid size provided for OpenPass sign-in button, please choose either 'x-large', 'large', 'medium' or 'small'");if(e.theme&&"openpass"!==e.theme&&"light"!==e.theme&&"dark"!==e.theme)throw new n("Invalid theme provided for OpenPass sign-in button, please choose either 'openpass', 'light' or 'dark'");if(e.text&&"signin"!==e.text&&"signin_with"!==e.text&&"continue_with"!==e.text)throw new n("Invalid text type provided for OpenPass sign-in button, please choose either 'signin', 'signin_with' or 'continue_with'");const t=document.getElementById(e.parentContainerElementId);if(!t)throw new n(`No button container found with id '${e.parentContainerElementId}' for OpenPass sign-in button`);var i;i=Z,null===document.querySelector(`style[id=${i}]`)&&((e,t)=>{const i=document.createElement("style");i.innerHTML=e,i.id=t,document.getElementsByTagName("head")[0].appendChild(i)})("\n .op-js-sdk-siwopb__root {\n border: none;\n cursor: pointer;\n display: flex;\n font-family: Poppins, sans-serif;\n text-align: center;\n align-items: center;\n justify-content: center;\n vertical-align: middle;\n }\n \n .op-js-sdk-siwopb__inner {\n display: flex;\n align-items: center;\n }\n \n .op-js-sdk-siwopb__inner > svg {\n flex-shrink: 0;\n }\n\n .op-js-sdk-siwopb__theme-openpass {\n background-color: #012359;\n color: #FFFFFF;\n }\n\n .op-js-sdk-siwopb__theme-light {\n background-color: #FFFFFF;\n color: #3C4043;\n\n border-style: solid;\n border-color: #DADCE0;\n border-width: 1px;\n }\n\n .op-js-sdk-siwopb__theme-dark {\n background-color: #202124;\n color: #FFFFFF;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-x-large {\n font-weight: 400;\n font-size: 16px;\n \n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 16px;\n padding-right: 16px;\n\n height: 48px;\n min-height: 48px;\n max-height: 48px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-pill-x-large {\n border-radius: 100px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-rectangle-x-large {\n border-radius: 4px;\n }\n \n .op-js-sdk-siwopb__size-shape-standard-large {\n font-weight: 400;\n font-size: 14px;\n \n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 12px;\n padding-right: 12px;\n\n height: 40px;\n min-height: 40px;\n max-height: 40px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-pill-large {\n border-radius: 20px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-rectangle-large {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-medium {\n font-weight: 400;\n font-size: 12px;\n\n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 12px;\n padding-right: 12px;\n \n height: 32px;\n min-height: 32px;\n max-height: 32px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-pill-medium {\n border-radius: 16px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-rectangle-medium {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-small {\n font-weight: 300;\n font-size: 11px;\n\n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 8px;\n padding-right: 8px;\n \n height: 20px;\n min-height: 20px;\n max-height: 20px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-pill-small {\n border-radius: 10px;\n }\n\n .op-js-sdk-siwopb__size-shape-standard-rectangle-small {\n border-radius: 4px;\n }\n\n\n .op-js-sdk-siwopb__size-shape-icon-x-large {\n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 12px;\n padding-right: 12px;\n\n height: 48px;\n min-height: 48px;\n max-height: 48px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-square-x-large {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-circle-x-large {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-large {\n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 10px;\n padding-right: 10px;\n\n height: 40px;\n min-height: 40px;\n max-height: 40px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-square-large {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-circle-large {\n border-radius: 20px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-medium {\n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 8px;\n padding-right: 8px;\n\n height: 32px;\n min-height: 32px;\n max-height: 32px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-square-medium {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-circle-medium {\n border-radius: 16px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-small {\n padding-top: 0px;\n padding-bottom: 0px;\n padding-left: 4px;\n padding-right: 4px;\n \n height: 20px;\n min-height: 20px;\n max-height: 20px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-square-small {\n border-radius: 4px;\n }\n\n .op-js-sdk-siwopb__size-shape-icon-circle-small {\n border-radius: 10px;\n }\n\n .op-js-sdk-siwopb__logo-x-large {\n height: 22px;\n width: 22px;\n }\n\n .op-js-sdk-siwopb__logo-large {\n height: 18px;\n width: 18px;\n }\n\n .op-js-sdk-siwopb__logo-medium {\n height: 14px;\n width: 14px;\n }\n\n .op-js-sdk-siwopb__logo-small {\n height: 10px;\n width: 10px;\n }\n\n .op-js-sdk-siwopb__logo-shape-standard-x-large {\n margin-right: 10px;\n }\n\n .op-js-sdk-siwopb__logo-shape-standard-large {\n margin-right: 10px;\n }\n\n .op-js-sdk-siwopb__logo-shape-standard-medium {\n margin-right: 10px;\n }\n\n .op-js-sdk-siwopb__logo-shape-standard-small {\n margin-right: 10px;\n }\n\n .op-js-sdk-siwopb__logo-shape-icon-x-large {\n margin-left: auto;\n margin-right: auto;\n vertical-align: middle;\n }\n\n .op-js-sdk-siwopb__logo-shape-icon-large {\n margin-left: auto;\n margin-right: auto;\n vertical-align: middle;\n }\n\n .op-js-sdk-siwopb__logo-shape-icon-medium {\n margin-left: auto;\n margin-right: auto;\n vertical-align: middle;\n }\n\n .op-js-sdk-siwopb__logo-shape-icon-small {\n margin-left: auto;\n margin-right: auto;\n vertical-align: middle;\n }\n ",Z),(e=>{const t=document.getElementsByTagName("head")[0].getElementsByTagName("link");for(let e=0;e<t.length;e++)if(t[e].href.includes("Poppins"))return!0;return!1})()||(e=>{const t=document.createElement("link");t.href="https://fonts.googleapis.com/css?family=Poppins",t.rel="stylesheet",document.getElementsByTagName("head")[0].appendChild(t)})();const s=(e=>{var t,i,n,s,o;const r=null!==(t=e.text)&&void 0!==t?t:"signin_with",a=null!==(i=e.size)&&void 0!==i?i:"large",d=null!==(n=e.theme)&&void 0!==n?n:"openpass",p=null!==(s=e.shape)&&void 0!==s?s:"standard",l=null!==(o=e.shapeVariant)&&void 0!==o?o:"pill",c=document.createElement("button");c.setAttribute("type","button"),c.setAttribute("aria-label","Sign in with OpenPass Button"),c.classList.add("op-js-sdk-siwopb__root"),c.classList.add(`op-js-sdk-siwopb__size-shape-${p}-${a}`),c.classList.add(`op-js-sdk-siwopb__size-shape-${p}-${l}-${a}`),c.classList.add(`op-js-sdk-siwopb__theme-${d}`);const h=document.createElement("div");if(h.classList.add("op-js-sdk-siwopb__inner"),c.appendChild(h),e.additionalWidth&&e.additionalWidth>0){const t=e.additionalWidth/2;h.style.marginLeft=`${t}px`,h.style.marginRight=`${t}px`}const u="light"===d?(e=>{const t=J(e),i=document.createElementNS("http://www.w3.org/2000/svg","svg");return i.setAttribute("role","img"),i.setAttribute("title","OpenPass Logo"),i.setAttribute("fill","none"),i.setAttribute("width",`${t}`),i.setAttribute("height",`${t}`),i.setAttribute("viewBox","5 4 40 40"),i.setAttribute("xmlns","http://www.w3.org/2000/svg"),i.innerHTML='\n<path d="M21.97 44c.95 0 1.87-.09 2.78-.26l.37-.08.12-.03.23-.05.19-.05.15-.04.23-.06.11-.03.24-.07.1-.03.25-.08c.03 0 .05-.02.08-.03a4.7 4.7 0 0 0 .33-.12l.28-.1h.02a17.05 17.05 0 0 0 1.51-.7h.02l.27-.14.03-.01.26-.15a.21.21 0 0 0 .05-.03l.23-.14a.2.2 0 0 0 .06-.04l.24-.14.03-.02c.37-.24.74-.5 1.09-.76l.24-.18.02-.02.22-.18c.02 0 .03-.03.05-.04l.2-.17.07-.05.2-.18.05-.04c.41-.37.8-.77 1.2-1.18a23.3 23.3 0 0 0 2.63-3.61c-.02.02.01-.02 0 0-.02.03 0 .02 0 0 .22-.39.41-.77.6-1.17l.54-1.23c-.01.01 0 0 0 0 1.1-2.7 1.58-5.65 1.58-8.56 0-7.58-5.53-15.41-14.35-13.13 5.05 1.45 8.8 6.77 8.8 13.13 0 6.35-3.74 11.7-8.8 13.15-8.13 1.57-14.32-4.59-14.32-13.47 0-5.73 1.81-11.28 6.19-15.13.5-.4.95-.85 1.47-1.24l.23-.17.08-.06.17-.11.03-.02.12-.08.13-.09.04-.03.15-.1.1-.07.2-.12.34-.2.32-.19c.03 0 .05-.03.08-.04.05-.01.09-.04.14-.06l.07-.04a3.02 3.02 0 0 1 .28-.15l.1-.06.42-.2.1-.03.1-.05c.02 0 .04-.02.05-.03l.08-.04.27-.12.36-.14c.17-.07.34-.12.51-.17l.67-.22.64-.18c1.32-.3 2.53-.77 3.9-.77h-5.55C12.51 4 4.84 12.96 4.84 24s7.67 20 17.12 20h.01Z" fill="#00A997"/>\n<path d="M27.82 44c9.4 0 17.02-8.95 17.02-20S37.22 4 27.82 4c-3.4 0-6.86 1.43-9.59 3.45-.8.66-1.55 1.36-2.24 2.15a21.2 21.2 0 0 0-5.09 12.6 25 25 0 0 0-.06 1.73c0 7.47 5.04 15.01 14.25 13.1-5.02-1.44-8.75-6.77-8.75-13.12 0-6.59 4.64-13.52 11.52-13.52 6.3 0 10 5.06 11.08 9.88.45 2.03.51 4.1.29 6.16-.07.66-.16 1.33-.29 1.98a20.25 20.25 0 0 1-8.71 13.27c-1.6.9-3.25 1.6-5.05 1.95-.9.17-1.82.37-2.76.37h5.4Z" fill="#030A40"/>\n',i})(a):(e=>{const t=J(e),i=document.createElementNS("http://www.w3.org/2000/svg","svg");return i.setAttribute("role","img"),i.setAttribute("title","OpenPass Logo"),i.setAttribute("fill","none"),i.setAttribute("width",`${t}`),i.setAttribute("height",`${t}`),i.setAttribute("viewBox","5 4 40 40"),i.setAttribute("xmlns","http://www.w3.org/2000/svg"),i.innerHTML='\n<path d="M21.97 44c.95 0 1.87-.09 2.78-.26l.37-.08.12-.03.23-.05.19-.05.15-.04.23-.06.11-.03.24-.07.1-.03.25-.08c.03 0 .05-.02.08-.03a4.7 4.7 0 0 0 .33-.12l.28-.1h.02a17.05 17.05 0 0 0 1.51-.7h.02l.27-.14.03-.01.26-.15a.21.21 0 0 0 .05-.03l.23-.14a.2.2 0 0 0 .06-.04l.24-.14.03-.02c.37-.24.74-.5 1.09-.76l.24-.18.02-.02.22-.18c.02 0 .03-.03.05-.04l.2-.17.07-.05.2-.18.05-.04c.41-.37.8-.77 1.2-1.18a23.3 23.3 0 0 0 2.63-3.61c-.02.02.01-.02 0 0-.02.03 0 .02 0 0 .22-.39.41-.77.6-1.17l.54-1.23c-.01.01 0 0 0 0 1.1-2.7 1.58-5.65 1.58-8.56 0-7.58-5.53-15.41-14.35-13.13 5.05 1.45 8.8 6.77 8.8 13.13 0 6.35-3.74 11.7-8.8 13.15-8.13 1.57-14.32-4.59-14.32-13.47 0-5.73 1.81-11.28 6.19-15.13.5-.4.95-.85 1.47-1.24l.23-.17.08-.06.17-.11.03-.02.12-.08.13-.09.04-.03.15-.1.1-.07.2-.12.34-.2.32-.19c.03 0 .05-.03.08-.04.05-.01.09-.04.14-.06l.07-.04a3.02 3.02 0 0 1 .28-.15l.1-.06.42-.2.1-.03.1-.05c.02 0 .04-.02.05-.03l.08-.04.27-.12.36-.14c.17-.07.34-.12.51-.17l.67-.22.64-.18c1.32-.3 2.53-.77 3.9-.77h-5.55C12.51 4 4.84 12.96 4.84 24s7.67 20 17.12 20h.01Z" fill="#00A997"/>\n<path d="M27.82 44c9.4 0 17.02-8.95 17.02-20S37.22 4 27.82 4c-3.4 0-6.86 1.43-9.59 3.45-.8.66-1.55 1.36-2.24 2.15a21.2 21.2 0 0 0-5.09 12.6 25 25 0 0 0-.06 1.73c0 7.47 5.04 15.01 14.25 13.1-5.02-1.44-8.75-6.77-8.75-13.12 0-6.59 4.64-13.52 11.52-13.52 6.3 0 10 5.06 11.08 9.88.45 2.03.51 4.1.29 6.16-.07.66-.16 1.33-.29 1.98a20.25 20.25 0 0 1-8.71 13.27c-1.6.9-3.25 1.6-5.05 1.95-.9.17-1.82.37-2.76.37h5.4Z" fill="#fff"/>\n ',i})(a);if(u.classList.add(`op-js-sdk-siwopb__logo-${a}`),u.classList.add(`op-js-sdk-siwopb__logo-shape-${p}-${a}`),h.appendChild(u),"standard"===p){const e=document.createElement("span");e.innerText=(e=>{switch(e){case"signin":return"Sign in";case"continue_with":return"Continue with OpenPass";default:return"Sign in with OpenPass"}})(r),h.appendChild(e)}return c})(e);s.addEventListener("click",(async t=>{var i;if(t.preventDefault(),"redirect"==e.authenticationMode)await this.redirectAuth.signIn({redirectUrl:e.redirectUrl,source:"SignInWithOpenPassButton",clientState:e.clientState,loginHint:e.loginHint,customQueryParameters:e.customQueryParameters});else if("popup"==e.authenticationMode)try{const t=await this.popupAuth.signInWithPopup({redirectUrl:e.redirectUrl,source:"SignInWithOpenPassButton",clientState:e.clientState,loginHint:e.loginHint,customQueryParameters:e.customQueryParameters});try{null===(i=e.popupSuccessCallback)||void 0===i||i.call(e,t)}catch(e){console.error(`Error executing popup success callback, error: ${e}`)}}catch(t){if(e.popupFailedCallback)try{e.popupFailedCallback(t)}catch(e){console.error(`Error executing popup failed callback, error: ${e}`)}}})),t.appendChild(s),this.apiClient.sendTelemetryEvent("SignInWithOpenPassButtonShown")}}class K{constructor(e,t){this.openPassOptions=e,this.openPassApiClient=t}async authorizeDevice(e){const t=await this.openPassApiClient.authorizeDevice(this.openPassOptions.clientId,e.loginHint,e.disableLoginHintEditing);return{deviceCode:t.device_code,userCode:t.user_code,verificationUri:t.verification_uri,verificationUriComplete:t.verification_uri_complete,expiresIn:t.expires_in,interval:t.interval}}async deviceToken(e){const t=await this.openPassApiClient.deviceToken(this.openPassOptions.clientId,e),i={status:t.status};if(t.tokensResponse){const e=P(t.tokensResponse.id_token);i.tokens={idToken:e,rawIdToken:t.tokensResponse.id_token,accessToken:t.tokensResponse.access_token,rawAccessToken:t.tokensResponse.access_token,refreshToken:t.tokensResponse.refresh_token,tokenType:t.tokensResponse.token_type,expiresIn:t.tokensResponse.expires_in}}return i}}class X{constructor(e){this.showQuickAuthSignIn=()=>this.quickAuth.showInstantly(),this.hideQuickAuthSignIn=()=>this.quickAuth.hideInstantly(),this.openPassOptions=e,this.openPassApiClient=new S(this.openPassOptions),this.redirect=new W(this.openPassOptions,new O(new E),this.openPassApiClient),this.popup=new Q(this.openPassOptions,this.redirect,this.openPassApiClient),this.inlineSigninform=new R(this.openPassOptions,this.redirect,this.popup,this.openPassApiClient),this.signInButton=new G(this.redirect,this.popup,this.openPassApiClient),this.quickAuth=new F(this.openPassOptions,this.redirect,this.popup,this.openPassApiClient),this.deviceAuthGrant=new K(this.openPassOptions,this.openPassApiClient)}async signInWithRedirect(e){return this.redirect.signIn({...e,source:"Custom"})}isAuthenticationRedirect(){return this.redirect.isAuthenticationRedirect()}async handleAuthenticationRedirect(){return this.redirect.handleAuthenticationRedirect()}async signInWithPopup(e){return this.popup.signInWithPopup({...e,source:"Custom"})}renderInlineSignInForm(e){this.inlineSigninform.renderInlineSignInForm(e)}renderQuickAuth(e){this.quickAuth.render(e)}renderSignInButton(e){this.signInButton.renderSignInButton(e)}async authorizeDevice(e){return await this.deviceAuthGrant.authorizeDevice(e)}async deviceToken(e){return await this.deviceAuthGrant.deviceToken(e.deviceCode)}}const Y=e=>null===e||""===e?void 0:e,ee=(e,t)=>{console.error(t),te(e,t)},te=(e,t)=>{e.setAttribute("data-error",t),e.style.display="none"};document.addEventListener("DOMContentLoaded",(()=>{void 0!==window&&((()=>{var e,t;const i=document.getElementById("openpass-quick-auth");if(!i)return;const n=i.getAttribute("data-openpass-quick-auth-mode"),s=i.getAttribute("data-openpass-quick-auth-client-id"),o=i.getAttribute("data-openpass-quick-auth-show"),a=i.getAttribute("data-openpass-quick-auth-visibility"),d=Y(i.getAttribute("data-openpass-quick-auth-redirect-uri")),p=Y(i.getAttribute("data-openpass-quick-auth-popup-success-callback")),l=Y(i.getAttribute("data-openpass-quick-auth-popup-failed-callback")),c=Y(i.getAttribute("data-openpass-quick-auth-sso-base-uri")),h=Y(i.getAttribute("data-openpass-quick-auth-visibility-changed-callback"));if(n&&"redirect"!==n&&"popup"!==n)return void ee(i,"Invalid mode provided for OpenPass quick-auth, please choose either 'redirect' or 'popup'");const u=null!==(e=n)&&void 0!==e?e:"redirect";if(!s)return void ee(i,"No client id provided for OpenPass quick-auth, please add a 'data-client-id' attribute to the quick-auth container");if(o&&"false"!==o&&"true"!==o)return void ee(i,"Show parameter must be either 'true' or 'false' in the data-openpass-quick-auth-show attribute");const g=void 0===o?void 0:"true"===o;if(a&&"displayOnInit"!==a&&"displayOnInitIfSessionActive"!==a&&"hideOnInit"!==a)return void ee(i,"Visibility parameter must be either 'displayOnInit', 'displayOnInitIfSessionActive', or 'hideOnInit' in the data-openpass-quick-auth-visibility attribute");const w=null!==(t=a)&&void 0!==t?t:"displayOnInit";if("redirect"===u&&!d)return void ee(i,"No redirect URI provided for OpenPass quick-auth, please add a 'data-redirect-uri' attribute to the quick-auth container");if("popup"===u&&!p)return void ee(i,"No popup success callback provided for OpenPass quick-auth, please add a 'data-popup-success-callback' attribute to the quick-auth container");if(c)try{new URL(c)}catch(e){return void ee(i,"Invalid URI provided for 'data-sso-base-uri' attribute, please provide a valid OpenPass Auth API URI")}new MutationObserver((e=>{e.forEach((e=>{if("data-openpass-quick-auth-show"===e.attributeName){if(!i)return;const e=i.getAttribute("data-openpass-quick-auth-show");"true"===e?m.showQuickAuthSignIn():"false"===e?m.hideQuickAuthSignIn():ee(i,`Unexpected value ${e} found in 'data-openpass-quick-auth-show' attribute, please report this to the OpenPass support. Expected value range: true, false.`)}}))})).observe(i,{subtree:!1,childList:!1,attributeFilter:["data-openpass-quick-auth-show"]});const m=new X({clientId:s,baseUrl:c}),b={parentContainerElementId:"openpass-quick-auth",authenticationMode:u,redirectUrl:d,popupSuccessCallback:e=>{p&&r(p,window,[e])},popupFailureCallback:e=>{l&&r(l,window,[e])},show:g,visibility:w,visibilityChangedCallback:e=>{h&&r(h,window,[e])}};try{m.renderQuickAuth(b)}catch(e){const t=e instanceof Error?e.message:"Error rendering quick-auth";ee(i,t)}})(),(()=>{var e;const t=document.getElementById("sign-in-with-openpass-button");if(!t)return;const i=t.getAttribute("data-mode"),n=t.getAttribute("data-client-id"),s=Y(t.getAttribute("data-redirect-uri")),o=Y(t.getAttribute("data-popup-success-callback")),a=Y(t.getAttribute("data-popup-failed-callback")),d=t.getAttribute("data-shape"),p=t.getAttribute("data-shape-variant"),l=t.getAttribute("data-size"),c=t.getAttribute("data-text"),h=t.getAttribute("data-theme"),u=t.getAttribute("data-additional-width"),g=Y(t.getAttribute("data-sso-base-uri"));if(i&&"redirect"!==i&&"popup"!==i)return void ee(t,"Invalid mode provided for OpenPass sign-in button, please choose either 'redirect' or 'popup'");const w=null!==(e=i)&&void 0!==e?e:"redirect";if(!n)return void ee(t,"No client id provided for OpenPass sign-in button, please add a 'data-client-id' attribute to the button container");if(c&&"signin"!==c&&"signin_with"!==c&&"continue_with"!==c)return void ee(t,"Invalid text type provided for OpenPass sign-in button, please choose either 'signin', 'signin_with' or 'continue_with'");if("redirect"==w&&!s)return void ee(t,"No redirect URI provided for OpenPass sign-in button, please add a 'data-redirect-uri' attribute to the button container");if("popup"==w&&!o)return void ee(t,"No popup success callback provided for OpenPass sign-in button, please add a 'data-popup-success-callback' attribute to the button container");if(g)try{new URL(g)}catch(e){return void ee(t,"Invalid URI provided for 'data-sso-base-uri' attribute, please provide a valid OpenPass Auth API URI")}if(d&&"standard"!==d&&"icon"!==d)return void ee(t,"Invalid shape provided for OpenPass sign-in button, please choose either 'standard' or 'icon'");if(p&&"pill"!==p&&"rectangle"!==p&&"circle"!==p&&"square"!==p)return void ee(t,"Invalid shape variant provided for OpenPass sign-in button, please choose either 'pill', 'rectangle', 'circle' or 'square'");if("standard"==d&&void 0!==p&&"pill"!==p&&"rectangle"!==p)return void ee(t,"Invalid shape variant provided for OpenPass sign-in button, please choose either 'pill' or 'rectangle'");if("icon"==d&&void 0!==p&&"circle"!==p&&"square"!==p)return void ee(t,"Invalid shape variant provided for OpenPass sign-in button, please choose either 'circle' or 'square'");if(u){const e=Number.parseInt(u);if(Number.isNaN(e)||e<0)return void ee(t,"Invalid additional width provided for OpenPass sign-in button, please provide a positive number")}if(l&&"x-large"!==l&&"large"!==l&&"medium"!==l&&"small"!==l)return void ee(t,"Invalid size provided for OpenPass sign-in button, please choose either 'x-large', 'large', 'medium' or 'small'");if(h&&"openpass"!==h&&"light"!==h&&"dark"!==h)return void ee(t,"Invalid theme provided for OpenPass sign-in button, please choose either 'openpass', 'light' or 'dark'");const m=d||void 0,b=p||void 0,v=h||void 0,f=l||void 0,k=c||void 0,I=u?Number.parseInt(u):void 0,y=new X({clientId:n,baseUrl:g}),_={parentContainerElementId:"sign-in-with-openpass-button",authenticationMode:w,redirectUrl:s,popupSuccessCallback:e=>{r(o,window,[e])},popupFailedCallback:e=>{a&&r(a,window,[e])},text:k,shape:m,shapeVariant:b,size:f,theme:v,additionalWidth:I};try{y.renderSignInButton(_)}catch(e){const i=e instanceof Error?e.message:"Error renering OpenPass sign-in button";ee(t,i)}})())}),{once:!0});const ie=i;return t.default})())); | ||
//# sourceMappingURL=openpass-js-sdk.min.js.map |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "4.5.6-pre-release", | ||
"version": "4.6.0", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "4.5.6-pre-release", | ||
"version": "4.6.0", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "4.5.6-pre-release", | ||
"version": "4.6.0", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
657792
6146