Wednesday, July 15, 2020

Claims Identity - Extract UPN from a claim (IIdentity)

A claim with the type IIdentity can contain multiple claims and quite often we may need to extract the value of a particular claim within. This is fairly simple like so:

var email = principal.FindFirst(ClaimTypes.Upn)?.Value;

Reference: https://docs.microsoft.com/en-us/azure/architecture/multitenant-identity/claims

No comments:

Regex Email validation in c# dot net core

 Use this regex /^_?[a-zA-Z0-9]([a-zA-Z0-9]*[._+-])*[a-zA-Z0-9_]+@(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.(?!-)[A-Za-z0-9-]{1,63}(?<!-))*\.[A-...