lbuchs / WebAuthn

A simple PHP WebAuthn (FIDO2/Passkey) server library

Home Page:https://webauthn.lubu.ch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Whip opened this issue · comments

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?

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(.........

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