@openpass/openpass-js-sdk
Advanced tools
Comparing version 4.7.0 to 4.7.1-pre-release
@@ -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:()=>ne});var i={};e.r(i),e.d(i,{AuthError:()=>s,OpenPassClient:()=>Y,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.7.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}}const F="openPassQuickAuthDismissalData";class D{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;this.clearDismissalData();const 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.incrementDismissalData(),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);s.searchParams.append("client_id",e);const o=this.getDismissalData();return o&&(s.searchParams.append("last_dismissed_utc",o.lastDismissedUtc),s.searchParams.append("times_dismissed",o.timesDismissed.toString())),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`}getDismissalData(){const e=localStorage.getItem(F);if(null==e)return null;try{const t=JSON.parse(e);if(!Number.isFinite(t.timesDismissed)||t.timesDismissed<0)throw new Error("Invalid quick auth dismissal data");if(!Date.parse(t.lastDismissedUtc))throw new Error("Invalid quick auth dismissal data");return t}catch(e){return this.clearDismissalData(),null}}clearDismissalData(){localStorage.removeItem(F)}incrementDismissalData(){const e=this.getDismissalData(),t=(new Date).toISOString(),i=((null==e?void 0:e.timesDismissed)||0)+1;localStorage.setItem(F,JSON.stringify({timesDismissed:i,lastDismissedUtc:t}))}}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 Q 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 J{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 Q(((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 Z=e=>{switch(e){case"x-large":return 22;case"large":return 18;case"medium":return 14;case"small":return 10}},G="openpass-sign-in-button-stylesheet";class K{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=G,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 ",G),(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=Z(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=Z(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 X{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 Y{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 J(this.openPassOptions,this.redirect,this.openPassApiClient),this.inlineSigninform=new R(this.openPassOptions,this.redirect,this.popup,this.openPassApiClient),this.signInButton=new K(this.redirect,this.popup,this.openPassApiClient),this.quickAuth=new D(this.openPassOptions,this.redirect,this.popup,this.openPassApiClient),this.deviceAuthGrant=new X(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 ee=e=>null===e||""===e?void 0:e,te=(e,t)=>{console.error(t),ie(e,t)},ie=(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=ee(i.getAttribute("data-openpass-quick-auth-redirect-uri")),p=ee(i.getAttribute("data-openpass-quick-auth-popup-success-callback")),l=ee(i.getAttribute("data-openpass-quick-auth-popup-failed-callback")),c=ee(i.getAttribute("data-openpass-quick-auth-sso-base-uri")),h=ee(i.getAttribute("data-openpass-quick-auth-visibility-changed-callback"));if(n&&"redirect"!==n&&"popup"!==n)return void te(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 te(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 te(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 te(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 te(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 te(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 te(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():te(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 Y({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";te(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=ee(t.getAttribute("data-redirect-uri")),o=ee(t.getAttribute("data-popup-success-callback")),a=ee(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=ee(t.getAttribute("data-sso-base-uri"));if(i&&"redirect"!==i&&"popup"!==i)return void te(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 te(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 te(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 te(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 te(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 te(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 te(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 te(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 te(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 te(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 te(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 te(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 te(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 Y({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";te(t,i)}})())}),{once:!0});const ne=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:()=>se});var i={};e.r(i),e.d(i,{AuthError:()=>s,OpenPassClient:()=>ee,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 v(e,t);const i=await fetch(e,t);return{status:i.status,json:await f(i)}},v=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)}},b=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.7.1-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:b(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:b(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:b(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 sendClientTelemetryEvent(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),timeout:6e4})}async sendSdkTelemetryEvent(e,t,i,n){const s={};s[p]=d,s[l]=A.i8,s["Content-Type"]="application/json";const o={client_id:this.options.clientId,event_type:e,event_name:t,message:i,stack_trace:n};await m(this.resolveUri("/v1/api/telemetry/sdk-event"),{method:"POST",headers:s,body:JSON.stringify(o),timeout:6e4})}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.sendClientTelemetryEvent("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}}const F="openPassQuickAuthDismissalData";class D{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.sendClientTelemetryEvent("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;this.clearDismissalData();const 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.incrementDismissalData(),this.hideInstantly(),this.apiClient.sendClientTelemetryEvent("SignInWithOpenPassQuickSignDismissed")}createHiddenQuickAuthIframe(e,t){const i=document.createElement("iframe"),n=w(this.openPassOptions.baseUrl),s=new URL("/quick-auth",n);s.searchParams.append("client_id",e);const o=this.getDismissalData();return o&&(s.searchParams.append("last_dismissed_utc",o.lastDismissedUtc),s.searchParams.append("times_dismissed",o.timesDismissed.toString())),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`}getDismissalData(){const e=localStorage.getItem(F);if(null==e)return null;try{const t=JSON.parse(e);if(!Number.isFinite(t.timesDismissed)||t.timesDismissed<0)throw new Error("Invalid quick auth dismissal data");if(!Date.parse(t.lastDismissedUtc))throw new Error("Invalid quick auth dismissal data");return t}catch(e){return this.clearDismissalData(),null}}clearDismissalData(){localStorage.removeItem(F)}incrementDismissalData(){const e=this.getDismissalData(),t=(new Date).toISOString(),i=((null==e?void 0:e.timesDismissed)||0)+1;localStorage.setItem(F,JSON.stringify({timesDismissed:i,lastDismissedUtc:t}))}}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),W=(e,t,i)=>{let n="",s="";t instanceof Error?(n=t.message,s=t.stack||""):n="An error occurred",i.sendSdkTelemetryEvent("Error",e,n,s)};class N{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}}catch(e){throw W("RedirectAuth.handleAuthenticationRedirect",e,this.openPassApiClient),e}finally{this.signInStateRepository.remove()}}isRedirectUrlValid(e,t){return!!e&&(!(!t.code||!t.state)&&e.state===t.state)}}const Q=(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 V extends Promise{constructor(e){let t;super(((i,n)=>e(i,n,(e=>t=e)))),this.onAbort=t}abort(){this.onAbort&&this.onAbort()}}const J="openpass:popup:login";class Z{constructor(e,t,i){this.openPassOptions=e,this.openPassApiClient=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||(W("PopupAuth.doLogin",t,this.openPassApiClient),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.openPassApiClient.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 V(((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?Q("",J,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,J):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 G=e=>{switch(e){case"x-large":return 22;case"large":return 18;case"medium":return 14;case"small":return 10}},K="openpass-sign-in-button-stylesheet";class X{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=K,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 ",K),(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=G(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=G(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.sendClientTelemetryEvent("SignInWithOpenPassButtonShown")}}class Y{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 ee{constructor(e){this.showQuickAuthSignIn=()=>this.quickAuth.showInstantly(),this.hideQuickAuthSignIn=()=>this.quickAuth.hideInstantly(),this.openPassOptions=e,this.openPassApiClient=new S(this.openPassOptions),this.redirect=new N(this.openPassOptions,new O(new E),this.openPassApiClient),this.popup=new Z(this.openPassOptions,this.redirect,this.openPassApiClient),this.inlineSigninform=new R(this.openPassOptions,this.redirect,this.popup,this.openPassApiClient),this.signInButton=new X(this.redirect,this.popup,this.openPassApiClient),this.quickAuth=new D(this.openPassOptions,this.redirect,this.popup,this.openPassApiClient),this.deviceAuthGrant=new Y(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 te=e=>null===e||""===e?void 0:e,ie=(e,t)=>{console.error(t),ne(e,t)},ne=(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=te(i.getAttribute("data-openpass-quick-auth-redirect-uri")),p=te(i.getAttribute("data-openpass-quick-auth-popup-success-callback")),l=te(i.getAttribute("data-openpass-quick-auth-popup-failed-callback")),c=te(i.getAttribute("data-openpass-quick-auth-sso-base-uri")),h=te(i.getAttribute("data-openpass-quick-auth-visibility-changed-callback"));if(n&&"redirect"!==n&&"popup"!==n)return void ie(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 ie(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 ie(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 ie(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 ie(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 ie(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 ie(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():ie(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 ee({clientId:s,baseUrl:c}),v={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(v)}catch(e){const t=e instanceof Error?e.message:"Error rendering quick-auth";ie(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=te(t.getAttribute("data-redirect-uri")),o=te(t.getAttribute("data-popup-success-callback")),a=te(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=te(t.getAttribute("data-sso-base-uri"));if(i&&"redirect"!==i&&"popup"!==i)return void ie(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 ie(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 ie(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 ie(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 ie(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 ie(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 ie(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 ie(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 ie(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 ie(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 ie(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 ie(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 ie(t,"Invalid theme provided for OpenPass sign-in button, please choose either 'openpass', 'light' or 'dark'");const m=d||void 0,v=p||void 0,b=h||void 0,f=l||void 0,k=c||void 0,I=u?Number.parseInt(u):void 0,y=new ee({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:v,size:f,theme:b,additionalWidth:I};try{y.renderSignInButton(_)}catch(e){const i=e instanceof Error?e.message:"Error renering OpenPass sign-in button";ie(t,i)}})())}),{once:!0});const se=i;return t.default})())); | ||
//# sourceMappingURL=openpass-js-sdk.min.js.map |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "4.7.0", | ||
"version": "4.7.1-pre-release", | ||
"repository": { | ||
@@ -72,3 +72,3 @@ "type": "git", | ||
"@percy/playwright": "^1.0.4", | ||
"@playwright/test": "^1.40.0", | ||
"@playwright/test": "^1.49.1", | ||
"@testing-library/dom": "^8.0.0", | ||
@@ -75,0 +75,0 @@ "@types/ejs": "^3.1.3", |
@@ -132,3 +132,3 @@ "use strict"; | ||
} | ||
async sendTelemetryEvent(eventType) { | ||
async sendClientTelemetryEvent(eventType) { | ||
const headers = {}; | ||
@@ -142,8 +142,28 @@ headers[constants_1.HEADER_SDK_NAME] = constants_1.SDK_NAME; | ||
}; | ||
await (0, fetch_1.fetchRequest)(this.resolveUri(config_1.config.SSO_TELEMETRY_EVENT_PATH), { | ||
await (0, fetch_1.fetchRequest)(this.resolveUri(config_1.config.SSO_CLIENT_TELEMETRY_EVENT_PATH), { | ||
method: "POST", | ||
headers: headers, | ||
body: JSON.stringify(payload), | ||
timeout: (0, config_1.getApiDefaultTimeoutMs)(), | ||
}); | ||
} | ||
async sendSdkTelemetryEvent(eventType, eventName, message, stackTrace) { | ||
const headers = {}; | ||
headers[constants_1.HEADER_SDK_NAME] = constants_1.SDK_NAME; | ||
headers[constants_1.HEADER_SDK_VERSION] = package_json_1.version; | ||
headers["Content-Type"] = "application/json"; | ||
const payload = { | ||
client_id: this.options.clientId, | ||
event_type: eventType, | ||
event_name: eventName, | ||
message: message, | ||
stack_trace: stackTrace, | ||
}; | ||
await (0, fetch_1.fetchRequest)(this.resolveUri(config_1.config.SSO_SDK_TELEMETRY_EVENT_PATH), { | ||
method: "POST", | ||
headers: headers, | ||
body: JSON.stringify(payload), | ||
timeout: (0, config_1.getApiDefaultTimeoutMs)(), | ||
}); | ||
} | ||
resolveUri(uri) { | ||
@@ -150,0 +170,0 @@ const baseUri = this.options.baseUrl || config_1.config.SSO_BASE_URL; |
@@ -143,3 +143,3 @@ "use strict"; | ||
// Do not await the result, this is a fire and forget operation | ||
this.apiClient.sendTelemetryEvent("SignInWithOpenPassInlineFormShown"); | ||
this.apiClient.sendClientTelemetryEvent("SignInWithOpenPassInlineFormShown"); | ||
} | ||
@@ -146,0 +146,0 @@ createIframeElement(clientId, inlineSignInOptions) { |
@@ -16,2 +16,3 @@ "use strict"; | ||
const abortablePromise_1 = __importDefault(require("./utils/abortablePromise")); | ||
const sdkTelemetry_1 = require("./utils/sdkTelemetry"); | ||
const POPUP_HEIGHT = 586; | ||
@@ -29,5 +30,5 @@ const POPUP_WIDTH = 428; | ||
class PopupAuth { | ||
constructor(OpenPassOptions, redirectApi, openPassClient) { | ||
this.openPassOptions = OpenPassOptions; | ||
this.openPassClient = openPassClient; | ||
constructor(openPassOptions, redirectApi, openPassApiClient) { | ||
this.openPassOptions = openPassOptions; | ||
this.openPassApiClient = openPassApiClient; | ||
this.redirectApi = redirectApi; | ||
@@ -102,2 +103,5 @@ } | ||
if (!(e instanceof errors_1.AuthCancelledError)) { | ||
// Only send telemetry events if the error is not due to the user closing the popup | ||
(0, sdkTelemetry_1.sendSdkTelemetryErrorEvent)("PopupAuth.doLogin", e, this.openPassApiClient); | ||
// Close the popup if an error occurs | ||
this.closePopupIfExists(authWindow); | ||
@@ -116,3 +120,3 @@ } | ||
} | ||
const openPassTokens = await this.openPassClient.exchangeAuthCodeForTokens(authCodeResponse.code, authSession); | ||
const openPassTokens = await this.openPassApiClient.exchangeAuthCodeForTokens(authCodeResponse.code, authSession); | ||
return await this.completeAuthentication(authWindow, openPassTokens, authSession); | ||
@@ -119,0 +123,0 @@ } |
@@ -35,3 +35,3 @@ "use strict"; | ||
} | ||
this.apiClient.sendTelemetryEvent("SignInWithOpenPassQuickSignShown"); | ||
this.apiClient.sendClientTelemetryEvent("SignInWithOpenPassQuickSignShown"); | ||
}; | ||
@@ -195,3 +195,3 @@ this.hideInstantly = () => { | ||
this.hideInstantly(); | ||
this.apiClient.sendTelemetryEvent("SignInWithOpenPassQuickSignDismissed"); | ||
this.apiClient.sendClientTelemetryEvent("SignInWithOpenPassQuickSignDismissed"); | ||
} | ||
@@ -198,0 +198,0 @@ createHiddenQuickAuthIframe(clientId, parentContainer) { |
@@ -10,2 +10,3 @@ "use strict"; | ||
const errors_1 = require("./error/errors"); | ||
const sdkTelemetry_1 = require("./utils/sdkTelemetry"); | ||
/** | ||
@@ -17,4 +18,4 @@ * Class which handles the redirect authorization flow. | ||
class RedirectAuth { | ||
constructor(OpenPassOptions, signInStateRepository, openPassAuthClient) { | ||
this.openPassOptions = OpenPassOptions; | ||
constructor(openPassOptions, signInStateRepository, openPassAuthClient) { | ||
this.openPassOptions = openPassOptions; | ||
this.openPassApiClient = openPassAuthClient; | ||
@@ -92,2 +93,6 @@ this.signInStateRepository = signInStateRepository; | ||
} | ||
catch (error) { | ||
(0, sdkTelemetry_1.sendSdkTelemetryErrorEvent)("RedirectAuth.handleAuthenticationRedirect", error, this.openPassApiClient); | ||
throw error; | ||
} | ||
finally { | ||
@@ -94,0 +99,0 @@ this.signInStateRepository.remove(); |
@@ -129,3 +129,3 @@ "use strict"; | ||
// Do not await the result, this is a fire and forget operation | ||
this.apiClient.sendTelemetryEvent("SignInWithOpenPassButtonShown"); | ||
this.apiClient.sendClientTelemetryEvent("SignInWithOpenPassButtonShown"); | ||
} | ||
@@ -132,0 +132,0 @@ } |
@@ -34,6 +34,7 @@ "use strict"; | ||
SSO_DEVICE_TOKEN_PATH: "/v1/api/device-token", | ||
SSO_TELEMETRY_EVENT_PATH: "/v1/api/telemetry/event", | ||
SSO_CLIENT_TELEMETRY_EVENT_PATH: "/v1/api/telemetry/event", | ||
SSO_SDK_TELEMETRY_EVENT_PATH: "/v1/api/telemetry/sdk-event", | ||
SSO_STORAGE_PREFIX: "__openpass", | ||
API_DEFAULT_TIMEOUT_MS: 60 * 1000, | ||
POPUP_RESPONSE_TIMEOUT_MS: 10 * 60 * 1000, //the timeout to receive a response from the popup | ||
POPUP_RESPONSE_TIMEOUT_MS: 10 * 60 * 1000, // The timeout to receive a response from the popup | ||
}; | ||
@@ -40,0 +41,0 @@ const getOpenPassApiBaseUrl = (baseUrl) => { |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "4.7.0", | ||
"version": "4.7.1-pre-release", | ||
"repository": { | ||
@@ -72,3 +72,3 @@ "type": "git", | ||
"@percy/playwright": "^1.0.4", | ||
"@playwright/test": "^1.40.0", | ||
"@playwright/test": "^1.49.1", | ||
"@testing-library/dom": "^8.0.0", | ||
@@ -75,0 +75,0 @@ "@types/ejs": "^3.1.3", |
@@ -129,3 +129,3 @@ import { joinPaths } from "../utils/path"; | ||
} | ||
async sendTelemetryEvent(eventType) { | ||
async sendClientTelemetryEvent(eventType) { | ||
const headers = {}; | ||
@@ -139,8 +139,28 @@ headers[HEADER_SDK_NAME] = SDK_NAME; | ||
}; | ||
await fetchRequest(this.resolveUri(config.SSO_TELEMETRY_EVENT_PATH), { | ||
await fetchRequest(this.resolveUri(config.SSO_CLIENT_TELEMETRY_EVENT_PATH), { | ||
method: "POST", | ||
headers: headers, | ||
body: JSON.stringify(payload), | ||
timeout: getApiDefaultTimeoutMs(), | ||
}); | ||
} | ||
async sendSdkTelemetryEvent(eventType, eventName, message, stackTrace) { | ||
const headers = {}; | ||
headers[HEADER_SDK_NAME] = SDK_NAME; | ||
headers[HEADER_SDK_VERSION] = sdkVersion; | ||
headers["Content-Type"] = "application/json"; | ||
const payload = { | ||
client_id: this.options.clientId, | ||
event_type: eventType, | ||
event_name: eventName, | ||
message: message, | ||
stack_trace: stackTrace, | ||
}; | ||
await fetchRequest(this.resolveUri(config.SSO_SDK_TELEMETRY_EVENT_PATH), { | ||
method: "POST", | ||
headers: headers, | ||
body: JSON.stringify(payload), | ||
timeout: getApiDefaultTimeoutMs(), | ||
}); | ||
} | ||
resolveUri(uri) { | ||
@@ -147,0 +167,0 @@ const baseUri = this.options.baseUrl || config.SSO_BASE_URL; |
@@ -141,3 +141,3 @@ import { getOpenPassApiBaseUrl } from "../config"; | ||
// Do not await the result, this is a fire and forget operation | ||
this.apiClient.sendTelemetryEvent("SignInWithOpenPassInlineFormShown"); | ||
this.apiClient.sendClientTelemetryEvent("SignInWithOpenPassInlineFormShown"); | ||
} | ||
@@ -144,0 +144,0 @@ createIframeElement(clientId, inlineSignInOptions) { |
@@ -11,2 +11,3 @@ import { config, getOpenPassApiBaseUrl } from "../config"; | ||
import AbortablePromise from "./utils/abortablePromise"; | ||
import { sendSdkTelemetryErrorEvent } from "./utils/sdkTelemetry"; | ||
const POPUP_HEIGHT = 586; | ||
@@ -24,5 +25,5 @@ const POPUP_WIDTH = 428; | ||
export default class PopupAuth { | ||
constructor(OpenPassOptions, redirectApi, openPassClient) { | ||
this.openPassOptions = OpenPassOptions; | ||
this.openPassClient = openPassClient; | ||
constructor(openPassOptions, redirectApi, openPassApiClient) { | ||
this.openPassOptions = openPassOptions; | ||
this.openPassApiClient = openPassApiClient; | ||
this.redirectApi = redirectApi; | ||
@@ -97,2 +98,5 @@ } | ||
if (!(e instanceof AuthCancelledError)) { | ||
// Only send telemetry events if the error is not due to the user closing the popup | ||
sendSdkTelemetryErrorEvent("PopupAuth.doLogin", e, this.openPassApiClient); | ||
// Close the popup if an error occurs | ||
this.closePopupIfExists(authWindow); | ||
@@ -111,3 +115,3 @@ } | ||
} | ||
const openPassTokens = await this.openPassClient.exchangeAuthCodeForTokens(authCodeResponse.code, authSession); | ||
const openPassTokens = await this.openPassApiClient.exchangeAuthCodeForTokens(authCodeResponse.code, authSession); | ||
return await this.completeAuthentication(authWindow, openPassTokens, authSession); | ||
@@ -114,0 +118,0 @@ } |
@@ -32,3 +32,3 @@ import { getOpenPassApiBaseUrl } from "../config"; | ||
} | ||
this.apiClient.sendTelemetryEvent("SignInWithOpenPassQuickSignShown"); | ||
this.apiClient.sendClientTelemetryEvent("SignInWithOpenPassQuickSignShown"); | ||
}; | ||
@@ -192,3 +192,3 @@ this.hideInstantly = () => { | ||
this.hideInstantly(); | ||
this.apiClient.sendTelemetryEvent("SignInWithOpenPassQuickSignDismissed"); | ||
this.apiClient.sendClientTelemetryEvent("SignInWithOpenPassQuickSignDismissed"); | ||
} | ||
@@ -195,0 +195,0 @@ createHiddenQuickAuthIframe(clientId, parentContainer) { |
@@ -8,2 +8,3 @@ import { config, getOpenPassApiBaseUrl } from "../config"; | ||
import { AuthError, SdkError } from "./error/errors"; | ||
import { sendSdkTelemetryErrorEvent } from "./utils/sdkTelemetry"; | ||
/** | ||
@@ -15,4 +16,4 @@ * Class which handles the redirect authorization flow. | ||
export default class RedirectAuth { | ||
constructor(OpenPassOptions, signInStateRepository, openPassAuthClient) { | ||
this.openPassOptions = OpenPassOptions; | ||
constructor(openPassOptions, signInStateRepository, openPassAuthClient) { | ||
this.openPassOptions = openPassOptions; | ||
this.openPassApiClient = openPassAuthClient; | ||
@@ -90,2 +91,6 @@ this.signInStateRepository = signInStateRepository; | ||
} | ||
catch (error) { | ||
sendSdkTelemetryErrorEvent("RedirectAuth.handleAuthenticationRedirect", error, this.openPassApiClient); | ||
throw error; | ||
} | ||
finally { | ||
@@ -92,0 +97,0 @@ this.signInStateRepository.remove(); |
@@ -126,5 +126,5 @@ import { createSignInButton } from "./embedded-assets/html"; | ||
// Do not await the result, this is a fire and forget operation | ||
this.apiClient.sendTelemetryEvent("SignInWithOpenPassButtonShown"); | ||
this.apiClient.sendClientTelemetryEvent("SignInWithOpenPassButtonShown"); | ||
} | ||
} | ||
//# sourceMappingURL=signInButton.js.map |
@@ -8,6 +8,7 @@ import * as consts from "./auth/constants"; | ||
SSO_DEVICE_TOKEN_PATH: "/v1/api/device-token", | ||
SSO_TELEMETRY_EVENT_PATH: "/v1/api/telemetry/event", | ||
SSO_CLIENT_TELEMETRY_EVENT_PATH: "/v1/api/telemetry/event", | ||
SSO_SDK_TELEMETRY_EVENT_PATH: "/v1/api/telemetry/sdk-event", | ||
SSO_STORAGE_PREFIX: "__openpass", | ||
API_DEFAULT_TIMEOUT_MS: 60 * 1000, | ||
POPUP_RESPONSE_TIMEOUT_MS: 10 * 60 * 1000, //the timeout to receive a response from the popup | ||
POPUP_RESPONSE_TIMEOUT_MS: 10 * 60 * 1000, // The timeout to receive a response from the popup | ||
}; | ||
@@ -14,0 +15,0 @@ export const getOpenPassApiBaseUrl = (baseUrl) => { |
import { AuthSession } from "../internalTypes"; | ||
import { OpenPassOptions, OpenPassTokens } from "../../types"; | ||
import { ClientTelemetryEventType, AuthorizeDeviceResponse, DeviceTokenWithStatusResponse } from "./types"; | ||
import { ClientTelemetryEventType, AuthorizeDeviceResponse, DeviceTokenWithStatusResponse, SdkTelemetryEventType } from "./types"; | ||
/** | ||
@@ -13,3 +13,4 @@ * Holds all methods that call the OpenPass API | ||
deviceToken(clientId: string, deviceCode: string): Promise<DeviceTokenWithStatusResponse>; | ||
sendTelemetryEvent(eventType: ClientTelemetryEventType): Promise<void>; | ||
sendClientTelemetryEvent(eventType: ClientTelemetryEventType): Promise<void>; | ||
sendSdkTelemetryEvent(eventType: SdkTelemetryEventType, eventName: string, message: string, stackTrace: string): Promise<void>; | ||
private resolveUri; | ||
@@ -16,0 +17,0 @@ private isErrorResponse; |
@@ -0,1 +1,2 @@ | ||
export type SdkTelemetryEventType = "Error" | "Info"; | ||
export type ClientTelemetryEventType = "SignInWithOpenPassButtonShown" | "SignInWithOpenPassInlineFormShown" | "SignInWithOpenPassQuickSignShown" | "SignInWithOpenPassQuickSignDismissed"; | ||
@@ -2,0 +3,0 @@ export interface TokenRequest { |
@@ -17,6 +17,6 @@ import { OpenPassApiClient } from "./api/openPassApiClient"; | ||
private readonly redirectApi; | ||
private readonly openPassClient; | ||
private readonly openPassApiClient; | ||
private readonly openPassOptions; | ||
private popupWindow?; | ||
constructor(OpenPassOptions: OpenPassOptions, redirectApi: RedirectAuth, openPassClient: OpenPassApiClient); | ||
constructor(openPassOptions: OpenPassOptions, redirectApi: RedirectAuth, openPassApiClient: OpenPassApiClient); | ||
refocusIfPopupExists(): boolean; | ||
@@ -23,0 +23,0 @@ signInWithPopup(options: InternalPopupSignInOptions): Promise<SignInResponse>; |
@@ -14,3 +14,3 @@ import { OpenPassApiClient } from "./api/openPassApiClient"; | ||
private readonly openPassOptions; | ||
constructor(OpenPassOptions: OpenPassOptions, signInStateRepository: SignInStateRepository, openPassAuthClient: OpenPassApiClient); | ||
constructor(openPassOptions: OpenPassOptions, signInStateRepository: SignInStateRepository, openPassAuthClient: OpenPassApiClient); | ||
/** | ||
@@ -17,0 +17,0 @@ * Initiate the login flow by redirecting to the authorization server |
@@ -7,3 +7,4 @@ export declare const config: { | ||
SSO_DEVICE_TOKEN_PATH: string; | ||
SSO_TELEMETRY_EVENT_PATH: string; | ||
SSO_CLIENT_TELEMETRY_EVENT_PATH: string; | ||
SSO_SDK_TELEMETRY_EVENT_PATH: string; | ||
SSO_STORAGE_PREFIX: string; | ||
@@ -10,0 +11,0 @@ API_DEFAULT_TIMEOUT_MS: number; |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "4.7.0", | ||
"version": "4.7.1-pre-release", | ||
"repository": { | ||
@@ -72,3 +72,3 @@ "type": "git", | ||
"@percy/playwright": "^1.0.4", | ||
"@playwright/test": "^1.40.0", | ||
"@playwright/test": "^1.49.1", | ||
"@testing-library/dom": "^8.0.0", | ||
@@ -75,0 +75,0 @@ "@types/ejs": "^3.1.3", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
679094
192
6328
2