How do you get all user profiles in Auth0 data store and display in a ASP.NET Core MVC view?

I have looked at numerous articles, documentation and I am hopelessly lost. What I have been able to do is successfully create a rule in Auth0 to pass the user’s information to my JWT. But I do not know how to read the user profiles in the client.

I just want to extract the JTW information from a claim so I can render all user profile names to a view in a html table.

Steps to reproduce:

Here is the code for my User\Index.cs controller file where I am having the problem:

        [Authorize(Roles = "admin")]
        public IActionResult Index()
        {
            //PROBLEM: get all user profile values, email,name and role.
            //EXTRACT claim from token.
            //CREATE
            foreach(var profile in User.Claims.ToList())
            {
                AuthenticationServiceUserProfile objAuth0Users = new AuthenticationServiceUserProfile();
                {
                     //TODO: Need to read users from this controller.
                }
            }
            string userSessionEmail = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value;
            return View();
        }

Here is the rule I am using:

	function (user, context, callback) 
	{
	  const namespace = 'https://schemas.Aussie_Tenant.com/';
	  // TODO: Get profile values.
	  context.idToken[namespace + 'user_metadata'] = user.email;
	  context.idToken[namespace + 'user_metadata'] = user.name;
	  context.idToken[namespace + 'user_metadata'] = user.app_metadata.roles;
	  return callback(null, user, context);
	}

Here is the code for the AuthenticationServiceUserProfile model.

	public class AuthenticationServiceUserProfile
	{

		public string UserEmailAddress { get; set; }

		public string UserName { get; set; }        
		
		public string UserProfileImage { get; set; }
	}

Environment data:
dotnet --info output:
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64

ASP.NET Core 2.2

Hi Jords,

You want the management API, in particular the list/get users:

This SDK may be of use to you:
https://auth0.github.io/auth0.net/

John

Hi John,

Ok I’m really confused. I’m very new to Auth0. I’ve only being using the tech for a few months. I don’t know how to use the Auth0 API Management document. i.e I don’t know what values I could already input to test the feature in the documentation.

The other link you provided describing the Auth0 .NET SDK is of more help. I’ve changed my Index controller method and have made an instance of the of the ManagementAPIClient.

However I do not know what arguments to input for the GetAllAsync method and get the error.

There is no argument given that corresponds to the required formal parameter ‘request’ of ‘UsersClient.GetAllAsync(GetUsersRequest, PaginationInfo)’

Another thing I have noticed while looking at the User search doc is this note.

Most user profile fields are not returned as part of an ID Token, nor are they included in the response from the /userinfo endpoint of the Authentication API.

That means the management API won’t work for me? Because Most of the info I want to return is actually in the profile fields and not user_metadata with the exception of my roles which is stored in app_metadata.

Here is he current code if it helps explain.

    [Authorize(Roles = "admin")]
    public async Task <IActionResult> Index()
    {
        //auth0 management API.
        var apiClient = new ManagementApiClient(Pitcher.Models.ConstantStrings.strToken, "dev-dgdfgfdgf324.au.auth0.com");
        var allUsers = await apiClient.Users.GetAllAsync();
        
        allUsers.Dispose();
        return View();            
    }

Hi @Jords

The full user info is available via the management API.

If you go to the management API link above and set the token (there are instructions when you click on the button), you can try the get_users call and see the result.

John

2 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.