I upgrade my project from .NET 7 to .NET 8. I know that there is a breaking change with the claims.
In .NET 7 I used to do:
return auth?.User?.Claims?.SingleOrDefault(x => x.Type == "email")?.Value;
In .NET 8, it looks like I need to do:
return auth?.User?.Claims?.SingleOrDefault(x => x.Type == @"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")?.Value;
Is there a better way to retrieve the email claim?
The System.Security.Claims
namespace holds a bunch of constants you can use for this. For example:
using System.Security.Claims;
...
return auth?.User?.Claims?
.SingleOrDefault(x => x.Type == ClaimTypes.Email)?.Value;