How can I request only some of profile information?

Hi,
I need only some of information that the profile scope returns. I need only picture and nickname. So I opened the /.well-known/openid-configuration and see that scopes like picture and other are supported. So I tried requesting openid picture nickname, and I got only openid. So I saw that claims are supported. So I requested claims like it (value of claims parameter in request):

{
   "id_token":{
      "nickname":{
         "essential":true
      },
      "picture":{
         "essential":true
      }
   }
}

and my id_token doesnt contain requested claims. So how can I request only some of claims that profile scope provides?

Hi @Szyszka947,

Welcome to the Auth0 Community!

Unfortunately, the picture and nickname are not legitimate scopes that you can request.

When passing the profile scope in the request, you will get the claims that represent the basic profile information, which includes name, family_name, given_name, middle_name, nickname, picture, and updated_at claims.

See OpenID Connect Scopes for more details on the OIDC Scopes.

Now, if you must require only a subset of these claims, like only having picture and nickname, you will have to write a Post-Login Action to append them as custom claims.

For example:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://myapp.example.com';
  if (event.authorization) {
    // Set claims in ID token
    api.idToken.setCustomClaim(`${namespace}/nickname`, event.user.nickname);
    api.idToken.setCustomClaim(`${namespace}/picture`, event.user.picture);
    
    // Set claims in access token
    api.accessToken.setCustomClaim(`${namespace}/nickname`, event.user.nickname);
    api.accessToken.setCustomClaim(`${namespace}/picture`, event.user.picture);
};

Thanks,
Rueben

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