# Cannot return required scope

**URL:** <https://community.auth0.com/t/cannot-return-required-scope/9485>\
**Category:** Get Help\
**Tags:** scope, rules, oidc\
**Created:** [February 14, 2018, 2:23am UTC](https://community.auth0.com/t/cannot-return-required-scope/9485 "2018-02-14T02:23:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![seqq86](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@seqq86](https://community.auth0.com/u/seqq86)\
**Post date:** [February 14, 2018, 2:23am UTC](https://community.auth0.com/t/cannot-return-required-scope/9485/1 "2018-02-14T02:23:17Z")

</div>

Hi, I use non-OIDC authentication and I am requesting scope user\_metadata.  
Also I have rule:

```
    function (user, context, callback) {
      user.user_metadata = user.user_metadata || {}; 
      user.user_metadata.signup = true;
    
      auth0.users.updateUserMetadata(user.user_id, user.user_metadata);
      callback(null, user, context);
    }

```

But it does not return required scope.  
Can you tell, please, what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![ricardo.batista](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ricardo.batista/32/7711_2.png) [@ricardo.batista](https://community.auth0.com/u/ricardo.batista)\
**Post date:** [February 15, 2018, 1:41am UTC](https://community.auth0.com/t/cannot-return-required-scope/9485/2 "2018-02-15T01:41:45Z")

</div>

If you’re using a non-OIDC client (a client with the \*\* Client Settings \> Advanced Settings \> OAuth \> OIDC Conformant\*\* switch disabled in the [dashboard](https://manage.auth0.com/#/clients), you should be able to retrieve the user\_metadata by adding it in the scope, for your authentication request.

As an example, if you’re using [Auth0.js] ([GitHub - auth0/auth0.js: Auth0 headless browser sdk](https://github.com/auth0/auth0.js)), you can request it with:

```
var webAuth = new auth0.WebAuth({
  domain: {YOUR_AUTH0_DOMAIN}, 
  clientID: {YOUR_CLIENT_ID},
  redirectUri: {REDIRECT_URL}, 
  scope: 'user_metadata',
  responseType: 'token id_token'
});
webAuth.authorize();

```

You’ll get an opaque access token and a JWT id token which will contain the user\_metadata.

If you want to give OIDC a try, you could fetch this same information with a rule to [add custom claims](https://auth0.com/docs/scopes/current#example-add-custom-claims) to the token, such as:

```
function (user, context, callback) {
  const namespace = 'https://myapp.example.com/';
  context.idToken[namespace + 'favorite_color'] = user.favorite_color;
  context.idToken[namespace + 'preferred_contact'] = user.user_metadata.preferred_contact;
  callback(null, user, context);
}

```

---

<div class="post-metadata">

**Author:** ![seqq86](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@seqq86](https://community.auth0.com/u/seqq86)\
**Post date:** [February 15, 2018, 3:07pm UTC](https://community.auth0.com/t/cannot-return-required-scope/9485/3 "2018-02-15T15:07:44Z")

</div>

I will try to use OIDC, but first would like try without it.

**Auth0 client settings:**  
![alt text][1]

**Auth0 connection settings:**  
![alt text][2]

**Response:**  
![alt text][3]

I uploaded not full response, from the Auth0, because it had my private info. But it can be seen that it does not have user\_metadata and also in does not exists in scope list. Can it be a bug?

---

<div class="post-metadata">

**Author:** ![seqq86](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@seqq86](https://community.auth0.com/u/seqq86)\
**Post date:** [February 15, 2018, 3:14pm UTC](https://community.auth0.com/t/cannot-return-required-scope/9485/4 "2018-02-15T15:14:50Z")

</div>

I already have add scope in the request:

```
    auth0 = new auth0.WebAuth({
        domain: AUTH_CONFIG.domain,
        clientID: AUTH_CONFIG.clientId,
        redirectUri: AUTH_CONFIG.callbackUrl,
        audience: `https://${AUTH_CONFIG.domain}/userinfo`,
        responseType: 'token id_token',
        scope: 'openid email profile user_metadata'
    });

```

And it does not return in response + in the response can be seen list of returned scopes: scope : “openid email profile”. So I think it is a bug.

---

<div class="post-metadata">

**Author:** ![ricardo.batista](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ricardo.batista/32/7711_2.png) [@ricardo.batista](https://community.auth0.com/u/ricardo.batista)\
**Post date:** [February 15, 2018, 3:57pm UTC](https://community.auth0.com/t/cannot-return-required-scope/9485/5 "2018-02-15T15:57:07Z")

</div>

As shown in the [documentation](https://auth0.com/docs/api-auth/tutorials/adoption/oidc-conformant#i-don-t-want-to-make-all-these-changes-at-once-), if you include the audience, the request will still be run through the OIDC conformant pipeline.

> Any authentication requests made with  
> an audience parameter will use the new  
> pipeline, and all other requests will  
> continue to work as usual.

[This pipeline](https://auth0.com/docs/api-auth/tutorials/adoption#terminology) will be used if any of the following are true:

- An authentication request was  
initiated with an audience parameter.
- The client being used is flagged as  
OIDC Conformant (available at  
Dashboard \> Clients \> Settings \> Show  
advanced settings \> OAuth \> OIDC  
Conformant flag).

Can you try with?

```
auth0 = new auth0.WebAuth({
   domain: AUTH_CONFIG.domain,
   clientID: AUTH_CONFIG.clientId,
   redirectUri: AUTH_CONFIG.callbackUrl,
   responseType: 'token id_token',
   scope: 'openid user_metadata'
});

```

---

<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:** [July 25, 2019, 10:07am UTC](https://community.auth0.com/t/cannot-return-required-scope/9485/6 "2019-07-25T10:07:07Z")

</div>


