2 lines
25 KiB
JavaScript
2 lines
25 KiB
JavaScript
"use strict";(self.webpackChunkelement_web=self.webpackChunkelement_web||[]).push([[8901],{"./src/components/views/auth/LoginWithQR.tsx":(e,t,i)=>{i.r(t),i.d(t,{LoginWithQRFailureReason:()=>B,default:()=>Y});var n=i("./node_modules/@babel/runtime/helpers/esm/defineProperty.js"),s=i("./node_modules/react/index.js"),r=i("./node_modules/@matrix-org/matrix-sdk-crypto-wasm/index-wasm-esm.mjs"),o=i("./node_modules/matrix-js-sdk/src/logger.ts"),a=i("./node_modules/matrix-js-sdk/src/http-api/index.ts"),c=i("./node_modules/matrix-js-sdk/src/utils.ts"),l=i("./node_modules/matrix-js-sdk/src/oidc/index.ts");function d(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),i.push.apply(i,n)}return i}function h(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?d(Object(i),!0).forEach(function(t){(0,n.A)(e,t,i[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):d(Object(i)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e}let u=function(e){return e.Protocols="m.login.protocols",e.Protocol="m.login.protocol",e.Failure="m.login.failure",e.Success="m.login.success",e.Secrets="m.login.secrets",e.ProtocolAccepted="m.login.protocol_accepted",e.Declined="m.login.declined",e}({});class _{get checkCode(){var e;return null===(e=this.channel)||void 0===e?void 0:e.getCheckCode()}constructor(e,t,i,s){(0,n.A)(this,"ourIntent",void 0),(0,n.A)(this,"_code",void 0),(0,n.A)(this,"expectingNewDeviceId",void 0),this.channel=e,this.didScanCode=t,this.client=i,this.onFailure=s,this.ourIntent=i?r.qqN.Reciprocate:r.qqN.Login}get code(){return this._code}async generateCode(){this._code||(this.ourIntent===r.qqN.Reciprocate&&this.client?this._code=await this.channel.generateCode(this.ourIntent,this.client.getDomain()):this.ourIntent===r.qqN.Login&&(this._code=await this.channel.generateCode(this.ourIntent)))}get isExistingDevice(){return this.ourIntent===r.qqN.Reciprocate}get isNewDevice(){return!this.isExistingDevice}async negotiateProtocols(){if(o.vF.info(`negotiateProtocols(isNewDevice=${this.isNewDevice} didScanCode=${this.didScanCode})`),await this.channel.connect(),this.didScanCode)if(this.isNewDevice);else{var e;let t;try{t=await this.client.getAuthMetadata()}catch(e){o.vF.error("Failed to discover OIDC metadata",e)}if(null===(e=t)||void 0===e||!e.grant_types_supported.includes(l.AO))throw await this.send({type:u.Failure,reason:v.UnsupportedProtocol}),new p("Device code grant unsupported",v.UnsupportedProtocol);await this.send({type:u.Protocols,protocols:["device_authorization_grant"],homeserver:this.client.getDomain()})}else if(this.isNewDevice){o.vF.info("Waiting for protocols message");const e=await this.receive();if((null==e?void 0:e.type)===u.Failure)throw new p("Failed",e.reason);if((null==e?void 0:e.type)!==u.Protocols)throw await this.send({type:u.Failure,reason:v.UnexpectedMessageReceived}),new p("Unexpected message received",v.UnexpectedMessageReceived);return{serverName:e.homeserver}}return{}}async deviceAuthorizationGrant(){if(this.isNewDevice)throw new Error("New device flows around OIDC are not yet implemented");{o.vF.info("Waiting for protocol message");const t=await this.receive();if((null==t?void 0:t.type)===u.Failure)throw new p("Failed",t.reason);if((null==t?void 0:t.type)!==u.Protocol)throw await this.send({type:u.Failure,reason:v.UnexpectedMessageReceived}),new p("Unexpected message received",v.UnexpectedMessageReceived);if(function(e){return"device_authorization_grant"===e.protocol}(t)){const{device_authorization_grant:i,device_id:n}=t,{verification_uri:s,verification_uri_complete:r}=i;let o=!0;try{var e;await(null===(e=this.client)||void 0===e?void 0:e.getDevice(n))}catch(e){e instanceof a.up&&404===e.httpStatus&&(o=!1)}if(o)throw await this.send({type:u.Failure,reason:v.DeviceAlreadyExists}),new p("Specified device ID already exists",v.DeviceAlreadyExists);return this.expectingNewDeviceId=n,{verificationUri:null!=r?r:s}}throw await this.send({type:u.Failure,reason:v.UnsupportedProtocol}),new p("Received a request for an unsupported protocol",v.UnsupportedProtocol)}}async shareSecrets(){if(this.isNewDevice){await this.send({type:u.Success}),o.vF.info("Waiting for secrets message");const e=await this.receive();if((null==e?void 0:e.type)===u.Failure)throw new p("Failed",e.reason);if((null==e?void 0:e.type)!==u.Secrets)throw await this.send({type:u.Failure,reason:v.UnexpectedMessageReceived}),new p("Unexpected message received",v.UnexpectedMessageReceived);return{secrets:e}}{if(!this.expectingNewDeviceId)throw new Error("No new device ID expected");await this.send({type:u.ProtocolAccepted}),o.vF.info("Waiting for outcome message");const t=await this.receive();if((null==t?void 0:t.type)===u.Failure)throw new p("Failed",t.reason);if((null==t?void 0:t.type)===u.Declined)throw new p("User declined",m.UserDeclined);if((null==t?void 0:t.type)!==u.Success)throw await this.send({type:u.Failure,reason:v.UnexpectedMessageReceived}),new p("Unexpected message",v.UnexpectedMessageReceived);const i=Date.now()+1e4;do{try{var e;if(await(null===(e=this.client)||void 0===e?void 0:e.getDevice(this.expectingNewDeviceId))){const e=await this.client.getCrypto().exportSecretsBundle();if(this.channel.cancelled)throw new p("User cancelled",v.UserCancelled);return await this.send(h({type:u.Secrets},e)),{secrets:e}}}catch(e){if(!(e instanceof a.up&&404===e.httpStatus))throw e}await(0,c.yy)(1e3)}while(Date.now()<i);throw await this.send({type:u.Failure,reason:v.DeviceNotFound}),new p("New device not found",v.DeviceNotFound)}}async receive(){return await this.channel.secureReceive()}async send(e){await this.channel.secureSend(e)}async declineLoginOnExistingDevice(){if(!this.isExistingDevice)throw new Error("Can only decline login on existing device");await this.send({type:u.Failure,reason:v.UserCancelled})}async cancel(e){var t;null===(t=this.onFailure)||void 0===t||t.call(this,e),await this.channel.cancel(e)}async close(){await this.channel.close()}}class p extends Error{constructor(e,t){super(e),this.code=t}}let v=function(e){return e.AuthorizationExpired="authorization_expired",e.DeviceAlreadyExists="device_already_exists",e.DeviceNotFound="device_not_found",e.UnexpectedMessageReceived="unexpected_message_received",e.UnsupportedProtocol="unsupported_protocol",e.UserCancelled="user_cancelled",e}({}),m=function(e){return e.Expired="expired",e.HomeserverLacksSupport="homeserver_lacks_support",e.InsecureChannelDetected="insecure_channel_detected",e.InvalidCode="invalid_code",e.OtherDeviceNotSignedIn="other_device_not_signed_in",e.OtherDeviceAlreadySignedIn="other_device_already_signed_in",e.Unknown="unknown",e.UserDeclined="user_declined",e.ETagMissing="etag_missing",e}({}),g=function(e){return e.LOGIN_ON_NEW_DEVICE="login.start",e.RECIPROCATE_LOGIN_ON_EXISTING_DEVICE="login.reciprocate",e}({});var w=i("./node_modules/matrix-js-sdk/src/matrix.ts");class f{constructor({fetchFn:e,onFailure:t,url:i,client:s,fallbackRzServer:r}){(0,n.A)(this,"url",void 0),(0,n.A)(this,"client",void 0),(0,n.A)(this,"fallbackRzServer",void 0),(0,n.A)(this,"fetchFn",void 0),(0,n.A)(this,"onFailure",void 0),(0,n.A)(this,"etag",void 0),(0,n.A)(this,"expiresAt",void 0),(0,n.A)(this,"expiresTimer",void 0),(0,n.A)(this,"_cancelled",!1),(0,n.A)(this,"_ready",!1),this.fetchFn=e,this.onFailure=t,this.client=s,this.fallbackRzServer=r,this.url=i}get ready(){return this._ready}get cancelled(){return this._cancelled}fetch(e,t){return this.fetchFn?this.fetchFn(e,t):globalThis.fetch(e,t)}async getPostEndpoint(){if(this.client)try{if(await this.client.doesServerSupportUnstableFeature("org.matrix.msc4108"))return this.client.http.getUrl("/org.matrix.msc4108/rendezvous",void 0,a.iD.Unstable).toString()}catch(e){o.vF.warn("Failed to get unstable features",e)}return this.fallbackRzServer}async send(e){var t,i;if(this._cancelled)return;const n=this.url?w.Method.Put:w.Method.Post,s=null!==(t=this.url)&&void 0!==t?t:await this.getPostEndpoint();if(!s)throw new Error("Invalid rendezvous URI");const r={"content-type":"text/plain"};!this.etag&&this.url&&await this.receive(),this.etag&&(r["if-match"]=this.etag),o.vF.info(`=> ${n} ${s} with ${e} if-match: ${this.etag}`);const a=await this.fetch(s,{method:n,headers:r,body:e,redirect:"follow"});if(404===a.status)return this.cancel(m.Unknown);if(this.etag=null!==(i=a.headers.get("etag"))&&void 0!==i?i:void 0,o.vF.info(`Received etag: ${this.etag}`),n===w.Method.Post){const e=a.headers.get("expires");e&&(this.expiresTimer&&(clearTimeout(this.expiresTimer),this.expiresTimer=void 0),this.expiresAt=new Date(e),this.expiresTimer=setTimeout(()=>{this.expiresTimer=void 0,this.cancel(m.Expired)},this.expiresAt.getTime()-Date.now()));const t=await a.json();if("string"!=typeof t.url)throw new Error("No rendezvous URL given");this.url=t.url,this._ready=!0}}async receive(){if(!this.url)throw new Error("Rendezvous not set up");for(;;){var e;if(this._cancelled)return;const t={};this.etag&&(t["if-none-match"]=this.etag),o.vF.info(`=> GET ${this.url} if-none-match: ${this.etag}`);const i=await this.fetch(this.url,{method:w.Method.Get,headers:t});if(404===i.status)return void await this.cancel(m.Unknown);const n=null!==(e=i.headers.get("etag"))&&void 0!==e?e:void 0;if("text/plain"!==i.headers.get("content-type"))this.etag=n;else if(200===i.status){if(!n)return void await this.cancel(m.ETagMissing);this.etag=n;const e=await i.text();return o.vF.info(`Received: ${e} with etag ${this.etag}`),e}await(0,c.yy)(1e3)}}async cancel(e){var t;this._cancelled||(this.expiresTimer&&(clearTimeout(this.expiresTimer),this.expiresTimer=void 0),e===m.Unknown&&this.expiresAt&&this.expiresAt.getTime()<Date.now()&&(e=m.Expired),this._cancelled=!0,this._ready=!1,null===(t=this.onFailure)||void 0===t||t.call(this,e),e!==m.UserDeclined&&e!==v.UserCancelled||await this.close())}async close(){if(this.expiresTimer&&(clearTimeout(this.expiresTimer),this.expiresTimer=void 0),this.url)try{await this.fetch(this.url,{method:w.Method.Delete})}catch(e){o.vF.warn(e)}}}class y{constructor(e,t,i){(0,n.A)(this,"secureChannel",void 0),(0,n.A)(this,"establishedChannel",void 0),(0,n.A)(this,"connected",!1),this.rendezvousSession=e,this.theirPublicKey=t,this.onFailure=i,this.secureChannel=new r.SG1}async generateCode(e,t){const{url:i}=this.rendezvousSession;if(!i)throw new Error("No rendezvous session URL");return new r.dFo(this.secureChannel.public_key(),i,e===r.qqN.Reciprocate?t:void 0).toBytes()}getCheckCode(){var e;const t=null===(e=this.establishedChannel)||void 0===e?void 0:e.check_code();if(t)return Array.from(t.as_bytes()).map(e=>""+e%10).join("")}async connect(){if(this.connected)throw new Error("Channel already connected");if(this.theirPublicKey){const e=this.secureChannel.establish_outbound_channel(this.theirPublicKey,"MATRIX_QR_CODE_LOGIN_INITIATE");this.establishedChannel=e.channel,o.vF.info("Sending LoginInitiateMessage"),await this.rendezvousSession.send(e.initial_message);{o.vF.info("Waiting for LoginOkMessage");const e=await this.rendezvousSession.receive();if(!e)throw new p("No response from other device",v.UnexpectedMessageReceived);if("MATRIX_QR_CODE_LOGIN_OK"!==await this.decrypt(e))throw new p("Invalid response from other device",m.InsecureChannelDetected)}}else{o.vF.info("Waiting for LoginInitiateMessage");const e=await this.rendezvousSession.receive();if(!e)throw new Error("No response from other device");const{channel:t,message:i}=this.secureChannel.establish_inbound_channel(e);if(this.establishedChannel=t,"MATRIX_QR_CODE_LOGIN_INITIATE"!==i)throw new p("Invalid response from other device",m.InsecureChannelDetected);o.vF.info("LoginInitiateMessage received"),o.vF.info("Sending LoginOkMessage");const n=await this.encrypt("MATRIX_QR_CODE_LOGIN_OK");await this.rendezvousSession.send(n)}this.connected=!0}async decrypt(e){if(!this.establishedChannel)throw new Error("Channel closed");return this.establishedChannel.decrypt(e)}async encrypt(e){if(!this.establishedChannel)throw new Error("Channel closed");return this.establishedChannel.encrypt(e)}async secureSend(e){if(!this.connected)throw new Error("Channel closed");const t=JSON.stringify(e);o.vF.debug(`=> {"type": ${JSON.stringify(e.type)}, ...}`),await this.rendezvousSession.send(await this.encrypt(t))}async secureReceive(){if(!this.establishedChannel)throw new Error("Channel closed");const e=await this.rendezvousSession.receive();if(!e)return;const t=await this.decrypt(e),i=JSON.parse(t);return o.vF.debug(`<= {"type": ${JSON.stringify(i.type)}, ...}`),i}async close(){await this.rendezvousSession.close()}async cancel(e){try{var t;await this.rendezvousSession.cancel(e),null===(t=this.onFailure)||void 0===t||t.call(this,e)}finally{await this.close()}}get cancelled(){return this.rendezvousSession.cancelled}}var E=i("./src/components/views/auth/LoginWithQR-types.ts"),x=i("./node_modules/@vector-im/compound-design-tokens/assets/web/icons/chevron-left.js"),C=i("./node_modules/@vector-im/compound-design-tokens/assets/web/icons/check-circle-solid.js"),b=i("./node_modules/@vector-im/compound-design-tokens/assets/web/icons/error-solid.js"),k=i("./node_modules/@vector-im/compound-web/dist/components/Typography/Text.js"),S=i("./node_modules/@vector-im/compound-web/dist/components/Typography/Heading.js"),R=i("./node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js"),F=i("./node_modules/react/jsx-runtime.js");const D="_container_43om7_10",O="_control_43om7_25",A="_digit_43om7_49";var I=i("./node_modules/classnames/index.js"),N=i.n(I);const U=["className","length"];function q(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),i.push.apply(i,n)}return i}function L(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?q(Object(i),!0).forEach(function(t){(0,n.A)(e,t,i[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):q(Object(i)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e}const z=({filled:e,selected:t})=>(0,F.jsx)("div",{className:A,"aria-hidden":"true","data-filled":e?"":void 0,"data-selected":t?"":void 0}),j=(0,s.forwardRef)(function(e,t){let{className:i,length:n=6}=e,r=(0,R.A)(e,U);const o=I(D,i),[a,c]=s.useState(0),[l,d]=s.useState(null),h=e=>{var t;const i=e.currentTarget;c(null===(t=i.value)||void 0===t?void 0:t.length),document.activeElement!==i||null===i.selectionStart||null===i.selectionEnd?d(null):d([i.selectionStart,i.selectionEnd])};return(0,F.jsxs)("div",{className:o,children:[(0,F.jsx)("input",L(L({},r),{},{inputMode:"numeric",type:"text",minLength:0,maxLength:n,className:O,pattern:`\\d{${n}}`,autoComplete:"one-time-code",onSelect:h,onFocus:h,onBlur:h,onMouseDown:h,onMouseMove:h,onMouseUp:h,onChange:h,ref:t})),Array.from(Array(n).keys()).map(e=>(0,F.jsx)(z,{filled:e<a,selected:!!l&&e>=l[0]&&e<l[1]},e))]})});var P=i("./node_modules/@vector-im/compound-design-tokens/assets/web/icons/qr-code.js"),M=i("./src/languageHandler.tsx"),T=i("./src/components/views/elements/AccessibleButton.tsx"),Q=i("./src/components/views/elements/QRCode.tsx"),W=i("./src/components/views/elements/Spinner.tsx"),G=i("./src/SdkConfig.ts"),H=i("./src/components/structures/ErrorMessage.tsx");class $ extends s.Component{constructor(...e){super(...e),(0,n.A)(this,"checkCodeInput",(0,s.createRef)()),(0,n.A)(this,"handleClick",e=>async t=>{var i;t.preventDefault(),await this.props.onClick(e,e===E.HY.Approve?null===(i=this.checkCodeInput.current)||void 0===i?void 0:i.value:void 0)}),(0,n.A)(this,"cancelButton",()=>s.createElement(T.A,{kind:"primary_outline",onClick:this.handleClick(E.HY.Cancel)},(0,M._t)("action|cancel"))),(0,n.A)(this,"simpleSpinner",e=>s.createElement("div",{className:"mx_LoginWithQR_spinner"},s.createElement("div",null,s.createElement(W.A,null),e&&s.createElement("p",null,e))))}render(){let e,t,i=!0,n="";switch(this.props.phase){case E.a0.Error:{i=!1;let t,r,o=b.A,a=!1;switch(this.props.failureReason){case v.UnsupportedProtocol:t=(0,M._t)("auth|qr_code_login|error_unsupported_protocol_title"),r=(0,M._t)("auth|qr_code_login|error_unsupported_protocol");break;case v.UserCancelled:t=(0,M._t)("auth|qr_code_login|error_user_cancelled_title"),r=(0,M._t)("auth|qr_code_login|error_user_cancelled");break;case v.AuthorizationExpired:case m.Expired:t=(0,M._t)("auth|qr_code_login|error_expired_title"),r=(0,M._t)("auth|qr_code_login|error_expired");break;case m.InsecureChannelDetected:t=(0,M._t)("auth|qr_code_login|error_insecure_channel_detected_title"),r=s.createElement(s.Fragment,null,(0,M._t)("auth|qr_code_login|error_insecure_channel_detected"),s.createElement(k.E,{as:"h2",size:"lg",weight:"semibold"},(0,M._t)("auth|qr_code_login|error_insecure_channel_detected_instructions")),s.createElement("ol",null,s.createElement("li",null,(0,M._t)("auth|qr_code_login|error_insecure_channel_detected_instructions_1")),s.createElement("li",null,(0,M._t)("auth|qr_code_login|error_insecure_channel_detected_instructions_2")),s.createElement("li",null,(0,M._t)("auth|qr_code_login|error_insecure_channel_detected_instructions_3"))));break;case m.OtherDeviceAlreadySignedIn:a=!0,o=C.A,t=(0,M._t)("auth|qr_code_login|error_other_device_already_signed_in_title"),r=(0,M._t)("auth|qr_code_login|error_other_device_already_signed_in");break;case m.UserDeclined:t=(0,M._t)("auth|qr_code_login|error_user_declined_title"),r=(0,M._t)("auth|qr_code_login|error_user_declined");break;case B.RateLimited:t=(0,M._t)("error|something_went_wrong"),r=(0,M._t)("auth|qr_code_login|error_rate_limited");break;case m.ETagMissing:t=(0,M._t)("error|something_went_wrong"),r=(0,M._t)("auth|qr_code_login|error_etag_missing");break;case m.HomeserverLacksSupport:a=null,o=P.A,i=!0,t=(0,M._t)("auth|qr_code_login|unsupported_heading"),r=(0,M._t)("auth|qr_code_login|unsupported_explainer");break;case v.DeviceAlreadyExists:case v.DeviceNotFound:case v.UnexpectedMessageReceived:case m.OtherDeviceNotSignedIn:case m.Unknown:default:t=(0,M._t)("error|something_went_wrong"),r=(0,M._t)("auth|qr_code_login|error_unexpected")}n="mx_LoginWithQR_error",e=s.createElement(s.Fragment,null,s.createElement("div",{className:N()("mx_LoginWithQR_icon",{"mx_LoginWithQR_icon--critical":!1===a,"mx_LoginWithQR_icon--success":!0===a})},s.createElement(o,{width:"32px",height:"32px"})),s.createElement(S.D,{as:"h1",size:"sm",weight:"semibold"},t),"object"==typeof r?r:s.createElement("p",null,r));break}case E.a0.OutOfBandConfirmation:i=!1,e=s.createElement(s.Fragment,null,s.createElement(S.D,{as:"h1",size:"sm",weight:"semibold"},(0,M._t)("auth|qr_code_login|check_code_heading")),s.createElement(k.E,{size:"md"},(0,M._t)("auth|qr_code_login|check_code_explainer")),s.createElement("label",{htmlFor:"mx_LoginWithQR_checkCode"},(0,M._t)("auth|qr_code_login|check_code_input_label")),s.createElement(j,{className:"mx_LoginWithQR_checkCode_input mx_no_textinput",ref:this.checkCodeInput,length:2,autoFocus:!0,id:"mx_LoginWithQR_checkCode","data-invalid":this.props.failureReason===B.CheckCodeMismatch||void 0}),s.createElement(H.K,{message:this.props.failureReason===B.CheckCodeMismatch?(0,M._t)("auth|qr_code_login|check_code_mismatch"):null})),t=s.createElement(s.Fragment,null,s.createElement(T.A,{kind:"primary",onClick:this.handleClick(E.HY.Approve)},(0,M._t)("action|continue")),s.createElement(T.A,{kind:"primary_outline",onClick:this.handleClick(E.HY.Decline)},(0,M._t)("action|cancel")));break;case E.a0.ShowingQR:if(this.props.code){const t=this.props.code;e=s.createElement(s.Fragment,null,s.createElement(S.D,{as:"h1",size:"sm",weight:"semibold"},(0,M._t)("auth|qr_code_login|scan_code_instruction")),s.createElement("div",{className:"mx_LoginWithQR_qrWrapper"},s.createElement(Q.A,{data:[{data:t,mode:"byte"}],className:"mx_QRCode"})),s.createElement("ol",null,s.createElement("li",null,(0,M._t)("auth|qr_code_login|open_element_other_device",{brand:G.Ay.get().brand})),s.createElement("li",null,(0,M._t)("auth|qr_code_login|select_qr_code",{scanQRCode:s.createElement("strong",null,(0,M._t)("auth|qr_code_login|scan_qr_code"))})),s.createElement("li",null,(0,M._t)("auth|qr_code_login|point_the_camera")),s.createElement("li",null,(0,M._t)("auth|qr_code_login|follow_remaining_instructions"))))}else e=this.simpleSpinner(),t=this.cancelButton();break;case E.a0.Loading:e=this.simpleSpinner();break;case E.a0.WaitingForDevice:e=s.createElement(s.Fragment,null,this.simpleSpinner((0,M._t)("auth|qr_code_login|waiting_for_device")),this.props.userCode?s.createElement("div",null,s.createElement("p",null,(0,M._t)("auth|qr_code_login|security_code")),s.createElement("p",null,(0,M._t)("auth|qr_code_login|security_code_prompt")),s.createElement("p",null,this.props.userCode)):null),t=this.cancelButton();break;case E.a0.Verifying:e=this.simpleSpinner((0,M._t)("auth|qr_code_login|completing_setup"))}return s.createElement("div",{className:N()("mx_LoginWithQR",n)},i?s.createElement("div",{className:"mx_LoginWithQR_heading"},s.createElement(T.A,{className:"mx_LoginWithQR_BackButton",onClick:this.handleClick(E.HY.Back),title:(0,M._t)("action|back")},s.createElement(x.A,null)),s.createElement("div",{className:"mx_LoginWithQR_breadcrumbs"},(0,M._t)("settings|sessions|title")," / ",(0,M._t)("settings|sessions|sign_in_with_qr"))):null,s.createElement("div",{className:"mx_LoginWithQR_main"},e),s.createElement("div",{className:"mx_LoginWithQR_buttons"},t))}}let B=function(e){return e.RateLimited="rate_limited",e.CheckCodeMismatch="check_code_mismatch",e}({});class Y extends s.Component{constructor(e){super(e),(0,n.A)(this,"finished",!1),(0,n.A)(this,"generateAndShowCode",async()=>{let e;try{const t=new f({onFailure:this.onFailure,client:this.props.client});await t.send("");const i=new y(t,void 0,this.onFailure);e=new _(i,!1,this.props.client,this.onFailure),await e.generateCode(),this.setState({phase:E.a0.ShowingQR,rendezvous:e,failureReason:void 0})}catch(e){return o.vF.error("Error whilst generating QR code",e),void this.setState({phase:E.a0.Error,failureReason:m.HomeserverLacksSupport})}try{if(this.ourIntent===g.RECIPROCATE_LOGIN_ON_EXISTING_DEVICE){await e.negotiateProtocols();const{verificationUri:t}=await e.deviceAuthorizationGrant();this.setState({phase:E.a0.OutOfBandConfirmation,verificationUri:t})}}catch(i){var t;o.vF.error("Error whilst approving login",i),await(null===(t=e)||void 0===t?void 0:t.cancel(i instanceof p?i.code:m.Unknown))}}),(0,n.A)(this,"approveLogin",async e=>{var t;if(!(this.state.rendezvous instanceof _))throw this.setState({phase:E.a0.Error,failureReason:m.Unknown}),new Error("Rendezvous not found");if((null===(t=this.state.rendezvous)||void 0===t?void 0:t.checkCode)===e)try{if(this.ourIntent!==g.RECIPROCATE_LOGIN_ON_EXISTING_DEVICE)throw this.setState({phase:E.a0.Error,failureReason:m.Unknown}),new Error("New device flows around OIDC are not yet implemented");this.setState({phase:E.a0.Loading}),this.state.verificationUri&&window.open(this.state.verificationUri,"_blank"),this.setState({phase:E.a0.WaitingForDevice}),await this.state.rendezvous.shareSecrets(),this.onFinished(!0)}catch(e){o.vF.error("Error whilst approving sign in",e),this.setState({phase:E.a0.Error,failureReason:e instanceof p?e.code:m.Unknown})}else this.setState({failureReason:B.CheckCodeMismatch})}),(0,n.A)(this,"onFailure",e=>{this.state.phase!==E.a0.Error&&(o.vF.info(`Rendezvous failed: ${e}`),this.setState({phase:E.a0.Error,failureReason:e}))}),(0,n.A)(this,"onClick",async(e,t)=>{var i,n,s;switch(e){case E.HY.Cancel:await(null===(i=this.state.rendezvous)||void 0===i?void 0:i.cancel(v.UserCancelled)),this.reset(),this.onFinished(!1);break;case E.HY.Approve:await this.approveLogin(t);break;case E.HY.Decline:await(null===(n=this.state.rendezvous)||void 0===n?void 0:n.declineLoginOnExistingDevice()),this.reset(),this.onFinished(!1);break;case E.HY.Back:await(null===(s=this.state.rendezvous)||void 0===s?void 0:s.cancel(v.UserCancelled)),this.onFinished(!1);break;case E.HY.ShowQr:await this.updateMode(E.Kt.Show)}}),this.state={phase:E.a0.Loading}}get ourIntent(){return g.RECIPROCATE_LOGIN_ON_EXISTING_DEVICE}componentDidMount(){this.updateMode(this.props.mode).then(()=>{})}componentDidUpdate(e){e.mode!==this.props.mode&&this.updateMode(this.props.mode).then(()=>{})}async updateMode(e){if(this.setState({phase:E.a0.Loading}),this.state.rendezvous){this.state.rendezvous.onFailure=void 0,this.setState({rendezvous:void 0})}e===E.Kt.Show&&await this.generateAndShowCode()}componentWillUnmount(){this.state.rendezvous&&!this.finished&&(this.state.rendezvous.onFailure=void 0,this.state.rendezvous.cancel(v.UserCancelled))}onFinished(e){this.finished=!0,this.props.onFinished(e)}reset(){this.setState({rendezvous:void 0,verificationUri:void 0,failureReason:void 0,userCode:void 0,checkCode:void 0,mediaPermissionError:!1})}render(){var e;return s.createElement($,{onClick:this.onClick,phase:this.state.phase,code:this.state.phase===E.a0.ShowingQR?null===(e=this.state.rendezvous)||void 0===e?void 0:e.code:void 0,failureReason:this.state.failureReason,userCode:this.state.userCode,checkCode:this.state.checkCode})}}}}]);
|
|
//# sourceMappingURL=8901.js.map
|