Auth0 Home Blog Docs

How can I request data from user_metadata and app_metadata?

profile
rules
user-creation
app_metadata
login

#1

Hello everyone,
I am trying to get the value of app_metadata and user_metadata on a user roles rule that you create:

In this way I am trying to obtain following the documentation of this link (I am working with angular 2):

https://auth0.com/docs/quickstart/spa/angular2/03-user-profile

CONFIGURATION:

auth0 = new auth0.WebAuth({
    clientID: 'client_id',
    domain: 'name.auth0.com',
    responseType: 'token id_token',
    audience: 'https://name.auth0.com/userinfo',
    redirectUri: 'http://localhost:4200/callback',      
    scope: 'openid profile'
  });

To get profile data use:

userProfile: any;

public getProfile(cb): void {

  const accessToken = localStorage.getItem('access_token');
  if (!accessToken) {
    throw new Error('Access token must exist to fetch profile');
  }

  const self = this;
  this.auth0.client.userInfo(accessToken, (err, profile) => {
    if (profile) {

      self.userProfile = profile;
    }
    cb(err, profile);
  });
}

But I never get the values of app_metadata and user_metadata

any solution?

Thank you


#2

See the following documentation regarding setting custom claims in the tokens:
https://auth0.com/docs/api-auth/tutorials/adoption/scope-custom-claims


#3