public static void SetUserClaims(this ClaimsPrincipal principal, IUserProfile user) { // ensure the local user id is stored in case we are using an external auth account var userId = principal.GetUserId(); if (user.Id != userId) { principal.AddOrUpdateClaimValue(Identity.HoodClaimTypes.LocalUserId, user.Id); } // Make sure the User.Identity.Name is set to the user's email. principal.AddOrUpdateClaimValue(HoodClaimTypes.UserName, user.Email); // Set the picture -if one is set in the user, then add the url to picture claim. if (user.AvatarJson.IsSet()) { principal.AddOrUpdateClaimValue(HoodClaimTypes.Picture, user.Avatar.LargeUrl); } // Set name/displayname - if set in the local user overwrite the claims. if (user.FirstName.IsSet()) { principal.AddOrUpdateClaimValue(ClaimTypes.GivenName, user.FirstName); } if (user.LastName.IsSet()) { principal.AddOrUpdateClaimValue(ClaimTypes.Surname, user.LastName); } principal.RemoveClaim(HoodClaimTypes.Nickname); if (user.DisplayName.IsSet()) { principal.AddOrUpdateClaimValue(HoodClaimTypes.Nickname, user.DisplayName); } principal.AddOrUpdateClaimValue(Identity.HoodClaimTypes.Anonymous, user.Anonymous.ToString()); }