dlmelendez / identityazuretable

This project provides a high performance cloud solution for ASP.NET Identity Core using Azure Table storage replacing the Entity Framework / MSSQL provider.
MIT License
104 stars 27 forks source link

Use IdentityUserClaim<T>.ToClaim() to prevent data not being returned from table #102

Closed martincostello closed 1 year ago

martincostello commented 1 year ago

Use the IdentityUserClaim<T>.ToClaim() method to create Claim instances from claim entities so that overridden behaviours are observed.

Otherwise if a user creates a custom claim type, for example so they can store the claim issuer and claim value type, this information is lost when reading from the store as the additional data is not copied to the Claim instances created by the user store as only the Type and Value are used.

An example of such a type is below.

public sealed class ApplicationUserClaim : IdentityUserClaim
{
    public string? ClaimIssuer { get; set; }

    public string? ClaimValueType { get; set; }

    public override void InitializeFromClaim(Claim claim)
    {
        base.InitializeFromClaim(claim);

        ClaimIssuer = claim.Issuer;
        ClaimValueType = claim.ValueType;
    }

    public override Claim ToClaim()
        => new(ClaimType!, ClaimValue!, ClaimValueType, ClaimIssuer);
}

After this change, additional properties added to the claim entity are correctly materialised from the table.

The behaviour for the out-of-the-box implementation is unchanged as the default ToClaim() implementation does the same as the store code did before the change.