(()=>{var e,r,n,i={77326:(e,r,n)=>{"use strict";var i=n(21777),a=n(32981),o=n(85471);function s(t){const e=new Uint8Array(t);let r="";for(const t of e)r+=String.fromCharCode(t);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function c(t){const e=t.replace(/-/g,"+").replace(/_/g,"/"),r=(4-e.length%4)%4,n=e.padEnd(e.length+r,"="),i=atob(n),a=new ArrayBuffer(i.length),o=new Uint8Array(a);for(let t=0;tt};function d(t){const{id:e}=t;return{...t,id:c(e),transports:t.transports}}class p extends Error{constructor({message:t,code:e,cause:r,name:n}){super(t,{cause:r}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=n??r.name,this.code=e}}const f=new class{constructor(){Object.defineProperty(this,"controller",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}createNewAbortSignal(){if(this.controller){const t=new Error("Cancelling existing WebAuthn API call for new one");t.name="AbortError",this.controller.abort(t)}const t=new AbortController;return this.controller=t,t.signal}cancelCeremony(){if(this.controller){const t=new Error("Manually cancelling existing WebAuthn API call");t.name="AbortError",this.controller.abort(t),this.controller=void 0}}},h=["cross-platform","platform"];function v(t){if(t&&!(h.indexOf(t)<0))return t}function g(t,e){console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${t}. You should report this error to them.\n`,e)}var y=n(56760),m=n(40083),A=n(10854),b=n.n(A),w=n(85168),x=n(97012),_=n(82182);const R=(0,n(35947).YK)().setApp("settings").detectUser().build();var E=n(53334),I=n(63814),C=n(65043);n(51257);const O=t=>e=>(R.debug(t),e),S=Object.freeze({READY:1,REGISTRATION:2,NAMING:3,PERSIST:4}),W={name:"AddDevice",components:{NcButton:x.A,NcTextField:_.A},props:{httpWarning:Boolean,isHttps:{type:Boolean,default:!1},isLocalhost:{type:Boolean,default:!1}},setup:()=>({RegistrationSteps:S}),data:()=>({name:"",credential:{},step:S.READY}),watch:{step(){this.step===S.NAMING&&this.$nextTick((()=>this.$refs.nameInput?.focus()))}},methods:{async start(){this.step=S.REGISTRATION,console.debug("Starting WebAuthn registration");try{await(0,y.C5)(),this.credential=await async function(){const t=(0,I.Jv)("/settings/api/personal/webauthn/registration");try{R.debug("Fetching webauthn registration data");const{data:e}=await C.Ay.get(t);return R.debug("Start webauthn registration"),await async function(t){const{optionsJSON:e,useAutoRegister:r=!1}=t;if(!u())throw new Error("WebAuthn is not supported in this browser");const n={...e,challenge:c(e.challenge),user:{...e.user,id:c(e.user.id)},excludeCredentials:e.excludeCredentials?.map(d)},i={};let a;r&&(i.mediation="conditional"),i.publicKey=n,i.signal=f.createNewAbortSignal();try{a=await navigator.credentials.create(i)}catch(t){throw function({error:t,options:e}){const{publicKey:r}=e;if(!r)throw Error("options was missing required publicKey property");if("AbortError"===t.name){if(e.signal instanceof AbortSignal)return new p({message:"Registration ceremony was sent an abort signal",code:"ERROR_CEREMONY_ABORTED",cause:t})}else if("ConstraintError"===t.name){if(!0===r.authenticatorSelection?.requireResidentKey)return new p({message:"Discoverable credentials were required but no available authenticator supported it",code:"ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT",cause:t});if("conditional"===e.mediation&&"required"===r.authenticatorSelection?.userVerification)return new p({message:"User verification was required during automatic registration but it could not be performed",code:"ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE",cause:t});if("required"===r.authenticatorSelection?.userVerification)return new p({message:"User verification was required but no available authenticator supported it",code:"ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT",cause:t})}else{if("InvalidStateError"===t.name)return new p({message:"The authenticator was previously registered",code:"ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED",cause:t});if("NotAllowedError"===t.name)return new p({message:t.message,code:"ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",cause:t});if("NotSupportedError"===t.name)return 0===r.pubKeyCredParams.filter((t=>"public-key"===t.type)).length?new p({message:'No entry in pubKeyCredParams was of type "public-key"',code:"ERROR_MALFORMED_PUBKEYCREDPARAMS",cause:t}):new p({message:"No available authenticator supported any of the specified pubKeyCredParams algorithms",code:"ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG",cause:t});if("SecurityError"===t.name){const e=globalThis.location.hostname;if("localhost"!==(n=e)&&!/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(n))return new p({message:`${globalThis.location.hostname} is an invalid domain`,code:"ERROR_INVALID_DOMAIN",cause:t});if(r.rp.id!==e)return new p({message:`The RP ID "${r.rp.id}" is invalid for this domain`,code:"ERROR_INVALID_RP_ID",cause:t})}else if("TypeError"===t.name){if(r.user.id.byteLength<1||r.user.id.byteLength>64)return new p({message:"User ID was not between 1 and 64 characters",code:"ERROR_INVALID_USER_ID_LENGTH",cause:t})}else if("UnknownError"===t.name)return new p({message:"The authenticator was unable to process the specified options, or could not create a new credential",code:"ERROR_AUTHENTICATOR_GENERAL_ERROR",cause:t})}var n;return t}({error:t,options:i})}if(!a)throw new Error("Registration was not completed");const{id:o,rawId:l,response:h,type:y}=a;let m,A,b,w;if("function"==typeof h.getTransports&&(m=h.getTransports()),"function"==typeof h.getPublicKeyAlgorithm)try{A=h.getPublicKeyAlgorithm()}catch(t){g("getPublicKeyAlgorithm()",t)}if("function"==typeof h.getPublicKey)try{const t=h.getPublicKey();null!==t&&(b=s(t))}catch(t){g("getPublicKey()",t)}if("function"==typeof h.getAuthenticatorData)try{w=s(h.getAuthenticatorData())}catch(t){g("getAuthenticatorData()",t)}return{id:o,rawId:s(l),response:{attestationObject:s(h.attestationObject),clientDataJSON:s(h.clientDataJSON),transports:m,publicKeyAlgorithm:A,publicKey:b,authenticatorData:w},type:y,clientExtensionResults:a.getClientExtensionResults(),authenticatorAttachment:v(a.authenticatorAttachment)}}({optionsJSON:e})}catch(t){if(R.error(t),(0,C.F0)(t))throw new Error((0,E.Tl)("settings","Could not register device: Network error"));if("InvalidStateError"===t.name)throw new Error((0,E.Tl)("settings","Could not register device: Probably already registered"));throw new Error((0,E.Tl)("settings","Could not register device"))}}(),this.step=S.NAMING}catch(t){(0,w.Qg)(t),this.step=S.READY}},submit(){return this.step=S.PERSIST,(0,y.C5)().then(O("confirmed password")).then(this.saveRegistrationData).then(O("registration data saved")).then((()=>this.reset())).then(O("app reset")).catch(console.error)},async saveRegistrationData(){try{const t=await async function(t,e){const r=(0,I.Jv)("/settings/api/personal/webauthn/registration");return(await C.Ay.post(r,{name:t,data:JSON.stringify(e)})).data}(this.name,this.credential);R.info("new device added",{device:t}),this.$emit("added",t)}catch(e){throw R.error("Error persisting webauthn registration",{error:e}),new Error(t("settings","Server error while trying to complete WebAuthn device registration"))}},reset(){this.name="",this.registrationData={},this.step=S.READY}}};var j=n(85072),N=n.n(j),D=n(97825),T=n.n(D),k=n(77659),P=n.n(k),B=n(55056),M=n.n(B),F=n(10540),L=n.n(F),U=n(41113),q=n.n(U),K=n(45711),z={};z.styleTagTransform=q(),z.setAttributes=M(),z.insert=P().bind(null,"head"),z.domAPI=T(),z.insertStyleElement=L(),N()(K.A,z),K.A&&K.A.locals&&K.A.locals;var $=n(14486);const G=(0,$.A)(W,(function(){var t=this,e=t._self._c;return t.isHttps||t.isLocalhost?e("div",[t.step===t.RegistrationSteps.READY?e("NcButton",{attrs:{type:"primary"},on:{click:t.start}},[t._v("\n\t\t"+t._s(t.t("settings","Add WebAuthn device"))+"\n\t")]):t.step===t.RegistrationSteps.REGISTRATION?e("div",{staticClass:"new-webauthn-device"},[e("span",{staticClass:"icon-loading-small webauthn-loading"}),t._v("\n\t\t"+t._s(t.t("settings","Please authorize your WebAuthn device."))+"\n\t")]):t.step===t.RegistrationSteps.NAMING?e("div",{staticClass:"new-webauthn-device"},[e("span",{staticClass:"icon-loading-small webauthn-loading"}),t._v(" "),e("form",{on:{submit:function(e){return e.preventDefault(),t.submit.apply(null,arguments)}}},[e("NcTextField",{ref:"nameInput",staticClass:"new-webauthn-device__name",attrs:{label:t.t("settings","Device name"),value:t.name,"show-trailing-button":"","trailing-button-label":t.t("settings","Add"),"trailing-button-icon":"arrowRight"},on:{"update:value":function(e){t.name=e},"trailing-button-click":t.submit}})],1)]):t.step===t.RegistrationSteps.PERSIST?e("div",{staticClass:"new-webauthn-device"},[e("span",{staticClass:"icon-loading-small webauthn-loading"}),t._v("\n\t\t"+t._s(t.t("settings","Adding your device …"))+"\n\t")]):e("div",[t._v("\n\t\tInvalid registration step. This should not have happened.\n\t")])],1):e("div",[t._v("\n\t"+t._s(t.t("settings","Passwordless authentication requires a secure connection."))+"\n")])}),[],!1,null,"6f94ece4",null).exports;var H=n(24764);const Y={name:"Device",components:{NcActionButton:n(57505).A,NcActions:H.A},props:{name:{type:String,required:!0}}};var V=n(98497),J={};J.styleTagTransform=q(),J.setAttributes=M(),J.insert=P().bind(null,"head"),J.domAPI=T(),J.insertStyleElement=L(),N()(V.A,J),V.A&&V.A.locals&&V.A.locals;const X=(0,$.A)(Y,(function(){var t=this,e=t._self._c;return e("li",{staticClass:"webauthn-device"},[e("span",{staticClass:"icon-webauthn-device"}),t._v("\n\t"+t._s(t.name||t.t("settings","Unnamed device"))+"\n\t"),e("NcActions",{attrs:{"force-menu":!0}},[e("NcActionButton",{attrs:{icon:"icon-delete"},on:{click:function(e){return t.$emit("delete")}}},[t._v("\n\t\t\t"+t._s(t.t("settings","Delete"))+"\n\t\t")])],1)],1)}),[],!1,null,"ff58f694",null).exports,Q=b()("name"),Z={components:{AddDevice:G,Device:X,NcNoteCard:m.A},props:{initialDevices:{type:Array,required:!0},isHttps:{type:Boolean,default:!1},isLocalhost:{type:Boolean,default:!1}},setup:()=>({supportsWebauthn:u()}),data(){return{devices:this.initialDevices}},computed:{sortedDevices(){return Q(this.devices)}},methods:{deviceAdded(t){R.debug(`adding new device to the list ${t.id}`),this.devices.push(t)},async deleteDevice(t){R.info(`deleting webauthn device ${t}`),await(0,y.C5)(),await async function(t){const e=(0,I.Jv)(`/settings/api/personal/webauthn/registration/${t}`);await C.Ay.delete(e)}(t),this.devices=this.devices.filter((e=>e.id!==t)),R.info(`webauthn device ${t} removed successfully`)}}};var tt=n(61738),et={};et.styleTagTransform=q(),et.setAttributes=M(),et.insert=P().bind(null,"head"),et.domAPI=T(),et.insertStyleElement=L(),N()(tt.A,et),tt.A&&tt.A.locals&&tt.A.locals;const rt=(0,$.A)(Z,(function(){var t=this,e=t._self._c;return e("div",{staticClass:"section",attrs:{id:"security-webauthn"}},[e("h2",[t._v(t._s(t.t("settings","Passwordless Authentication")))]),t._v(" "),e("p",{staticClass:"settings-hint hidden-when-empty"},[t._v("\n\t\t"+t._s(t.t("settings","Set up your account for passwordless authentication following the FIDO2 standard."))+"\n\t")]),t._v(" "),0===t.devices.length?e("NcNoteCard",{attrs:{type:"info"}},[t._v("\n\t\t"+t._s(t.t("settings","No devices configured."))+"\n\t")]):e("h3",{attrs:{id:"security-webauthn__active-devices"}},[t._v("\n\t\t"+t._s(t.t("settings","The following devices are configured for your account:"))+"\n\t")]),t._v(" "),e("ul",{staticClass:"security-webauthn__device-list",attrs:{"aria-labelledby":"security-webauthn__active-devices"}},t._l(t.sortedDevices,(function(r){return e("Device",{key:r.id,attrs:{name:r.name},on:{delete:function(e){return t.deleteDevice(r.id)}}})})),1),t._v(" "),t.supportsWebauthn?t._e():e("NcNoteCard",{attrs:{type:"warning"}},[t._v("\n\t\t"+t._s(t.t("settings","Your browser does not support WebAuthn."))+"\n\t")]),t._v(" "),t.supportsWebauthn?e("AddDevice",{attrs:{"is-https":t.isHttps,"is-localhost":t.isLocalhost},on:{added:t.deviceAdded}}):t._e()],1)}),[],!1,null,"d3d13050",null).exports;n.nc=(0,i.aV)(),o.Ay.prototype.t=t,new(o.Ay.extend(rt))({propsData:{initialDevices:(0,a.C)("settings","webauthn-devices"),isHttps:"https:"===window.location.protocol,isLocalhost:"localhost"===window.location.hostname}}).$mount("#security-webauthn")},45711:(t,e,r)=>{"use strict";r.d(e,{A:()=>s});var n=r(71354),i=r.n(n),a=r(76314),o=r.n(a)()(i());o.push([t.id,".webauthn-loading[data-v-6f94ece4]{display:inline-block;vertical-align:sub;margin-inline:2px}.new-webauthn-device[data-v-6f94ece4]{display:flex;gap:22px;align-items:center}.new-webauthn-device__name[data-v-6f94ece4]{max-width:min(100vw,400px)}","",{version:3,sources:["webpack://./apps/settings/src/components/WebAuthn/AddDevice.vue"],names:[],mappings:"AACA,mCACC,oBAAA,CACA,kBAAA,CACA,iBAAA,CAGD,sCACC,YAAA,CACA,QAAA,CACA,kBAAA,CAEA,4CACC,0BAAA",sourcesContent:["\n.webauthn-loading {\n\tdisplay: inline-block;\n\tvertical-align: sub;\n\tmargin-inline: 2px;\n}\n\n.new-webauthn-device {\n\tdisplay: flex;\n\tgap: 22px;\n\talign-items: center;\n\n\t&__name {\n\t\tmax-width: min(100vw, 400px);\n\t}\n}\n"],sourceRoot:""}]);const s=o},98497:(t,e,r)=>{"use strict";r.d(e,{A:()=>s});var n=r(71354),i=r.n(n),a=r(76314),o=r.n(a)()(i());o.push([t.id,"\n.webauthn-device[data-v-ff58f694] {\n\tline-height: 300%;\n\tdisplay: flex;\n}\n.icon-webauthn-device[data-v-ff58f694] {\n\tdisplay: inline-block;\n\tbackground-size: 100%;\n\tpadding: 3px;\n\tmargin: 3px;\n}\n","",{version:3,sources:["webpack://./apps/settings/src/components/WebAuthn/Device.vue"],names:[],mappings:";AAkDA;CACA,iBAAA;CACA,aAAA;AACA;AAEA;CACA,qBAAA;CACA,qBAAA;CACA,YAAA;CACA,WAAA;AACA",sourcesContent:["\x3c!--\n - SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors\n - SPDX-License-Identifier: AGPL-3.0-or-later\n--\x3e\n\n\n\n