Browse Source

Map IdentityUserPasskey.Data as a json column for MySQL providers

pull/25896/head
maliming 1 week ago
parent
commit
7d3ba2ec40
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 25
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs

25
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs

@ -1,6 +1,8 @@
using System;
using System.Text.Json;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Volo.Abp.Users.EntityFrameworkCore;
@ -187,7 +189,28 @@ public static class IdentityDbContextModelBuilderExtensions
b.HasKey(p => p.CredentialId);
b.Property(p => p.CredentialId).HasMaxLength(IdentityUserPasskeyConsts.MaxCredentialIdLength); // Defined in WebAuthn spec to be no longer than 1023 bytes
b.OwnsOne(p => p.Data).ToJson();
if (builder.IsUsingMySQL())
{
/* MySQL providers do not support EF Core JSON columns (ToJson),
* so store Data as a serialized json column with the same column
* name and content. The comparer detects in-place mutations
* (e.g. sign count updates on login). */
b.Property(p => p.Data)
.HasColumnName(nameof(IdentityUserPasskey.Data))
.HasColumnType("json")
.HasConversion(
d => JsonSerializer.Serialize(d, (JsonSerializerOptions?)null),
s => JsonSerializer.Deserialize<IdentityPasskeyData>(s, (JsonSerializerOptions?)null)!,
new ValueComparer<IdentityPasskeyData>(
(l, r) => JsonSerializer.Serialize(l, (JsonSerializerOptions?)null) == JsonSerializer.Serialize(r, (JsonSerializerOptions?)null),
v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null).GetHashCode(),
v => JsonSerializer.Deserialize<IdentityPasskeyData>(JsonSerializer.Serialize(v, (JsonSerializerOptions?)null), (JsonSerializerOptions?)null)!));
}
else
{
b.OwnsOne(p => p.Data).ToJson();
}
b.ApplyObjectExtensionMappings();
});

Loading…
Cancel
Save