2017-12-15 1 views
0

신원 확인 서버 빠른 시작 응용 프로그램을 사용하고 있으며 userinfo 끝점을 호출 할 때 반환 할 역할 정보를 추가하고 싶습니다.신원 서버의 userinfo 끝점에 역할을 추가하는 방법

public Claim[] GetUserClaims(UserServiceProxy.Dto.User user) 

    { 
     return new Claim[] 
     { 
      new Claim(JwtClaimTypes.Name, user.Username), 
      new Claim(JwtClaimTypes.Email, user.Email), 
      new Claim(JwtClaimTypes.GivenName, user.Firstname), 
      new Claim(JwtClaimTypes.FamilyName, user.Lastname), 
      new Claim(JwtClaimTypes.Subject, user.Username), 
      new Claim(JwtClaimTypes.Role, user.Role ?? "normal"), //have added this 
     }; 
    } 

내가 호출하면이 내 GetProfileDataAsync

if (context.RequestedClaimTypes.Any()) 
     { 
      var user = UserClient.FindByUserName(context.Subject.GetSubjectId()); 
      if (user != null) 
      { 
       context.AddRequestedClaims(UserClient.GetUserClaims(user.Result.User)); 
      } 
     } 

에서 호출되는/연결/사용자 정보 엔드 포인트, 나는이 (어떤 역할을) 얻을 :

{ "이름을" "joe3", "GIVEN_NAME": "조", "FAMILY_NAME": "세", "하위": "joe3"}

답변

0

신경 쓰지 마, 나는 t 발견 그 문제는 내가 필요가 있다고했다 : 클라이언트의 AllowedScopes 목록에 역할 범위를 추가 GetIdentityResources

public static IEnumerable<IdentityResource> GetIdentityResources() 
{ 
    return new List<IdentityResource> 
    { 
     new IdentityResources.OpenId(), 
     new IdentityResources.Profile(), 
     new IdentityResources.Email(), 
     new IdentityResource{Name = "roles", UserClaims={JwtClaimTypes.Role}} 
    }; 
} 
  • 에 의해 반환 된 목록에 역할에 대한 새로운 아이덴티티 자원을 추가

    1. AllowedScopes = new List<string> 
            { 
             IdentityServerConstants.StandardScopes.OpenId, 
             IdentityServerConstants.StandardScopes.Profile, 
             IdentityServerConstants.StandardScopes.Email, 
             "roles", 
      
            }, 
      
    2. 요청에서 역할 범위에 대한 요청을 추가하십시오.

       "RequestedScopes": "openid profile email roles", 
      
  • +0

    예 는, 키 것은 당신의'ConfigureServices'에 어떻게 든 그냥'ApiResources' 이외에'IdentityResources'를 추가하는 것입니다. 그러면 여러분이 정의한'IdentityResources'는'userInfo' 엔드 포인트에서 제공 될 것입니다 – Mashton

    관련 문제