/*! For license information please see settings-vue-settings-personal-webauthn.js.LICENSE.txt */ (()=>{var e,n={77099:(e,n,r)=>{"use strict";var i=r(20144),a=r(43554),o=r(7820),s=r(50323),l=(r(65509),r(66415)),c=r.n(l),u=r(54572);const d=(0,r(17499).IY)().setApp("settings").detectUser().build();var p=r(93664),h=r(79753),f=r(25108);const g=t=>e=>(d.debug(t),e),v=Object.freeze({READY:1,REGISTRATION:2,NAMING:3,PERSIST:4}),y={name:"AddDevice",components:{NcButton:u.Z},props:{httpWarning:Boolean,isHttps:{type:Boolean,default:!1},isLocalhost:{type:Boolean,default:!1}},data:()=>({name:"",credential:{},RegistrationSteps:v,step:v.READY}),methods:{arrayToBase64String:t=>btoa(String.fromCharCode(...t)),start(){return this.step=v.REGISTRATION,f.debug("Starting WebAuthn registration"),(0,o.Z)().then(this.getRegistrationData).then(this.register.bind(this)).then((()=>{this.step=v.NAMING})).catch((t=>{f.error(t.name,t.message),this.step=v.READY}))},getRegistrationData:()=>(f.debug("Fetching webauthn registration data"),async function(){const t=(0,h.generateUrl)("/settings/api/personal/webauthn/registration");return(await p.Z.get(t)).data}().then((t=>(f.debug(t),t.challenge=Uint8Array.from(function(t){const e=(t=t.replace(/-/g,"+").replace(/_/g,"/")).length%4;if(e){if(1===e)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");t+=new Array(5-e).join("=")}return window.atob(t)}(t.challenge),(t=>t.charCodeAt(0))),t.user.id=Uint8Array.from(t.user.id,(t=>t.charCodeAt(0))),t))).catch((e=>{throw f.error("Error getting webauthn registration data from server",e),new Error(t("settings","Server error while trying to add WebAuthn device"))}))),register(t){return f.debug("starting webauthn registration"),navigator.credentials.create({publicKey:t}).then((t=>{this.credential={id:t.id,type:t.type,rawId:this.arrayToBase64String(new Uint8Array(t.rawId)),response:{clientDataJSON:this.arrayToBase64String(new Uint8Array(t.response.clientDataJSON)),attestationObject:this.arrayToBase64String(new Uint8Array(t.response.attestationObject))}}}))},submit(){return this.step=v.PERSIST,(0,o.Z)().then(g("confirmed password")).then(this.saveRegistrationData).then(g("registration data saved")).then((()=>this.reset())).then(g("app reset")).catch(f.error.bind(this))},async saveRegistrationData(){try{const t=await async function(t,e){const n=(0,h.generateUrl)("/settings/api/personal/webauthn/registration");return(await p.Z.post(n,{name:t,data:e})).data}(this.name,JSON.stringify(this.credential));d.info("new device added",{device:t}),this.$emit("added",t)}catch(e){throw d.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=v.READY}}};var m=r(93379),A=r.n(m),b=r(7795),w=r.n(b),x=r(90569),_=r.n(x),R=r(3565),I=r.n(R),W=r(19216),S=r.n(W),C=r(44589),O=r.n(C),E=r(37311),B={};B.styleTagTransform=O(),B.setAttributes=I(),B.insert=_().bind(null,"head"),B.domAPI=w(),B.insertStyleElement=S(),A()(E.Z,B),E.Z&&E.Z.locals&&E.Z.locals;var N=r(51900);const k=(0,N.Z)(y,(function(){var t=this,e=t._self._c;return t.isHttps||t.isLocalhost?e("div",[t.step===t.RegistrationSteps.READY?e("div",[e("NcButton",{attrs:{type:"primary"},on:{click:t.start}},[t._v("\n\t\t\t"+t._s(t.t("settings","Add WebAuthn device"))+"\n\t\t")])],1):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("input",{directives:[{name:"model",rawName:"v-model",value:t.name,expression:"name"}],attrs:{type:"text",placeholder:t.t("settings","Name your device")},domProps:{value:t.name},on:{":keyup":function(e){return!e.type.indexOf("key")&&t._k(e.keyCode,"enter",13,e.key,"Enter")?null:t.submit.apply(null,arguments)},input:function(e){e.target.composing||(t.name=e.target.value)}}}),t._v(" "),e("NcButton",{attrs:{type:"primary"},on:{click:t.submit}},[t._v("\n\t\t\t"+t._s(t.t("settings","Add"))+"\n\t\t")])],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")])]):e("div",[t._v("\n\t"+t._s(t.t("settings","Passwordless authentication requires a secure connection."))+"\n")])}),[],!1,null,"14a3490a",null).exports;var T=r(61057);const D={name:"Device",components:{NcActionButton:r(43589).Z,NcActions:T.Z},props:{name:{type:String,required:!0}}};var P=r(68256),j={};j.styleTagTransform=O(),j.setAttributes=I(),j.insert=_().bind(null,"head"),j.domAPI=w(),j.insertStyleElement=S(),A()(P.Z,j),P.Z&&P.Z.locals&&P.Z.locals;const L=(0,N.Z)(D,(function(){var t=this,e=t._self._c;return e("div",{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,"46d7f170",null).exports,F=c()("name"),M={components:{AddDevice:k,Device:L,NcNoteCard:s.Z},props:{initialDevices:{type:Array,required:!0},isHttps:{type:Boolean,default:!1},isLocalhost:{type:Boolean,default:!1},hasPublicKeyCredential:{type:Boolean,default:!1}},data(){return{devices:this.initialDevices}},computed:{sortedDevices(){return F(this.devices)}},methods:{deviceAdded(t){d.debug(`adding new device to the list ${t.id}`),this.devices.push(t)},async deleteDevice(t){d.info(`deleting webauthn device ${t}`),await(0,o.Z)(),await async function(t){const e=(0,h.generateUrl)(`/settings/api/personal/webauthn/registration/${t}`);await p.Z.delete(e)}(t),this.devices=this.devices.filter((e=>e.id!==t)),d.info(`webauthn device ${t} removed successfully`)}}},U=(0,N.Z)(M,(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",[t._v("\n\t\t"+t._s(t.t("settings","The following devices are configured for your account:"))+"\n\t")]),t._v(" "),t._l(t.sortedDevices,(function(n){return e("Device",{key:n.id,attrs:{name:n.name},on:{delete:function(e){return t.deleteDevice(n.id)}}})})),t._v(" "),t.hasPublicKeyCredential?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.hasPublicKeyCredential?e("AddDevice",{attrs:{"is-https":t.isHttps,"is-localhost":t.isLocalhost},on:{added:t.deviceAdded}}):t._e()],2)}),[],!1,null,"71aa9ded",null).exports;r.nc=btoa(OC.requestToken),i.ZP.prototype.t=t,new(i.ZP.extend(U))({propsData:{initialDevices:(0,a.j)("settings","webauthn-devices"),isHttps:"https:"===window.location.protocol,isLocalhost:"localhost"===window.location.hostname,hasPublicKeyCredential:void 0!==window.PublicKeyCredential}}).$mount("#security-webauthn")},37311:(t,e,n)=>{"use strict";n.d(e,{Z:()=>s});var r=n(87537),i=n.n(r),a=n(23645),o=n.n(a)()(i());o.push([t.id,"\n.webauthn-loading[data-v-14a3490a] {\n\tdisplay: inline-block;\n\tvertical-align: sub;\n\tmargin-left: 2px;\n\tmargin-right: 2px;\n}\n.new-webauthn-device[data-v-14a3490a] {\n\tline-height: 300%;\n}\n","",{version:3,sources:["webpack://./apps/settings/src/components/WebAuthn/AddDevice.vue"],names:[],mappings:";AAmOA;CACA,qBAAA;CACA,mBAAA;CACA,gBAAA;CACA,iBAAA;AACA;AAEA;CACA,iBAAA;AACA",sourcesContent:["\x3c!--\n - @copyright 2020, Roeland Jago Douma \n -\n - @author Roeland Jago Douma \n -\n - @license GNU AGPL version 3 or any later version\n -\n - This program is free software: you can redistribute it and/or modify\n - it under the terms of the GNU Affero General Public License as\n - published by the Free Software Foundation, either version 3 of the\n - License, or (at your option) any later version.\n -\n - This program is distributed in the hope that it will be useful,\n - but WITHOUT ANY WARRANTY; without even the implied warranty of\n - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n - GNU Affero General Public License for more details.\n -\n - You should have received a copy of the GNU Affero General Public License\n - along with this program. If not, see .\n --\x3e\n\n\n\n