2017-05-02 25 views
3

對於使用Auth0 AuthenticationApi的身份驗證。在帳戶控制器中,我需要獲取user_metadata但缺少它。取得user_metadata的任何替代方法?在auth0的userInfo中缺少user_metadata

AuthenticationApiClient client = new AuthenticationApiClient(new Uri($"https://{_auth0Options.Domain}/")); 

       var authenticateResponse = await client.GetTokenAsync(new ResourceOwnerTokenRequest 
       { 
        ClientId = _auth0Options.ClientId, 
        ClientSecret = _auth0Options.ClientSecret, 
        Scope = "openid", 
        Realm = _auth0Options.Connection, 
        Username = vm.EmailAddress, 
        Password = vm.Password 
       }); 
       var user = await client.GetUserInfoAsync(authenticateResponse.AccessToken); 
       if (user.UserMetadata != null) 
       { 
     // Giving error...any alternative to access the userMetaData ? 
       } 

回答

0

是的,就我現在看到的,傳統呼叫仍然有效。但是,我還沒有非遺留解決方案:(

using (var client = GetClient()) 
     { 
      var jObject = new JObject(new JProperty("id_token", id_token)); 


      var response = await client.PostAsJsonAsync("tokeninfo", jObject); 

      if (response.IsSuccessStatusCode) 
      { 
       var userProfileJson = JObject.Parse(await response.Content.ReadAsStringAsync()); 
       retVal.user_id = userProfileJson.Value<string>("user_id"); 
       retVal.email = userProfileJson.Value<string>("email"); 
       retVal.user_name = userProfileJson.Value<string>("nickname"); 
       if (userProfileJson.Value<string>("created_at") != null) 
       { 
        retVal.created_at = userProfileJson.Value<DateTime>("created_at"); 
       } 
       var exists = userProfileJson.TryGetValue("user_metadata", out JToken meta);