-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
The new version of .NET Identity in .NET 10 includes support for Passkeys. This requires the addition of an AspNetUserPasskeys table in your .NET Identity database. This is accomplished by specifying Version3 in your .NET Identity service registration:
options.Stores.SchemaVersion = IdentitySchemaVersions.Version3
The IdentityUserPasskey class contains a property named Data:
The Data column is of type IdentityPasskeyData:
IdentityPasskeyData contains properties with non-primitive types (ie. string[])
When the IdentityUserPasskey class is mapped by EF Core:
It uses the following syntax:
builder.Entity<TUserPasskey>(b =>
{
b.HasKey(p => p.CredentialId);
b.ToTable("AspNetUserPasskeys");
b.Property(p => p.CredentialId).HasMaxLength(1024); // Defined in WebAuthn spec to be no longer than 1023 bytes
b.OwnsOne(p => p.Data).ToJson();
});
The method ToJson() which is used for the Data property is NOT supported by any current MySQL database provider (ie. MySQL.EntityFrameworkCore or Pomelo.EntityFrameworkCore.MySql). When trying to use the new .NET Identity in .NET 10 with a MySQL database provider you will encounter an error:
The property 'IdentityPasskeyData.Transports' could not be mapped because it is of type 'string[]', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'. at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IConventionTypeBase structuralType, IConventionModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger) at MySql.EntityFrameworkCore.Internal.MySQLModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger)
This is a blocker from using the new .NET Identity with Passkey support in .NET 10.
Expected Behavior
.NET Identity has traditionally provided support for multiple types of databases including MySQL. The new .NET Identity provider in .NET 10 should support MySQL.
Steps To Reproduce
- scaffold a web app in .NET 10, specifying the "Individual Accounts for authentication" option
- add a reference to MySQL.EntityFrameworkCore 10.0.0-rc
- use MySQL in your DbContext
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySQL(connectionString)
);
- update connection string in appsettings.json to point at MySQL database
- run migrations on the MySQL database
Exceptions (if any)
The property 'IdentityPasskeyData.Transports' could not be mapped because it is of type 'string[]', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'. at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IConventionTypeBase structuralType, IConventionModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger) at MySql.EntityFrameworkCore.Internal.MySQLModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger)
.NET Version
10.0.0
Anything else?
Note that it is possible to use .NET Identity in .NET 10 with MySQL if you specify the SchemaVersion as Version2 in the .NET Identity service registration:
options.Stores.SchemaVersion = IdentitySchemaVersions.Version2
Essentially this is a feature flag which disables Passkey support in .NET Identity and allows the data mapping issue to be avoided.