예제 #1
0
        public async Task <ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal)
        {
            if (principal != null && principal.Identity.IsAuthenticated && principal.Claims.Any(a => a.Type == JwtClaimTypes.Subject))
            {
                IEnumerable <string> roles;
                try
                {
                    roles = await _userManagementClient.GetRoles();
                }
                catch (ClientResponseException)
                {
                    return(principal);
                }

                if (roles != null && roles.Any())
                {
                    var claims = roles.Select(role => new Claim(JwtClaimTypes.Role, role));

                    var id = ((ClaimsIdentity)principal.Identity);
                    id.AddClaims(claims);
                }
            }

            return(principal);
        }
예제 #2
0
 public Task <IEnumerable <string> > GetUserRoles()
 {
     return(_userManagementClient.GetRoles());
 }