Пример #1
0
        private ClaimsPrincipal ObtenerPrincipalPorToken(string token)
        {
            var api = new SearchBestPrice();

            if (api.CheckValidToken(Guid.Parse(token)))
            {
                User user          = api.GetUserByToken(Guid.Parse(token));
                var  usernameClaim = new Claim(ClaimTypes.Name, user.Name);
                var  roleClaim     = new Claim(ClaimTypes.Role, user.Role);
                var  emailClaim    = new Claim(ClaimTypes.Email, user.Mail);
                var  IdClaim       = new Claim(ClaimTypes.Sid, user.Id.ToString());
                var  identity      = new ClaimsIdentity(new[] { usernameClaim, roleClaim, emailClaim, IdClaim }, "token");
                var  principal     = new ClaimsPrincipal(identity);

                return(principal);
            }

            return(null);
        }