Missing user_metadata in userInfo auth0

For authentication I am using Auth0 AuthenticationApi. In Account Controller, I need to get user_metadata, but it is missing. Any alternative for getting 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 ?
                }

      

+3


source to share


1 answer


Yes, as far as I can see now, the legacy call still works. However, I don't have a yet deprecated solution :(



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

      

0


source







All Articles