Empty user_metadata

I am trying to write a rule that will return a user’s user_metadata to me in C# using the following code…

var claimsIdentity = User.Identity as ClaimsIdentity;

string accessToken = claimsIdentity?.FindFirst(c => c.Type == "access_token")?.Value;
string idToken = claimsIdentity?.FindFirst(c => c.Type == "id_token")?.Value;

AuthenticationApiClient client = new AuthenticationApiClient(new Uri(string.Format("https://{0}", ConfigurationManager.AppSettings["auth0:Domain"])));
var profile = await client.GetUserInfoAsync(accessToken);

I have been playing with rules to help with this, and every time I try to get the user_metadata property, it is null, even when my user has user_metadata. When just trying the following in a rule, I get no data…

function (user, context, callback) {
  user.user_metadata = user.user_metadata || {};
  console.log(user.user_metadata.test);
  context.idToken['https://bzs-baplayground.auth0.com/user_metadata'] = user.user_metadata;
  callback(null, user, context);
}

I am able to see the data if I set the properties in a rule, but not when attempting to just reading the data. This returns data to C#…

user.user_metadata.name = "Jane Doe";
user.user_metadata.given_name = "Jane";
user.user_metadata.family_name = "Doe";
        
 auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
    .then(function() {
        context.idToken['https://bzs-baplayground.auth0.com/user_metadata'] = user.user_metadata;
        callback(null, user, context);
    })
    .catch(function (err) {
        callback(err);
    });

Thoughts as to why this is not working for me?

Hey there!

Sorry for such a delayed response! We’re doing our best in providing you with the best developer support experience out there but sometimes our bandwidth is just not enough for all the questions coming in. Sorry for the inconvenience!

Can you let us know if you still require further assistance from us?