From 0c070894ac79a825ec7fddd710197b0421e8ae8a Mon Sep 17 00:00:00 2001 From: horus Date: Mon, 20 Mar 2023 06:00:00 +0800 Subject: [PATCH] fix: update webauthn authenticate (#36) Co-authored-by: Anthony Lukin --- src/data/webAuthnAuthenticate.ts | 24 ++++++++++--------- .../resources/dist/webAuthnAuthenticate.js | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/data/webAuthnAuthenticate.ts b/src/data/webAuthnAuthenticate.ts index 5b95f0af7..8aab5bb94 100644 --- a/src/data/webAuthnAuthenticate.ts +++ b/src/data/webAuthnAuthenticate.ts @@ -8,7 +8,7 @@ type DataType = { type RefsType = { authenticatorDataInput: HTMLInputElement; - authnSelectForm: HTMLFormElement; + authnSelectForm?: HTMLFormElement; clientDataJSONInput: HTMLInputElement; credentialIdInput: HTMLInputElement; errorInput: HTMLInputElement; @@ -114,17 +114,19 @@ document.addEventListener('alpine:init', () => { const checkAllowCredentials = () => { const allowCredentials: PublicKeyCredentialDescriptor[] = []; - const authnSelectFormElements = Array.from(authnSelectForm.elements); + if (authnSelectForm) { + const authnSelectFormElements = Array.from(authnSelectForm.elements); - if (authnSelectFormElements.length) { - authnSelectFormElements.forEach((element) => { - if (element instanceof HTMLInputElement) { - allowCredentials.push({ - id: base64url.parse(element.value, { loose: true }), - type: 'public-key', - }); - } - }); + if (authnSelectFormElements.length) { + authnSelectFormElements.forEach((element) => { + if (element instanceof HTMLInputElement) { + allowCredentials.push({ + id: base64url.parse(element.value, { loose: true }), + type: 'public-key', + }); + } + }); + } } doAuthenticate(allowCredentials); diff --git a/theme/keywind/login/resources/dist/webAuthnAuthenticate.js b/theme/keywind/login/resources/dist/webAuthnAuthenticate.js index d3503fa8c..b9fa83123 100644 --- a/theme/keywind/login/resources/dist/webAuthnAuthenticate.js +++ b/theme/keywind/login/resources/dist/webAuthnAuthenticate.js @@ -1 +1 @@ -import{m as g}from"./assets/module.esm-62c37d0d.js";import{b as n}from"./assets/index-a7b84447.js";document.addEventListener("alpine:init",()=>{g.data("webAuthnAuthenticate",function(){const{authenticatorDataInput:c,authnSelectForm:l,clientDataJSONInput:p,credentialIdInput:f,errorInput:r,signatureInput:d,userHandleInput:h,webAuthnForm:i}=this.$refs,{challenge:m,createTimeout:s,isUserIdentified:A,rpId:w,unsupportedBrowserText:y,userVerification:o}=this.$store.webAuthnAuthenticate,u=a=>{if(!window.PublicKeyCredential){r.value=y,i.submit();return}const t={challenge:n.parse(m,{loose:!0}),rpId:w};a.length&&(t.allowCredentials=a),parseInt(s)!==0&&(t.timeout=parseInt(s)*1e3),o!=="not specified"&&(t.userVerification=o),navigator.credentials.get({publicKey:t}).then(e=>{e instanceof PublicKeyCredential&&e.response instanceof AuthenticatorAssertionResponse&&(window.result=e,c.value=n.stringify(new Uint8Array(e.response.authenticatorData),{pad:!1}),p.value=n.stringify(new Uint8Array(e.response.clientDataJSON),{pad:!1}),d.value=n.stringify(new Uint8Array(e.response.signature),{pad:!1}),f.value=e.id,e.response.userHandle&&(h.value=n.stringify(new Uint8Array(e.response.userHandle),{pad:!1})),i.submit())}).catch(e=>{r.value=e,i.submit()})},b=()=>{const a=[],t=Array.from(l.elements);t.length&&t.forEach(e=>{e instanceof HTMLInputElement&&a.push({id:n.parse(e.value,{loose:!0}),type:"public-key"})}),u(a)};return{webAuthnAuthenticate:()=>{if(!A){u([]);return}b()}}})}); +import{m as g}from"./assets/module.esm-62c37d0d.js";import{b as n}from"./assets/index-a7b84447.js";document.addEventListener("alpine:init",()=>{g.data("webAuthnAuthenticate",function(){const{authenticatorDataInput:l,authnSelectForm:r,clientDataJSONInput:p,credentialIdInput:f,errorInput:s,signatureInput:d,userHandleInput:h,webAuthnForm:a}=this.$refs,{challenge:m,createTimeout:o,isUserIdentified:A,rpId:w,unsupportedBrowserText:y,userVerification:u}=this.$store.webAuthnAuthenticate,c=i=>{if(!window.PublicKeyCredential){s.value=y,a.submit();return}const t={challenge:n.parse(m,{loose:!0}),rpId:w};i.length&&(t.allowCredentials=i),parseInt(o)!==0&&(t.timeout=parseInt(o)*1e3),u!=="not specified"&&(t.userVerification=u),navigator.credentials.get({publicKey:t}).then(e=>{e instanceof PublicKeyCredential&&e.response instanceof AuthenticatorAssertionResponse&&(window.result=e,l.value=n.stringify(new Uint8Array(e.response.authenticatorData),{pad:!1}),p.value=n.stringify(new Uint8Array(e.response.clientDataJSON),{pad:!1}),d.value=n.stringify(new Uint8Array(e.response.signature),{pad:!1}),f.value=e.id,e.response.userHandle&&(h.value=n.stringify(new Uint8Array(e.response.userHandle),{pad:!1})),a.submit())}).catch(e=>{s.value=e,a.submit()})},b=()=>{const i=[];if(r){const t=Array.from(r.elements);t.length&&t.forEach(e=>{e instanceof HTMLInputElement&&i.push({id:n.parse(e.value,{loose:!0}),type:"public-key"})})}c(i)};return{webAuthnAuthenticate:()=>{if(!A){c([]);return}b()}}})});