I am able to login to the application but still I am not getting the roles in the user response, here is my code may this help you understanding if i m doing something wrong here:
When user clicks on login button, here is the implementation that runs to open the Auth0 login:
if (_settingManager.UseAuth0Authentication)
{
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties
{
RedirectUri = Url.Action("Auth0LoginCallback", "Account")
},
"Auth0");
return new HttpUnauthorizedResult();
}
And when I get the callback on the Auth0LoginCallback
, here is what i am doing there:
public ActionResult Auth0LoginCallback()
{
string username = User.Identity.Name;
var user = _userProfileManager.FindByUserProfileName(username);
if (user == null)
{
UserProfile userProfile = new UserProfile()
{
UserName = username
};
_userProfileManager.CreateUserProfile(userProfile);
}
return Redirect(Url.Action("Index", "Main"));
}
Here I am hoping to get the user role in the User object, I am getting all the information but not role.
Here are the User and User.Identity object data:
User:
{System.Web.Security.RolePrincipal}
CachedListChanged: false
Claims: {System.Security.Claims.ClaimsPrincipal.<get_Claims>d__37}
CookiePath: "/"
CustomSerializationData: null
ExpireDate: {27-03-2020 13:30:15}
Expired: false
Identities: Count = 1
Identity: {System.Security.Claims.ClaimsIdentity}
IsRoleListCached: false
IssueDate: {27-03-2020 13:00:15}
ProviderName: "AspNetSqlRoleProvider"
Version: 1
User.Identity
{System.Security.Claims.ClaimsIdentity}
Actor: nullUser
AuthenticationType: "Cookies"
BootstrapContext: null
Claims: {System.Security.Claims.ClaimsIdentity.<get_Claims>d__51}
CustomSerializationData: null
IsAuthenticated: true
Label: null
Name: "rakesh@gmail.com"
NameClaimType: "name"
RoleClaimType: "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
The Role Rue is enabled from the Auth0 dashboard and this user has the Role assigned as well. I see the RoleClaimType
but not sure if that can be of help here.
Please let me know if i need to do something to make it work. Thank you for your help.