【问题标题】:Missing user_metadata in userInfo of auth0auth0 的 userInfo 中缺少 user_metadata
【发布时间】:2017-09-29 17:45:09
【问题描述】:

对于身份验证,我使用的是 Auth0 AuthenticationApi。在帐户控制器中,我需要获取 user_metadata 但它丢失了。获取 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 ?
                }

【问题讨论】:

    标签: authentication model-view-controller oauth-2.0 auth0


    【解决方案1】:

    是的,就我现在所见,旧调用仍然有效。但是,我还没有非传统的解决方案:(

      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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-20
      • 2017-10-04
      • 2021-08-08
      • 2017-07-11
      • 2017-10-18
      • 2019-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多