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