dotnet / dotnet/aspnetcore

Remove/mitigate the nullability of IdentityUserClaim's ClaimType and ClaimValue properties

Open
#52,504 2 comments 0 reactions 0 assignees View on GitHub
area-identity
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

The nullability of `IdentityUserClaim.ClaimType` and `IdentityUserClaim.ClaimValue` properties are misleading for users modifying the data directly. If a user does modify the data directly and sets a null value, `IdentityUserClaim.ToClaim()` will throw an `ArgumentNullException` because of the `Claim` class's constructor.

While I understand the intent of this is not to modify the data directly, there will be cases where some users will do it and they will assume that a null is valid value.

### Describe the solution you'd like

Unsure of which way to go on it and I think it needs a larger discussion.

One approach would be to remove the nullability for `IdentityUserClaim.ClaimType` and `IdentityUserClaim.ClaimValue` and force a migration on users

Another approach could be to change `IdentityUserClaim.ToClaim()` to return `Claim?`, which would imply if either `IdentityUserClaim.ClaimType` or`IdentityUserClaim.ClaimValue` is `null` then return `null`.

Another approach would be to document and recommend users adjust their DbContext accordingly, which would allow them to opt-in to the migration.

### Additional context

I can see that a similar issue https://github.com/dotnet/aspnetcore/issues/18679 exists and is closed, though I would like to see some guidance on how to approach the issue

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.