9958.js (17318B)
1 "use strict";(self.webpackChunkelement_web=self.webpackChunkelement_web||[]).push([[9958],{"./src/components/views/auth/LoginWithQR.tsx"(e,t,n){n.r(t),n.d(t,{LoginWithQRFailureReason:()=>A,default:()=>L});var o=n("../../node_modules/.pnpm/@babel+runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/defineProperty.js"),i=n("../../node_modules/.pnpm/react@19.2.7/node_modules/react/index.js"),s=n("../../node_modules/.pnpm/matrix-js-sdk@41.9.0/node_modules/matrix-js-sdk/src/rendezvous/index.ts"),r=n("../../node_modules/.pnpm/matrix-js-sdk@41.9.0/node_modules/matrix-js-sdk/src/logger.ts"),a=n("../../node_modules/.pnpm/matrix-js-sdk@41.9.0/node_modules/matrix-js-sdk/src/matrix.ts"),c=n("../../node_modules/.pnpm/matrix-js-sdk@41.9.0/node_modules/matrix-js-sdk/src/utils.ts"),l=n("../../node_modules/.pnpm/matrix-js-sdk@41.9.0/node_modules/matrix-js-sdk/src/randomstring.ts"),d=n("./src/components/views/auth/LoginWithQR-types.ts"),_=n("../../node_modules/.pnpm/@vector-im+compound-design-tokens@10.2.1_@types+react@19.2.14_react@19.2.7/node_modules/@vector-im/compound-design-tokens/assets/web/icons/chevron-left.js"),h=n("../../node_modules/.pnpm/@vector-im+compound-design-tokens@10.2.1_@types+react@19.2.14_react@19.2.7/node_modules/@vector-im/compound-design-tokens/assets/web/icons/check-circle-solid.js"),u=n("../../node_modules/.pnpm/@vector-im+compound-design-tokens@10.2.1_@types+react@19.2.14_react@19.2.7/node_modules/@vector-im/compound-design-tokens/assets/web/icons/error-solid.js"),m=n("../../node_modules/.pnpm/@vector-im+compound-web@9.7.1_@fontsource+inconsolata@5.2.8_@fontsource+inter@5.2.8_@ty_d0b9248e7924d8975cc2a582ba698967/node_modules/@vector-im/compound-web/dist/components/Button/Button.js"),p=n("../../node_modules/.pnpm/@vector-im+compound-web@9.7.1_@fontsource+inconsolata@5.2.8_@fontsource+inter@5.2.8_@ty_d0b9248e7924d8975cc2a582ba698967/node_modules/@vector-im/compound-web/dist/components/Typography/Text.js"),g=n("../../node_modules/.pnpm/@vector-im+compound-web@9.7.1_@fontsource+inconsolata@5.2.8_@fontsource+inter@5.2.8_@ty_d0b9248e7924d8975cc2a582ba698967/node_modules/@vector-im/compound-web/dist/components/Icon/BigIcon/BigIcon.js"),v=n("../../node_modules/.pnpm/@vector-im+compound-web@9.7.1_@fontsource+inconsolata@5.2.8_@fontsource+inter@5.2.8_@ty_d0b9248e7924d8975cc2a582ba698967/node_modules/@vector-im/compound-web/dist/components/Typography/Heading.js"),E=n("../../node_modules/.pnpm/@vector-im+compound-web@9.7.1_@fontsource+inconsolata@5.2.8_@fontsource+inter@5.2.8_@ty_d0b9248e7924d8975cc2a582ba698967/node_modules/@vector-im/compound-web/dist/components/Form/Controls/MFA/MFA.js"),w=n("../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"),k=n.n(w),f=n("../../node_modules/.pnpm/@vector-im+compound-design-tokens@10.2.1_@types+react@19.2.14_react@19.2.7/node_modules/@vector-im/compound-design-tokens/assets/web/icons/qr-code.js"),C=n("../../node_modules/.pnpm/@vector-im+compound-design-tokens@10.2.1_@types+react@19.2.14_react@19.2.7/node_modules/@vector-im/compound-design-tokens/assets/web/icons/mobile.js"),b=n("../../node_modules/.pnpm/@vector-im+compound-design-tokens@10.2.1_@types+react@19.2.14_react@19.2.7/node_modules/@vector-im/compound-design-tokens/assets/web/icons/lock-solid.js"),S=n("./src/languageHandler.tsx"),y=n("./src/components/views/elements/AccessibleButton.tsx"),I=n("./src/components/views/elements/QRCode.tsx"),N=n("./src/components/views/elements/Spinner.tsx"),x=n("./src/SdkConfig.ts"),F=n("./src/components/structures/ErrorMessage.tsx");class R extends i.Component{constructor(...e){super(...e),(0,o.A)(this,"checkCodeInput",(0,i.createRef)()),(0,o.A)(this,"handleClick",e=>async t=>{var n;t.preventDefault(),await this.props.onClick(e,e===d.HY.Approve?null===(n=this.checkCodeInput.current)||void 0===n?void 0:n.value:void 0)}),(0,o.A)(this,"cancelButton",()=>i.createElement(m.$,{kind:"primary",size:"lg",onClick:this.handleClick(d.HY.Cancel)},(0,S._t)("action|cancel"))),(0,o.A)(this,"simpleSpinner",e=>i.createElement("div",{className:"mx_LoginWithQR_spinner"},i.createElement("div",null,i.createElement(N.A,null),e&&i.createElement("p",null,e))))}render(){let e,t,n=!0,o="";switch(this.props.phase){case d.a0.Error:{n=!1,t=i.createElement(m.$,{kind:"primary",size:"lg",onClick:this.handleClick(d.HY.ShowQr)},this.props.intent===s.E$.LOGIN_ON_NEW_DEVICE?(0,S._t)("auth|qr_code_login|start_over"):(0,S._t)("action|try_again"));let r,a,c=u.A,l="critical";switch(this.props.failureReason){case s.n$.UnsupportedProtocol:r=(0,S._t)("auth|qr_code_login|error_unsupported_protocol_title"),a=(0,S._t)("auth|qr_code_login|error_unsupported_protocol");break;case s.n$.UserCancelled:r=(0,S._t)("auth|qr_code_login|error_user_cancelled_title"),a=(0,S._t)("auth|qr_code_login|error_user_cancelled"),this.props.intent===s.E$.LOGIN_ON_NEW_DEVICE&&(t=this.cancelButton());break;case s.n$.AuthorizationExpired:case s.fF.Expired:r=(0,S._t)("auth|qr_code_login|error_expired_title"),a=(0,S._t)("auth|qr_code_login|error_expired");break;case s.fF.InsecureChannelDetected:r=(0,S._t)("auth|qr_code_login|error_insecure_channel_detected_title"),a=i.createElement(i.Fragment,null,(0,S._t)("auth|qr_code_login|error_insecure_channel_detected"),i.createElement(p.E,{as:"h2",size:"lg",weight:"semibold"},(0,S._t)("auth|qr_code_login|error_insecure_channel_detected_instructions")),i.createElement("ol",null,i.createElement("li",null,(0,S._t)("auth|qr_code_login|error_insecure_channel_detected_instructions_1")),i.createElement("li",null,(0,S._t)("auth|qr_code_login|error_insecure_channel_detected_instructions_2")),i.createElement("li",null,(0,S._t)("auth|qr_code_login|error_insecure_channel_detected_instructions_3"))));break;case s.fF.OtherDeviceAlreadySignedIn:l="success",c=h.A,r=(0,S._t)("auth|qr_code_login|error_other_device_already_signed_in_title"),a=(0,S._t)("auth|qr_code_login|error_other_device_already_signed_in");break;case s.fF.UserDeclined:r=(0,S._t)("auth|qr_code_login|error_user_declined_title"),a=(0,S._t)("auth|qr_code_login|error_user_declined"),this.props.intent===s.E$.LOGIN_ON_NEW_DEVICE&&(t=this.cancelButton());break;case A.RateLimited:r=(0,S._t)("error|something_went_wrong"),a=(0,S._t)("auth|qr_code_login|error_rate_limited");break;case s.fF.ETagMissing:r=(0,S._t)("error|something_went_wrong"),a=(0,S._t)("auth|qr_code_login|error_etag_missing");break;case s.fF.HomeserverLacksSupport:c=f.A,n=!0,r=(0,S._t)("auth|qr_code_login|unsupported_heading"),a=(0,S._t)("auth|qr_code_login|unsupported_explainer"),this.props.intent===s.E$.LOGIN_ON_NEW_DEVICE&&(t=this.cancelButton());break;case s.n$.DeviceAlreadyExists:case s.n$.DeviceNotFound:case s.n$.UnexpectedMessageReceived:case s.fF.OtherDeviceNotSignedIn:case s.fF.Unknown:default:r=(0,S._t)("error|something_went_wrong"),a=(0,S._t)("auth|qr_code_login|error_unexpected")}o="mx_LoginWithQR_error",e=i.createElement(i.Fragment,null,i.createElement(g.Y,{kind:l},i.createElement(c,null)),i.createElement(v.D,{as:"h1",size:"sm",weight:"semibold"},r),"object"==typeof a?a:i.createElement("p",null,a));break}case d.a0.OutOfBandConfirmation:n=!1,e=i.createElement(i.Fragment,null,this.props.intent===s.E$.LOGIN_ON_NEW_DEVICE&&i.createElement(g.Y,null,i.createElement(C.A,null)),i.createElement(v.D,{as:"h1",size:"sm",weight:"semibold"},(0,S._t)("auth|qr_code_login|check_code_heading")),i.createElement(p.E,{size:"md"},(0,S._t)("auth|qr_code_login|check_code_explainer")),i.createElement("label",{htmlFor:"mx_LoginWithQR_checkCode"},(0,S._t)("auth|qr_code_login|check_code_input_label")),i.createElement(E.f,{className:"mx_LoginWithQR_checkCode_input mx_no_textinput",ref:this.checkCodeInput,length:2,autoFocus:!0,id:"mx_LoginWithQR_checkCode","data-invalid":this.props.failureReason===A.CheckCodeMismatch||void 0}),i.createElement(F.K,{message:this.props.failureReason===A.CheckCodeMismatch?(0,S._t)("auth|qr_code_login|check_code_mismatch"):null})),t=i.createElement(i.Fragment,null,i.createElement(m.$,{kind:"primary",size:"lg",onClick:this.handleClick(d.HY.Approve)},(0,S._t)("action|continue")),i.createElement(m.$,{kind:"tertiary",size:"lg",onClick:this.handleClick(d.HY.Decline)},(0,S._t)("action|cancel")));break;case d.a0.ShowingQR:{let t;t=this.props.intent===s.E$.LOGIN_ON_NEW_DEVICE?[(0,S._t)("auth|qr_code_login|open_element_mobile_device",{brand:x.A.get().brand}),(0,S._t)("auth|qr_code_login|tap_avatar_link_new_device",{linkNewDevice:i.createElement("strong",null,(0,S._t)("settings|sessions|sign_in_with_qr"))}),(0,S._t)("auth|qr_code_login|choose_desktop_computer",{desktopComputer:i.createElement("strong",null,(0,S._t)("auth|qr_code_login|desktop_computer"))}),(0,S._t)("auth|qr_code_login|select_ready_to_scan",{readyToScan:i.createElement("strong",null,(0,S._t)("auth|qr_code_login|ready_to_scan"))}),(0,S._t)("auth|qr_code_login|follow_remaining_instructions")]:[(0,S._t)("auth|qr_code_login|open_element_other_device",{brand:x.A.get().brand}),(0,S._t)("auth|qr_code_login|select_qr_code",{scanQRCode:i.createElement("strong",null,(0,S._t)("auth|qr_code_login|scan_qr_code"))}),(0,S._t)("auth|qr_code_login|point_the_camera"),(0,S._t)("auth|qr_code_login|follow_remaining_instructions")],e=i.createElement(i.Fragment,null,i.createElement(v.D,{as:"h1",size:"sm",weight:"semibold"},this.props.intent===s.E$.LOGIN_ON_NEW_DEVICE?(0,S._t)("auth|qr_code_login|scan_code_instruction"):(0,S._t)("auth|qr_code_login|scan_code_instruction_reciprocate")),i.createElement("div",{className:"mx_LoginWithQR_qrWrapper"},this.props.code?i.createElement(I.A,{data:[{data:this.props.code,mode:"byte"}],width:200}):i.createElement(N.A,null)),i.createElement("ol",null,t.map((e,t)=>i.createElement("li",{key:this.props.intent+t},e))));break}case d.a0.Loading:e=this.simpleSpinner();break;case d.a0.WaitingForDevice:e=this.props.intent===s.E$.LOGIN_ON_NEW_DEVICE?i.createElement(i.Fragment,null,i.createElement(g.Y,null,i.createElement(b.A,null)),i.createElement(v.D,{as:"h1",size:"sm",weight:"semibold"},(0,S._t)("auth|qr_code_login|security_code_title")),i.createElement(p.E,{size:"md"},(0,S._t)("auth|qr_code_login|security_code_prompt")),i.createElement(E.f,{className:"mx_LoginWithQR_checkCode_input mx_no_textinput",length:6,value:this.props.userCode,disabled:!0}),this.simpleSpinner((0,S._t)("auth|qr_code_login|waiting_for_device"))):this.simpleSpinner((0,S._t)("auth|qr_code_login|waiting_for_device")),t=this.cancelButton();break;case d.a0.Verifying:e=this.simpleSpinner((0,S._t)("auth|qr_code_login|completing_setup"))}return i.createElement("div",{className:k()("mx_LoginWithQR",o)},this.props.intent===s.E$.RECIPROCATE_LOGIN_ON_EXISTING_DEVICE&&n?i.createElement("div",{className:"mx_LoginWithQR_heading"},i.createElement(y.A,{className:"mx_LoginWithQR_BackButton",onClick:this.handleClick(d.HY.Cancel),title:(0,S._t)("action|back")},i.createElement(_.A,null)),i.createElement("div",{className:"mx_LoginWithQR_breadcrumbs"},(0,S._t)("settings|sessions|title")," / ",(0,S._t)("settings|sessions|sign_in_with_qr"))):null,i.createElement("div",{className:"mx_LoginWithQR_main"},e),i.createElement("div",{className:"mx_LoginWithQR_buttons"},t))}}var q=n("./src/utils/oidc/registerClient.ts");let A=function(e){return e.RateLimited="rate_limited",e.CheckCodeMismatch="check_code_mismatch",e}({});class L extends i.Component{constructor(e){var t,n;super(e),(0,o.A)(this,"finished",!1),(0,o.A)(this,"abortController",void 0),(0,o.A)(this,"generateAndShowCode",async e=>{let t;try{if(t=this.props.intent===s.E$.LOGIN_ON_NEW_DEVICE?await(0,s.tS)(this.props.client,this.onFailure,e.signal):await(0,s.lS)(this.props.client,this.onFailure,e.signal),e.signal.aborted)return;this.setState({phase:d.a0.ShowingQR,rendezvous:t,failureReason:void 0})}catch(t){if(e.signal.aborted)return;return r.vF.error("Error whilst generating QR code",t),void this.setState({phase:d.a0.Error,failureReason:s.fF.HomeserverLacksSupport})}try{if(this.props.intent===s.E$.RECIPROCATE_LOGIN_ON_EXISTING_DEVICE){await t.negotiateProtocols();const{verificationUri:e}=await t.deviceAuthorizationGrant();this.setState({phase:d.a0.OutOfBandConfirmation,verificationUri:e})}else{const{serverName:e}=await t.negotiateProtocols(),{homeserverUrl:n,identityServerUrl:o}=await async function(e){var t,n,o,i;if(e.startsWith("http://")||e.startsWith("https://"))return{homeserverUrl:e};const s=await a.AutoDiscovery.findClientConfig(e);return{homeserverUrl:null!==(t=null==s||null===(n=s["m.homeserver"])||void 0===n?void 0:n.base_url)&&void 0!==t?t:void 0,identityServerUrl:null!==(o=null==s||null===(i=s["m.identity_server"])||void 0===i?void 0:i.base_url)&&void 0!==o?o:void 0}}(e);if(!n)throw this.setState({phase:d.a0.Error,failureReason:s.fF.Unknown}),r.vF.error("Failed to discover homeserver URL"),new Error("Failed to discover homeserver URL");let i,c;try{if(i=await new a.MatrixClient({baseUrl:n}).getAuthMetadata(),!i.grant_types_supported.includes(a.OAuthGrantType.DeviceAuthorization))throw new Error("Server does not support Device Authorization Grant");c=await(0,q.S)(i,x.A.get().oidc_static_clients)}catch(e){throw this.setState({phase:d.a0.Error,failureReason:s.fF.HomeserverLacksSupport}),r.vF.error("Failed to register OIDC Client ID",e),new Error("Failed to register OIDC Client ID",{cause:e})}this.setState({phase:d.a0.OutOfBandConfirmation,loginServerDetails:{homeserverUrl:n,identityServerUrl:o,metadata:i,clientId:c}})}}catch(n){if(e.signal.aborted)return;r.vF.error("Error whilst approving login",n),await t.cancel(n instanceof s.Qd?n.code:s.fF.Unknown)}}),(0,o.A)(this,"approveLogin",async e=>{var t;if(!(this.state.rendezvous instanceof s.G_))throw this.setState({phase:d.a0.Error,failureReason:s.fF.Unknown}),new Error("Rendezvous not found");if((null===(t=this.state.rendezvous)||void 0===t?void 0:t.checkCode)===e)try{if(this.props.intent===s.E$.RECIPROCATE_LOGIN_ON_EXISTING_DEVICE)this.setState({phase:d.a0.Loading}),this.state.verificationUri&&window.open(this.state.verificationUri,"_blank"),this.setState({phase:d.a0.WaitingForDevice}),await this.state.rendezvous.shareSecrets(),this.onFinished(!0);else{if(!this.state.loginServerDetails)throw this.setState({phase:d.a0.Error,failureReason:s.fF.Unknown}),new Error("Server details not found in state");const{homeserverUrl:e,identityServerUrl:t,clientId:n,metadata:o}=this.state.loginServerDetails,i=(0,l.US)(10),{userCode:r}=await this.state.rendezvous.deviceAuthorizationGrant({metadata:o,clientId:n,deviceId:i});this.setState({phase:d.a0.WaitingForDevice,userCode:r});const a=await this.state.rendezvous.completeLoginOnNewDevice({clientId:n});if(a){const{secrets:s}=await this.state.rendezvous.shareSecrets();await this.props.onLoggedIn({accessToken:a.access_token,refreshToken:a.refresh_token,homeserverUrl:e,clientId:n,idToken:a.id_token,issuer:o.issuer,identityServerUrl:t,secrets:s,deviceId:i}),this.onFinished(!0)}}}catch(e){r.vF.error("Error whilst approving sign in",e),this.setState({phase:d.a0.Error,failureReason:e instanceof s.Qd?e.code:s.fF.Unknown})}else this.setState({failureReason:A.CheckCodeMismatch})}),(0,o.A)(this,"onFailure",async e=>{if(this.state.phase!==d.a0.Error){if(r.vF.warn(`Rendezvous failed: ${e}`),e===s.fF.Expired&&this.state.phase===d.a0.ShowingQR)try{return this.reset(),await(0,c.yy)(1e3),void await this.updateMode(d.Kt.Show,!1)}catch(e){r.vF.warn("Failed to re-roll qr code on expiry",e)}this.setState({phase:d.a0.Error,failureReason:e})}}),(0,o.A)(this,"onClick",async(e,t)=>{var n;switch(e){case d.HY.Cancel:await(null===(n=this.state.rendezvous)||void 0===n?void 0:n.cancel(s.n$.UserCancelled)),this.onFinished(!1);break;case d.HY.Approve:await this.approveLogin(t);break;case d.HY.Decline:var o,i;if(this.props.intent===s.E$.LOGIN_ON_NEW_DEVICE)await(null===(o=this.state.rendezvous)||void 0===o?void 0:o.cancel(s.n$.UserCancelled));else await(null===(i=this.state.rendezvous)||void 0===i?void 0:i.declineLoginOnExistingDevice());this.onFinished(!1);break;case d.HY.ShowQr:await this.updateMode(d.Kt.Show)}}),this.state={phase:d.a0.Loading},null===(t=(n=this.props).onPhaseChange)||void 0===t||t.call(n,this.state.phase)}componentDidMount(){this.updateMode(this.props.mode)}componentDidUpdate(e,t){var n,o;t.phase!==this.state.phase&&(null===(n=(o=this.props).onPhaseChange)||void 0===n||n.call(o,this.state.phase));e.mode!==this.props.mode&&this.updateMode(this.props.mode)}async updateMode(e,t=!0){var n;null===(n=this.abortController)||void 0===n||n.abort(),this.abortController=new AbortController,this.setState({rendezvous:void 0}),t&&this.setState({phase:d.a0.Loading}),e===d.Kt.Show&&await this.generateAndShowCode(this.abortController)}componentWillUnmount(){var e;this.finished||(null===(e=this.abortController)||void 0===e||e.abort())}onFinished(e){var t;(this.finished=!0,e)||(null===(t=this.abortController)||void 0===t||t.abort());this.props.onFinished(e)}reset(){var e;null===(e=this.abortController)||void 0===e||e.abort(),this.setState({rendezvous:void 0,verificationUri:void 0,failureReason:void 0,userCode:void 0})}render(){var e;return i.createElement(R,{onClick:this.onClick,phase:this.state.phase,code:this.state.phase===d.a0.ShowingQR?null===(e=this.state.rendezvous)||void 0===e?void 0:e.code:void 0,failureReason:this.state.failureReason,userCode:this.state.userCode,intent:this.props.intent})}}}}]); 2 //# sourceMappingURL=9958.js.map