# Cannot see role in User.Identity object

**URL:** <https://community.auth0.com/t/cannot-see-role-in-user-identity-object/56656>\
**Category:** Get Help\
**Tags:** aspnet-mvc, rules, auth0\
**Created:** [January 22, 2021, 1:11pm UTC](https://community.auth0.com/t/cannot-see-role-in-user-identity-object/56656 "2021-01-22T13:11:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gwhitdev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gwhitdev/32/25808_2.png) [@gwhitdev](https://community.auth0.com/u/gwhitdev)\
**Post date:** [January 22, 2021, 1:11pm UTC](https://community.auth0.com/t/cannot-see-role-in-user-identity-object/56656/1 "2021-01-22T13:11:18Z")

</div>

Hello,  
I have used the sample [Asp.Net](http://Asp.Net) MVC Core app to integrate my auth. I can login/out and see user profile details etc but the role claim isn’t appearing in the User.Idenity object.

GitHub: [MealSaverApp/MealSaverApp at main · gwhitdev/MealSaverApp · GitHub](https://github.com/gwhitdev/MealSaverApp/tree/main/MealSaverApp)

I’ve created a rule  
function setRolesToUser(user, context, callback) {  
// Roles should only be set to verified users.  
//  
if (!user.email || !user.email\_verified) {  
return callback(null, user, context);  
}

user.app\_metadata = user.app\_metadata || {};  
// You can add a Role based on what you want  
// In this case I check domain  
const addRolesToUser = function (user) {  
const endsWith = ‘@garethwhitley.online’;

if (  
user.email &&  
user.email.substring(  
user.email.length - endsWith.length,  
user.email.length  
) === endsWith  
) {  
return [‘admin’];  
}  
return [‘user’];  
};

```
  const roles = addRolesToUser(user);

  user.app_metadata.roles = roles;
  auth0.users
    .updateAppMetadata(user.user_id, user.app_metadata)
    .then(function () {
      context.idToken['https://mealsaverapp/roles'] = user.app_metadata.roles;
      callback(null, user, context);
    })
    .catch(function (err) {
      callback(err);
    });
}

```

I pre-populated the ‘admin’ role into two different users that I created and testing the rule shows the role appearing. However, when I run the app (locally and in Azure) the only claims I get are the ‘standard’ ones associated with the sample app. The NameClaimType comes through, but the RoleClaimType does not.

Any ideas?

---

<div class="post-metadata">

**Author:** ![gwhitdev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gwhitdev/32/25808_2.png) [@gwhitdev](https://community.auth0.com/u/gwhitdev)\
**Post date:** [January 22, 2021, 1:43pm UTC](https://community.auth0.com/t/cannot-see-role-in-user-identity-object/56656/2 "2021-01-22T13:43:26Z")

</div>

Ok. So, I don’t know if this is actually THE solution, but somehow I’ve managed to get it to work.

I added another authentication scheme in the Startup.cs for JwtDefaults and then added .AddJwtBearer with the authority and audience as options and… now it works!

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [January 22, 2021, 8:47pm UTC](https://community.auth0.com/t/cannot-see-role-in-user-identity-object/56656/3 "2021-01-22T20:47:30Z")

</div>

Thanks for sharing your solution!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 28, 2021, 3:56pm UTC](https://community.auth0.com/t/cannot-see-role-in-user-identity-object/56656/4 "2021-01-28T15:56:11Z")

</div>


