2017-05-18 4 views
1

사용자 이름과 암호를 사용하여 사용자를 인증하려고합니다. 응답으로 JWT를 검색하고 app_metadata에 저장된 그의 권한을 찾으려고합니다.Auth0 : 토큰에서 app_metadata 및 user_metadata를 검색하는 방법은 무엇입니까?

그러나 반환 된 id_token에는 user_metadata 또는 app_metadata가 없습니다.

자바 드라이버와 HTTP 호출을 시도했습니다.

자바 :

AuthAPI auth = new AuthAPI("my-domain.auth0.com", "my_client_id", "my_secret_id"); 
AuthRequest request = auth.login(username, password) 
     .setScope("openid app_metadata user_metadata"); 
try { 
    TokenHolder holder = request.execute(); 
    return holder; 
} catch (Auth0Exception e) { 
    throw new AuthentException("Error authenticating " + username, e); 
} 

HTTP 다음 id_token 반환

 final String req = "{" 
      + "\"username\":\"[email protected]\"," 
      + "\"password\":\"test\"," 
      + "\"scope\":\"openid app_metadata user_metadata\"," 
      + "\"client_id\":\"my_client_id\"," 
      + "\"client_secret\":\"my_secret_id\"," 
      + "\"grant_type\":\"password\"" 
      + "}"; 
    RestTemplate template = new RestTemplate(); 
    HttpHeaders headers = new HttpHeaders(); 
    headers.setContentType(MediaType.APPLICATION_JSON); 
    HttpEntity<String> entity = new HttpEntity<>(req, headers); 

    ResponseEntity<String> response = template.exchange("https://my-domain.auth0.com/oauth/token", HttpMethod.POST, entity, String.class); 

만 포함

function (user, context, callback) { 
    var namespace = 'https://my-domain.auth0.com/'; 
    if (context.idToken && user.user_metadata) { 
    context.idToken[namespace + 'user_metadata'] = user.user_metadata; 
    } 
    if (context.idToken && user.app_metadata) { 
    context.idToken[namespace + 'app_metadata'] = user.app_metadata; 
    } 
    callback(null, user, context); 
} 
:

{ 
    "email": "[email protected]", 
    "email_verified": true, 
    "iss": "https://my-domain.auth0.com/", 
    "sub": "auth0|xxx", 
    "aud": "my_client_id", 
    "exp": 1497744462, 
    "iat": 1495116462 
} 

내가 규칙을 추가하려

그리고 훅 :

module.exports = function(client, scope, audience, context, cb) { 
    var access_token = {}; 
    access_token.scope = scope; 
    access_token.scope.push('user_profile'); 
    cb(null, access_token); 
}; 

그러나 아무것도는 id_token에 메타 데이터를 추가합니다.

어떻게 이러한 메타 데이터를 검색 할 수 있습니까?

감사합니다.

답변

1

나는/OAuth를/RO 엔드 포인트가 작동하고 있음을 발견 https://auth0.com/docs/api/authentication#resource-owner

  final String req = "{" 
       + "\"username\":\"[email protected]\"," 
       + "\"password\":\"test\"," 
       + "\"scope\":\"" + settings.getScope() + "\"," 
       + "\"connection\":\"Username-Password-Authentication\"," 
       + "\"client_id\":\"" + settings.getClientId() + "\"," 
       + "\"grant_type\":\"password\"" 
       + "}"; 
     RestTemplate template = new RestTemplate(); 
     HttpHeaders headers = new HttpHeaders(); 
     headers.setContentType(MediaType.APPLICATION_JSON); 
     HttpEntity<String> entity = new HttpEntity<>(req, headers); 

     ResponseEntity<String> response = template.exchange("https://my-domain.auth0.com/oauth/ro", HttpMethod.POST, entity, String.class); 

하지만 자바 드라이버에 해당하는 찾을 수 없습니다 1.0.0