lbuchs / WebAuthn

A simple PHP WebAuthn (FIDO2/Passkey) server library
https://webauthn.lubu.ch
MIT License
419 stars 75 forks source link

Only exactly one of 'password', 'federated', and 'publicKey' credential types are currently supported. #84

Closed Whip closed 5 months ago

Whip commented 5 months ago

I followed your _test code to create a new registration. The request is sent to the server and I get this response back

1706769509

But then I get error from navigator.credentials.create() - Only exactly one of 'password', 'federated', and 'publicKey' credential types are currently supported.

Here's my code:

G.ajax({
    type: 'POST',
    data: {
        action: 'newRegistration',
        name: nameField.value,
        email: emailField.value
    }
}).then(data => {
    console.log(JSON.parse(data.responseText)); // output posted above as screenshot
    const publicKeyCredentialCreationOptions = recursiveBase64StrToArrayBuffer(JSON.parse(data.responseText));

    navigator.credentials.create(publicKeyCredentialCreationOptions).then(response => {
        console.log(response);

    }).catch(err => {
        console.log(err);
    });
}).catch(xhr => {
    console.log('Failed', xhr);
    handleError('Request timed out or was denied. Tap Sign in again to start over');
});

What is the reason for this? Is my JSON wrong?

lbuchs commented 5 months ago

Do you use the recursiveBase64StrToArrayBuffer function from my example?

It does not have a response, it takes a reference of a object and modifies it:

const publicKeyCredentialCreationOptions = JSON.parse(data.responseText);
recursiveBase64StrToArrayBuffer(publicKeyCredentialCreationOptions);

navigator.credentials.create(publicKeyCredentialCreationOptions).then(.........
Whip commented 5 months ago

That's it. It worked. Thanks a bunch.