Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 7, 2022
Merged

Conversation

martincostello
Copy link
Contributor

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.

Use the `IdentityUserClaim<T>.ToClaim()` method to create `Claim` instances from claim entities so that overridden behaviours are observed.
@dlmelendez dlmelendez changed the base branch from master to rel/7.1 December 7, 2022 03:34
@dlmelendez dlmelendez merged commit eba042b into dlmelendez:rel/7.1 Dec 7, 2022
@martincostello martincostello deleted the Use-ToClaim branch December 7, 2022 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants