performance.mark("js-parse-end:27493-fc2daf7119ca7d8f.js"); "use strict";(globalThis.webpackChunk_github_ui_github_ui=globalThis.webpackChunk_github_ui_github_ui||[]).push([["27493"],{4644(t,e,i){i.r(e),i.d(e,{SudoCredentialOptionsElement:()=>g});var s=i(31635),a=i(94571),o=i(13511),r=i(40845),n=i(74043),l=i(46131),h=i(5045);let u="webauthn",d="password",b="github_mobile",p="email";class g extends HTMLElement{static attrPrefix="";#t;connectedCallback(){let t=this.initialState;this.#t=t,this.reRenderPrompt(!0)}reRenderPrompt(t=!1){this.resetPrompt();try{switch(this.#t){case u:this.renderWebauthnOption();break;case b:this.renderGitHubMobileOption(t);break;case"app":this.renderTotpAppOption();break;case p:this.renderTotpEmailOption();break;default:this.renderPasswordOption()}this.reRenderNavContainer()}catch(t){this.handleUnexpectedPromptError(t)}}handleUnexpectedPromptError(t){let e="";if(e=this.#t===b?this.githubMobileGenericErrorMessage:this.genericErrorMessage,t&&this.#t!==d)throw this.renderPasswordOptionWithError(e),t}renderPasswordOptionWithError(t){this.showPassword(),this.showErrorMessage(t)}resetPrompt(){this.hideErrorMessage(),this.isWebAuthnAvailable()&&this.hideWebAuthn(),this.isGitHubMobileAvailable()&&this.hideGitHubMobile(),this.isTotpAppAvailable()&&this.hideTotpApp(),this.isTotpEmailAvailable()&&this.hideTotpEmail(),this.hidePassword()}hideWebAuthn(){this.safeSetElementVisibility(this.webauthnContainer,!1),this.safeSetElementVisibility(this.webauthnNav,!1)}hideGitHubMobile(){this.safeSetElementVisibility(this.githubMobileContainer,!1),this.safeSetElementVisibility(this.githubMobileNav,!1),this.safeSetElementVisibility(this.githubMobileLoading,!1),this.safeSetElementVisibility(this.githubMobileLanding,!1)}hideTotpApp(){this.safeSetElementVisibility(this.totpAppContainer,!1),this.safeSetElementVisibility(this.totpAppNav,!1)}hideTotpEmail(){this.safeSetElementVisibility(this.totpEmailContainer,!1),this.safeSetElementVisibility(this.totpEmailNav,!1)}hidePassword(){this.safeSetElementVisibility(this.passwordContainer,!1),this.safeSetElementVisibility(this.passwordNav,!1)}reRenderNavContainer(){this.isWebAuthnAvailable()&&this.#t!==u&&this.safeSetElementVisibility(this.webauthnNav,!0),this.isGitHubMobileAvailable()&&this.#t!==b&&this.safeSetElementVisibility(this.githubMobileNav,!0),this.isTotpAppAvailable()&&"app"!==this.#t&&this.safeSetElementVisibility(this.totpAppNav,!0),this.isTotpEmailAvailable()&&this.#t!==p&&this.safeSetElementVisibility(this.totpEmailNav,!0),this.#t!==d&&this.safeSetElementVisibility(this.passwordNav,!0)}renderWebauthnOption(){this.safeSetElementVisibility(this.webauthnContainer,!0),this.webauthnGet?.setState((0,n.$j)()?o.U.Ready:o.U.Unsupported)}renderGitHubMobileOption(t){try{(0,r.s)()}catch{}t?(this.safeSetElementVisibility(this.githubMobileLoading,!1),this.safeSetElementVisibility(this.githubMobileLanding,!0),this.safeSetElementVisibility(this.githubMobileContainer,!1)):(this.safeSetElementVisibility(this.githubMobileLoading,!0),this.safeSetElementVisibility(this.githubMobileLanding,!1),this.safeSetElementVisibility(this.githubMobileContainer,!1),this.initiateGitHubMobileAuthRequest())}renderTotpAppOption(){this.safeSetElementVisibility(this.totpAppContainer,!0)}renderTotpEmailOption(){this.safeSetElementVisibility(this.totpEmailContainer,!0)}renderPasswordOption(){this.safeSetElementVisibility(this.passwordContainer,!0),this.loginField?this.loginField.focus():this.passwordField?.focus()}hasMultipleOptions(){return this.isWebAuthnAvailable()||this.isGitHubMobileAvailable()||this.isTotpAppAvailable()||this.isTotpEmailAvailable()}isWebAuthnAvailable(){return"true"===this.webauthnAvailable}isGitHubMobileAvailable(){return"true"===this.githubMobileAvailable}isTotpAppAvailable(){return"true"===this.totpAppAvailable}isTotpEmailAvailable(){return"true"===this.totpEmailAvailable}showWebauthn(){this.#t=u,this.reRenderPrompt()}showGitHubMobile(){this.#t=b,this.reRenderPrompt()}showTotpApp(){this.#t="app",this.reRenderPrompt()}showTotpEmail(){this.#t=p,this.reRenderPrompt()}showEmailConfirm(){if(this.#t!==p)return;let t=document.getElementById("email-landing-container"),e=document.getElementById("sudo-send-email");this.safeSetElementVisibility(t,!1),e?.setAttribute("disabled","true");let i=document.getElementById("email-confirm-container");this.safeSetElementVisibility(i,!0)}showPassword(){this.#t=d,this.reRenderPrompt()}githubMobileRetry(t){t.preventDefault(),this.showGitHubMobile()}async initiateGitHubMobileAuthRequest(){let t=this.githubMobilePromptUrl,e=document.getElementById("sudo-credential-options-github-mobile-csrf").value,i=new FormData;i.append("authenticity_token",e);try{let e=await fetch(t,{method:"POST",headers:{...(0,h.kt)()},body:i});if(!e.ok&&this.#t===b)return void this.mobileFailHandler(this.githubMobileGenericErrorMessage);let s=await e.json(),a=!!s.challenge;this.safeSetElementVisibility(this.githubMobileNoChallengeMessage,!a),this.safeSetElementVisibility(this.githubMobileChallengeMessage,a),this.safeSetElementVisibility(this.githubMobileChallengeValue,a),a&&(this.githubMobileChallengeValue.textContent=s.challenge);let o=document.getElementsByClassName("js-poll-github-mobile-sudo-authenticate")[0];(0,r.R1)(o,()=>this.mobileApprovedHandler(),t=>this.mobileFailHandler(t),()=>this.mobileCancelCheck())}catch{this.#t===b&&this.mobileFailHandler(this.githubMobileGenericErrorMessage)}finally{this.#t===b&&(this.safeSetElementVisibility(this.githubMobileLoading,!1),this.safeSetElementVisibility(this.githubMobileContainer,!0))}}mobileApprovedHandler(){if(this.#t===b){let t=this.githubMobileContainer.getElementsByTagName("form")[0];(0,l.k_)(t)}}mobileFailHandler(t){this.#t===b&&(this.showErrorMessage(t),(0,r.Cg)())}mobileCancelCheck(){return this.#t!==b}async initiateTotpEmailRequest(){let t=this.totpEmailInitiateUrl,e=document.getElementById("sudo-credential-options-totp-email-csrf").value,i=new FormData;i.append("authenticity_token",e);try{if(!(await fetch(t,{method:"POST",headers:{...(0,h.kt)()},body:i})).ok&&this.#t===p)return}catch{return}this.showEmailConfirm()}safeSetElementVisibility(t,e){return!!t&&(t.hidden=!e,!0)}showErrorMessage(t){this.flashErrorMessageText&&(this.flashErrorMessageText.textContent=t,this.safeSetElementVisibility(this.flashErrorMessageContainer,!0))}hideErrorMessage(){this.flashErrorMessageText&&(this.flashErrorMessageText.textContent=""),this.safeSetElementVisibility(this.flashErrorMessageContainer,!1)}}(0,s.Cg)([a.CF],g.prototype,"initialState",void 0),(0,s.Cg)([a.CF],g.prototype,"webauthnAvailable",void 0),(0,s.Cg)([a.CF],g.prototype,"githubMobileAvailable",void 0),(0,s.Cg)([a.CF],g.prototype,"totpAppAvailable",void 0),(0,s.Cg)([a.CF],g.prototype,"totpEmailAvailable",void 0),(0,s.Cg)([a.CF],g.prototype,"githubMobilePromptUrl",void 0),(0,s.Cg)([a.CF],g.prototype,"githubMobileGenericErrorMessage",void 0),(0,s.Cg)([a.CF],g.prototype,"totpEmailInitiateUrl",void 0),(0,s.Cg)([a.CF],g.prototype,"genericErrorMessage",void 0),(0,s.Cg)([a.aC],g.prototype,"flashErrorMessageContainer",void 0),(0,s.Cg)([a.aC],g.prototype,"flashErrorMessageText",void 0),(0,s.Cg)([a.aC],g.prototype,"webauthnContainer",void 0),(0,s.Cg)([a.aC],g.prototype,"githubMobileContainer",void 0),(0,s.Cg)([a.aC],g.prototype,"githubMobileLoading",void 0),(0,s.Cg)([a.aC],g.prototype,"githubMobileLanding",void 0),(0,s.Cg)([a.aC],g.prototype,"totpAppContainer",void 0),(0,s.Cg)([a.aC],g.prototype,"totpEmailContainer",void 0),(0,s.Cg)([a.aC],g.prototype,"passwordContainer",void 0),(0,s.Cg)([a.aC],g.prototype,"githubMobileNoChallengeMessage",void 0),(0,s.Cg)([a.aC],g.prototype,"githubMobileChallengeMessage",void 0),(0,s.Cg)([a.aC],g.prototype,"githubMobileChallengeValue",void 0),(0,s.Cg)([a.aC],g.prototype,"webauthnNav",void 0),(0,s.Cg)([a.aC],g.prototype,"githubMobileNav",void 0),(0,s.Cg)([a.aC],g.prototype,"totpAppNav",void 0),(0,s.Cg)([a.aC],g.prototype,"totpEmailNav",void 0),(0,s.Cg)([a.aC],g.prototype,"passwordNav",void 0),(0,s.Cg)([a.aC],g.prototype,"webauthnGet",void 0),(0,s.Cg)([a.aC],g.prototype,"loginField",void 0),(0,s.Cg)([a.aC],g.prototype,"passwordField",void 0),g=(0,s.Cg)([(0,a.p_)("sudo-credential-options")],g)},40845(t,e,i){i.d(e,{Cg:()=>l,R1:()=>b,s:()=>h});var s=i(85498),a=i(21403),o=i(5045);let r="github-mobile-auth-flash";function n(){let t=document.querySelector("#js-flash-container");if(t)for(let e of t.children)!e.classList.contains("js-flash-template")&&e.classList.contains(r)&&t.removeChild(e)}function l(){let t=document.getElementById("github-mobile-authenticate-prompt");t&&(t.hidden=!0);let e=document.getElementById("github-mobile-authenticate-error-and-retry");e&&(e.hidden=!1)}function h(){n();let t=document.getElementById("github-mobile-authenticate-prompt");t&&(t.hidden=!1);let e=document.getElementById("github-mobile-authenticate-error-and-retry");e&&(e.hidden=!0)}function u(t){let e,i,a;t&&(e=new s.TemplateInstance(document.querySelector("template.js-flash-template"),{className:`flash-error ${r}`,message:t}),i=document.importNode(e,!0),(a=document.querySelector("#js-flash-container"))&&(n(),a.appendChild(i))),l()}function d(t){return document.getElementById("github-mobile-authenticate-error-and-retry").getAttribute(t)}async function b(t,e,i,s){try{var a;await (a=t.getAttribute("data-poll-url"),async function t(r){let n,l,h,b;if(s&&s())return;let p="STATUS_UNKNOWN";try{let t=document.getElementById("github-mobile-authenticate-form"),e=t.querySelector(".js-data-url-csrf"),i=await self.fetch(new Request(a,{method:"POST",body:new FormData(t),mode:"same-origin",headers:{Accept:"application/json","Scoped-CSRF-Token":e.value,...(0,o.kt)()}}));if(i.ok){let t=await i.json();p=t.status,n=t.token,l=t.sign_in_method}else p="STATUS_ERROR"}catch{p="STATUS_ERROR"}switch(p){case"STATUS_APPROVED":var g,c;return e?e():(g=n,c=l,void((b=g?new URL(`password_reset/${encodeURIComponent(g)}`,window.location.origin):new URL("",window.location.href)).searchParams.set("redirect","true"),c&&b.searchParams.set("sign_in_method",c),window.location.assign(b)));case"STATUS_EXPIRED":return h=d("timeout-flash"),i?i(h):u(h);case"STATUS_ACTIVE":case"STATUS_ERROR":case"STATUS_UNKNOWN":break;case"STATUS_REJECTED":return h=d("error-flash"),i?i(h):void document.getElementById("github-mobile-rejected-redirect").click();default:return h=d("error-flash"),i?i(h):u(h)}await new Promise(t=>setTimeout(t,3e3)),t(r)}(0))}catch{return u(d("error-flash"))}}(0,a.lB)(".js-poll-github-mobile-two-factor-authenticate",function(t){b(t)}),(0,a.lB)(".js-poll-github-mobile-verified-device-authenticate",function(t){b(t)}),(0,a.lB)(".js-poll-github-mobile-two-factor-password-reset-authenticate",function(t){b(t)})},13511(t,e,i){i.d(e,{U:()=>l});var s=i(31635),a=i(94571),o=i(74043),r=i(46131),n=i(73537);let l={Initializing:"initializing",Unsupported:"unsupported",Ready:"ready",Waiting:"waiting",Error:"error",Submitting:"submitting"};class h extends HTMLElement{state=l.Initializing;static attrPrefix="";dataJson="";subtleLogin=!1;hasErrored=!1;async connectedCallback(){this.originalButtonText=this.getCurrentButtonText(),this.originalErrorText=this.errorText.textContent,this.setState((0,o.$j)()?l.Ready:l.Unsupported),this.passkeySupport=await window.PublicKeyCredential?.isUserVerifyingPlatformAuthenticatorAvailable(),this.state!==l.Unsupported&&!this.passkeySupport&&this.passkeysUnsupportedMessage&&(this.passkeysUnsupportedMessage.hidden=!1),this.subtleLogin?this.handleWebauthnSubtle():this.showWebauthnLoginFragment()}handleWebauthnSubtle(){let t=document.querySelector(".js-webauthn-subtle");t&&(t.hidden=!1,this.updateWebauthnSubtleParentBoxVisibility(!1),t.addEventListener("webauthn-subtle-submit",()=>{this.showWebauthnLoginFragment(),this.state!==l.Unsupported&&this.prompt()}))}showWebauthnLoginFragment(){let t=document.querySelector(".js-webauthn-login-section");if(!t)return;t.hidden=!1;let e=document.querySelector(".js-webauthn-login-divider");e&&(e.hidden=!1,this.updateWebauthnSubtleParentBoxVisibility(!0))}updateWebauthnSubtleParentBoxVisibility(t){let e=document.querySelector(".js-webauthn-hint");e&&(e.hidden=t)}getCurrentButtonText(){return this.buttonText.textContent||""}setCurrentButtonText(t){this.buttonText.textContent=t}setState(t){let e=this.button.getAttribute("data-retry-message")||this.originalButtonText,i=this.hasErrored?e:this.originalButtonText;for(let t of(this.setCurrentButtonText(i),this.button.disabled=!1,this.button.hidden=!1,this.errorText.textContent="",this.messages))t.hidden=!0;switch(t){case l.Initializing:this.button.disabled=!0;break;case l.Unsupported:this.button.disabled=!0,this.unsupportedMessage.hidden=!1,this.passkeysUnsupportedMessage&&(this.passkeysUnsupportedMessage.hidden=!0);break;case l.Ready:break;case l.Waiting:this.waitingMessage.hidden=!1,this.button.hidden=!0;break;case l.Error:this.errorMessage.hidden=!1,this.errorText.textContent=this.originalErrorText;break;case l.Submitting:this.setCurrentButtonText("Verifying\u2026"),this.button.disabled=!0;break;default:throw Error("invalid state")}this.state=t}async prompt(t,e){t?.preventDefault(),this.dispatchEvent(new CustomEvent("webauthn-get-prompt"));try{if(e||this.setState(l.Waiting),(0,n.G7)("migrate_away_from_webauthn_json")){let t=JSON.parse(this.dataJson).publicKey,e=PublicKeyCredential.parseRequestOptionsFromJSON(t),i=await navigator.credentials.get({publicKey:e});this.setState(l.Submitting);let s=this.closest(".js-webauthn-form");s.querySelector(".js-webauthn-response").value=JSON.stringify(i.toJSON()),(0,r.k_)(s)}else{let t=JSON.parse(this.dataJson),e=(0,o.d5)(t),i=await (0,o.Jt)(e);this.setState(l.Submitting);let s=this.closest(".js-webauthn-form");s.querySelector(".js-webauthn-response").value=JSON.stringify(i),(0,r.k_)(s)}}catch(t){if(!e)throw this.hasErrored=!0,this.setState(l.Error),t}}}(0,s.Cg)([a.aC],h.prototype,"button",void 0),(0,s.Cg)([a.aC],h.prototype,"buttonText",void 0),(0,s.Cg)([a.zV],h.prototype,"messages",void 0),(0,s.Cg)([a.aC],h.prototype,"capitalizedDescription",void 0),(0,s.Cg)([a.aC],h.prototype,"unsupportedMessage",void 0),(0,s.Cg)([a.aC],h.prototype,"passkeysUnsupportedMessage",void 0),(0,s.Cg)([a.aC],h.prototype,"waitingMessage",void 0),(0,s.Cg)([a.aC],h.prototype,"errorMessage",void 0),(0,s.Cg)([a.aC],h.prototype,"errorText",void 0),(0,s.Cg)([a.CF],h.prototype,"dataJson",void 0),(0,s.Cg)([a.CF],h.prototype,"subtleLogin",void 0),(0,s.Cg)([(0,a.p_)("webauthn-get")],h)}}]); //# sourceMappingURL=27493-fc2daf7119ca7d8f-6bd13eae9d34d20d.js.map