ManagementApiClient missing FirstName LastName

I have a set of users from Username-Password-Authentication connection setup.
These users do not come with given_name and family_name so I added them to user_metadata information like
user_metadata: { "given_name": "FirstName", "family_name": "LastName", }

and I made a new Rule to add them to the user context like
if (user.user_metadata.given_name) {
user.given_name = user.user_metadata.given_name; }
if (user.user_metadata.family_name) {
user.family_name = user.user_metadata.family_name; }

The resulting user context looks fine and it has given_name and family_name the same way that other users have.

The problem is that when I use Management API in C# the FirstName and LastName are empty strings for these users.

var client = new ManagementApiClient(tokenResponse.AccessToken, new Uri(_auth0Options.Value.ApiIdentifier)); var users = await client.Users.GetAllAsync(); var result= users.Select(p => new { p.FirstName, p.LastName, })

hi @arazmjou I’m trying to understand your question a bit more… is it C# just putting empty strings there or just not able to retrieve the fields (family_name for example) from user_metadata? I think it’s the latter but trying to understand what’s your issue since I cannot see it from that code snippet. Thanks in advance.

The quick fix for that would be to use UserMetadata directly

var users = await client.Users.GetAllAsync();  
            var enumerable = users
                .Select(p => new
                {
                    FirstName = string.IsNullOrWhiteSpace(p.FirstName) ? p.UserMetadata?.given_name : p.FirstName,
                    LastName = string.IsNullOrWhiteSpace(p.LastName) ? p.UserMetadata?.family_name : p.LastName});

But I wish I could get the FirstName and the LastName directly from the API like:

 var client = new ManagementApiClient(tokenResponse.AccessToken, 
           new Uri(_auth0Options.Value.ApiIdentifier));      
var users = await client.Users.GetAllAsync(); 
var result= users.Select(p => new {p.FirstName, p.LastName })

As I already have a rule

function (user, context, callback) {  
  if (user.user_metadata.given_name) 
    user.given_name = user.user_metadata.given_name;
  
  if (user.user_metadata.family_name) 
    user.family_name = user.user_metadata.family_name;   
  callback(null, user, context);
}

Hey there!

Sorry for such huge delay in response! We’re doing our best in providing you with best developer support experience out there, but sometimes our bandwidth is not enough comparing to the number of incoming questions.

Wanted to reach out to know if you still require further assistance?

I’m just adding things using the standard Auth0 interface to create a number of user with all associated details based on what eventually our organisation is going to be doing once the business has finally sorted out the requirements. I need to get things moving along so we don’t have to many delays, yet as details are still being ignored and fiddly aspects of business process are under consideration I can’t justify the business case for anything as complex as an actual running application.
So I can only configure Auth0 as much as possible using its own interface to cover a fully federated SSO authentication model using SAML with a couple of dozen test accounts with anticipated roles and special metadata attributes.
Some of the special metadata we will need is First Name, Last Name, and Middle Name, Roles, and additional special ones for various other integrations.

Now my Question is how do I show/demonstrate these in the User profile of Auth0 to Business people that do not care about or want to ever see any JSON?

It’s this demonstration that could convince them Auth0 is go enough for me to start cutting code on new applications and integrating with existing applications.