public SecuredController() { _sb = new StringBuilder(); _principal = (ClaimsPrincipal)Thread.CurrentPrincipal; _sb.Append("My UserName is " + _principal.GetStringValue(ClaimTypes.Name) + ". "); _sb.Append("My real name is " + _principal.GetStringValue(ClaimTypes.GivenName) + ". "); _sb.Append("My email address is " + _principal.GetStringValue(ClaimTypes.Email) + ". "); }
public User BuildUserFromPrincipal(ClaimsPrincipal principal) { string[] names = principal.GetStringValue(ClaimTypes.GivenName).Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); User user = new User() { UserName = principal.GetStringValue(ClaimTypes.Name), FirstName = names.First(), LastName = names.Last(), Email = principal.GetStringValue(ClaimTypes.Email) }; return user; }