settings-vue-settings-personal-webauthn.mjs 8.5 KB

12
  1. /*! third party licenses: dist/vendor.LICENSE.txt */
  2. import{bV as L,bZ as S,bR as C,cr as M,bS as m,F as q,al as z,b as V,v as j,a7 as J,aV as G,b_ as U}from"./core-common.mjs";import{a as Z,b as K}from"./chunks/index-CPIrzAK_.mjs";import{x as R}from"./chunks/index-CDMqmWCu.mjs";import{r as Q,a as X,c as tt}from"./chunks/convert-uH8MyJU8.mjs";import{_ as et,r as nt,a as it}from"./chunks/_baseIteratee-CdKuEoft.mjs";import{_ as st}from"./chunks/_baseEach-BuCj9lAy.mjs";import{i as rt,c as at,e as ot,f as ct}from"./chunks/_overRest-DjFtaWRq.mjs";import{i as ut}from"./chunks/isSymbol-CFNg2trq.mjs";import{a as dt,b as lt}from"./chunks/_isIterateeCall-CX-rKv74.mjs";import"./chunks/index-PaKKd09k.mjs";import{z as vt}from"./chunks/_plugin-vue2_normalizer-VrK6B12S-BQkexw0P.mjs";import{l as p}from"./chunks/logger-C7fGMvfA.mjs";import{n as E}from"./chunks/icons-TElqpmA8.mjs";import"./chunks/_setToArray-V03nfpyh.mjs";import"./chunks/toNumber-OniEEhDz.mjs";import"./chunks/isPlainObject-CnMaw-ru.mjs";import"./chunks/index-CiG5J8j_.mjs";var w,I;function ht(){if(I)return w;I=1;var e=st,n=rt;function i(s,u){var a=-1,r=n(s)?Array(s.length):[];return e(s,function(c,v,h){r[++a]=u(c,v,h)}),r}return w=i,w}var b,T;function pt(){if(T)return b;T=1;function e(n,i){var s=n.length;for(n.sort(i);s--;)n[s]=n[s].value;return n}return b=e,b}var _,x;function ft(){if(x)return _;x=1;var e=ut;function n(i,s){if(i!==s){var u=i!==void 0,a=i===null,r=i===i,c=e(i),v=s!==void 0,h=s===null,d=s===s,o=e(s);if(!h&&!o&&!c&&i>s||c&&v&&d&&!h&&!o||a&&v&&d||!u&&d||!r)return 1;if(!a&&!c&&!o&&i<s||o&&u&&r&&!a&&!c||h&&u&&r||!v&&r||!d)return-1}return 0}return _=n,_}var y,B;function gt(){if(B)return y;B=1;var e=ft();function n(i,s,u){for(var a=-1,r=i.criteria,c=s.criteria,v=r.length,h=u.length;++a<v;){var d=e(r[a],c[a]);if(d){if(a>=h)return d;var o=u[a];return d*(o=="desc"?-1:1)}}return i.index-s.index}return y=n,y}var A,W;function mt(){if(W)return A;W=1;var e=et,n=nt(),i=it,s=ht(),u=pt(),a=ot,r=gt(),c=at,v=ct;function h(d,o,k){o.length?o=e(o,function(l){return v(l)?function(g){return n(g,l.length===1?l[0]:l)}:l}):o=[c];var O=-1;o=e(o,a(i));var Y=s(d,function(l,g,Mt){var F=e(o,function(H){return H(l)});return{criteria:F,index:++O,value:l}});return u(Y,function(l,g){return r(l,g,k)})}return A=h,A}var N,$;function wt(){if($)return N;$=1;var e=Q(),n=mt(),i=dt,s=lt,u=i(function(a,r){if(a==null)return[];var c=r.length;return c>1&&s(a,r[0],r[1])?r=[]:c>2&&s(r[0],r[1],r[2])&&(r=[r[0]]),n(a,e(r,1),[])});return N=u,N}var bt=tt,P=bt("sortBy",wt());P.placeholder=X();var _t=P;const yt=L(_t);async function At(){const e=S("/settings/api/personal/webauthn/registration");try{p.debug("Fetching webauthn registration data");const{data:n}=await C.get(e);return p.debug("Start webauthn registration"),await Z(n)}catch(n){throw p.error(n),M.isAxiosError(n)?new Error(m("settings","Could not register device: Network error")):n.name==="InvalidStateError"?new Error(m("settings","Could not register device: Probably already registered")):new Error(m("settings","Could not register device"))}}async function Nt(e,n){const i=S("/settings/api/personal/webauthn/registration");return(await C.post(i,{name:e,data:JSON.stringify(n)})).data}async function Dt(e){const n=S("/settings/api/personal/webauthn/registration/".concat(e));await C.delete(n)}const D=e=>n=>(p.debug(e),n),f=Object.freeze({READY:1,REGISTRATION:2,NAMING:3,PERSIST:4}),Rt={name:"AddDevice",components:{NcButton:q,NcTextField:z},props:{httpWarning:Boolean,isHttps:{type:Boolean,default:!1},isLocalhost:{type:Boolean,default:!1}},setup(){return{RegistrationSteps:f}},data(){return{name:"",credential:{},step:f.READY}},watch:{step(){this.step===f.NAMING&&this.$nextTick(()=>{var e;return(e=this.$refs.nameInput)==null?void 0:e.focus()})}},methods:{async start(){this.step=f.REGISTRATION,console.debug("Starting WebAuthn registration");try{await R(),this.credential=await At(),this.step=f.NAMING}catch(e){vt(e),this.step=f.READY}},submit(){return this.step=f.PERSIST,R().then(D("confirmed password")).then(this.saveRegistrationData).then(D("registration data saved")).then(()=>this.reset()).then(D("app reset")).catch(console.error)},async saveRegistrationData(){try{const e=await Nt(this.name,this.credential);p.info("new device added",{device:e}),this.$emit("added",e)}catch(e){throw p.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=f.READY}}};var St=function(){var e=this,n=e._self._c;return!e.isHttps&&!e.isLocalhost?n("div",[e._v(" "+e._s(e.t("settings","Passwordless authentication requires a secure connection."))+" ")]):n("div",[e.step===e.RegistrationSteps.READY?n("NcButton",{attrs:{type:"primary"},on:{click:e.start}},[e._v(" "+e._s(e.t("settings","Add WebAuthn device"))+" ")]):e.step===e.RegistrationSteps.REGISTRATION?n("div",{staticClass:"new-webauthn-device"},[n("span",{staticClass:"icon-loading-small webauthn-loading"}),e._v(" "+e._s(e.t("settings","Please authorize your WebAuthn device."))+" ")]):e.step===e.RegistrationSteps.NAMING?n("div",{staticClass:"new-webauthn-device"},[n("span",{staticClass:"icon-loading-small webauthn-loading"}),n("form",{on:{submit:function(i){return i.preventDefault(),e.submit.apply(null,arguments)}}},[n("NcTextField",{ref:"nameInput",staticClass:"new-webauthn-device__name",attrs:{label:e.t("settings","Device name"),value:e.name,"show-trailing-button":"","trailing-button-label":e.t("settings","Add"),"trailing-button-icon":"arrowRight"},on:{"update:value":function(i){e.name=i},"trailing-button-click":e.submit}})],1)]):e.step===e.RegistrationSteps.PERSIST?n("div",{staticClass:"new-webauthn-device"},[n("span",{staticClass:"icon-loading-small webauthn-loading"}),e._v(" "+e._s(e.t("settings","Adding your device …"))+" ")]):n("div",[e._v(" Invalid registration step. This should not have happened. ")])],1)},Ct=[],Et=E(Rt,St,Ct,!1,null,"0a462d60");const It=Et.exports,Tt={name:"Device",components:{NcActionButton:V,NcActions:j},props:{name:{type:String,required:!0}}};var xt=function(){var e=this,n=e._self._c;return n("li",{staticClass:"webauthn-device"},[n("span",{staticClass:"icon-webauthn-device"}),e._v(" "+e._s(e.name||e.t("settings","Unnamed device"))+" "),n("NcActions",{attrs:{"force-menu":!0}},[n("NcActionButton",{attrs:{icon:"icon-delete"},on:{click:function(i){return e.$emit("delete")}}},[e._v(" "+e._s(e.t("settings","Delete"))+" ")])],1)],1)},Bt=[],Wt=E(Tt,xt,Bt,!1,null,"13b18981");const $t=Wt.exports,Gt=yt("name"),Pt={components:{AddDevice:It,Device:$t,NcNoteCard:J},props:{initialDevices:{type:Array,required:!0},isHttps:{type:Boolean,default:!1},isLocalhost:{type:Boolean,default:!1}},setup(){return{supportsWebauthn:K()}},data(){return{devices:this.initialDevices}},computed:{sortedDevices(){return Gt(this.devices)}},methods:{deviceAdded(e){p.debug("adding new device to the list ".concat(e.id)),this.devices.push(e)},async deleteDevice(e){p.info("deleting webauthn device ".concat(e)),await R(),await Dt(e),this.devices=this.devices.filter(n=>n.id!==e),p.info("webauthn device ".concat(e," removed successfully"))}}};var kt=function(){var e=this,n=e._self._c;return n("div",{staticClass:"section",attrs:{id:"security-webauthn"}},[n("h2",[e._v(e._s(e.t("settings","Passwordless Authentication")))]),n("p",{staticClass:"settings-hint hidden-when-empty"},[e._v(" "+e._s(e.t("settings","Set up your account for passwordless authentication following the FIDO2 standard."))+" ")]),e.devices.length===0?n("NcNoteCard",{attrs:{type:"info"}},[e._v(" "+e._s(e.t("settings","No devices configured."))+" ")]):n("h3",{attrs:{id:"security-webauthn__active-devices"}},[e._v(" "+e._s(e.t("settings","The following devices are configured for your account:"))+" ")]),n("ul",{staticClass:"security-webauthn__device-list",attrs:{"aria-labelledby":"security-webauthn__active-devices"}},e._l(e.sortedDevices,function(i){return n("Device",{key:i.id,attrs:{name:i.name},on:{delete:function(s){return e.deleteDevice(i.id)}}})}),1),e.supportsWebauthn?e._e():n("NcNoteCard",{attrs:{type:"warning"}},[e._v(" "+e._s(e.t("settings","Your browser does not support WebAuthn."))+" ")]),e.supportsWebauthn?n("AddDevice",{attrs:{"is-https":e.isHttps,"is-localhost":e.isLocalhost},on:{added:e.deviceAdded}}):e._e()],1)},Ot=[],Yt=E(Pt,kt,Ot,!1,null,"85df54b3");const Ft=Yt.exports;G.prototype.t=t;const Ht=G.extend(Ft),Lt=U("settings","webauthn-devices");new Ht({propsData:{initialDevices:Lt,isHttps:window.location.protocol==="https:",isLocalhost:window.location.hostname==="localhost"}}).$mount("#security-webauthn");