1import { 2 get, 3 parseRequestOptionsFromJSON 4} from '@github/webauthn-json/browser-ponyfill' 5 6import { conditionalMediationAvailable } from 'authentication/passkeys/conditional_mediation_available' 7 8const startConditionalMediation = async function (form) { 9 const available = await conditionalMediationAvailable() 10 console.log('startConditionalMediation', available) 11 if (!available) { return } 12 13 getChallengeAndSubmitCredential(form) 14} 15 16const getChallengeAndSubmitCredential = async function (form) { 17 const csrfToken = document.getElementsByName('csrf-token')[0].content 18 const credentialFieldName = form.dataset.credentialFieldName 19 const newChallengeURL = new URL(form.dataset.challengeUrl) 20 21 const challengeFetch = fetch(newChallengeURL, { 22 method: 'POST', 23 headers: { 24 Accept: 'application/json', 25 'X-CSRF-Token': csrfToken 26 } 27 }) 28 29 const challengeJSON = await (await challengeFetch).json() 30 const credentialAuthenticationOptions = parseRequestOptionsFromJSON({ publicKey: challengeJSON }) 31 32 const credentialAuthenticationResponse = await get(credentialAuthenticationOptions) 33 34 form.elements[credentialFieldName].value = JSON.stringify(credentialAuthenticationResponse) 35 form.submit() 36} 37 38const submitFormEvent = async function (event) { 39 event.preventDefault() 40 event.stopImmediatePropagation() 41 const form = event.currentTarget 42 getChallengeAndSubmitCredential(form) 43} 44 45export { startConditionalMediation, submitFormEvent }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.