Ejemplo n.º 1
0
 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) + ". ");
 }
Ejemplo n.º 2
0
        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;
        }