fido2-net-lib icon indicating copy to clipboard operation
fido2-net-lib copied to clipboard

Using Fido2NetLib with Microsoft Identity ASP.NET Core 6.0

Open andreizammit opened this issue 3 years ago • 9 comments

I am using Fido2NetLib with Microsoft Identity ASP.NET Core 6.0 and implemented a sample project using the demo code and samples supplied from this GitHub. When trying to register a user I am getting the following error:

"Failed to read the 'attestation' property from 'PublicKeyCredentialCreationOptions': The provided value '0' is not a valid enum value of type AttestationConveyancePreference."

The values being passed are:

Attestation Type = "none"
Authenticator Attachment = ""    
User Verification = "preferred"
Require Resident Key = "false"

Can someone give me any indicator what might be issue?

andreizammit avatar Dec 22 '21 09:12 andreizammit

It works for me in .NET 6.0

I suspect there is a json serialisation issue. The default of asp.net core is System.Text.Json which serializes enums as integers. This library uses Newtonsoft (or it changes to system.text.json, dont remember exactly...). try to return data objects using the libraries ToJson method. return Content(assertionOptions.ToJson(), "application/json");

dIeGoLi avatar Jan 07 '22 13:01 dIeGoLi

I have an example of this working here:

https://github.com/damienbod/AspNetCoreIdentityFido2Mfa

maybe you can compare

Greetings Damien

damienbod avatar Jan 08 '22 11:01 damienbod

I tried the same approach with ASP.NET Core 6 and ran into the same sort of serialization issues. I managed to get the default serializer to serialize to string, but the values don't match what is expected. I guess it's due to serialization settings. But after comparing your sources to mine @damienbod I can't find any custom serialization settings in your sample.

Are you using NewtonSoft or System.Text.Json?

wmeints avatar Jul 13 '22 19:07 wmeints

Turns out, you need to call ToJson() on the created CredentialsCreateOptions. This is not matching any of the samples or the docs but works great.

wmeints avatar Jul 15 '22 12:07 wmeints

Yes, we are in need of some update docs. Does anyone want to do a PR?

abergs avatar Jul 26 '22 13:07 abergs

I'll take a look and create a PR. I'm in the process of writing a blogpost, so it's the right timing :-)

wmeints avatar Aug 12 '22 13:08 wmeints

@wmeints I updated my identity samples and use System.Text.Json

damienbod avatar Aug 12 '22 14:08 damienbod

Do you still need the update for the docs?

wmeints avatar Aug 12 '22 14:08 wmeints

I believe so, this is a great package and more docs would be great

damienbod avatar Aug 12 '22 15:08 damienbod