# Unable to add namespaced claims to ID Token while using /delegation with a refresh token flow

**URL:** <https://community.auth0.com/t/unable-to-add-namespaced-claims-to-id-token-while-using-delegation-with-a-refresh-token-flow/6253>\
**Category:** Get Help\
**Tags:** custom-claims, delegation\
**Created:** [April 18, 2017, 2:21pm UTC](https://community.auth0.com/t/unable-to-add-namespaced-claims-to-id-token-while-using-delegation-with-a-refresh-token-flow/6253 "2017-04-18T14:21:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacob.wang](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@jacob.wang](https://community.auth0.com/u/jacob.wang)\
**Post date:** [April 18, 2017, 2:21pm UTC](https://community.auth0.com/t/unable-to-add-namespaced-claims-to-id-token-while-using-delegation-with-a-refresh-token-flow/6253/1 "2017-04-18T14:21:03Z")

</div>

It seems I’m not able to add additional custom claims to the ID Token for `/delegation` endpoint with a refresh token.

I have a rule which adds custom claims to both the access token and ID token. From the webtask log I can see that the rule is being run when I send the following request:

```
POST https://mycompany.au.auth0.com/delegation

{
  "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
  "client_id": "[the client id]",
  "refresh_token": "[refresh token]",
  "scope": "openid",
  "api_type": "app"
}

```

and the result I got

```
{
"token_type": "Bearer",
"expires_in": 36000,
"id_token": "[some id token]"
}

```

However when I decode the ID token, none of my custom claims are present, even though I’ve put them in the `context.idToken` object. This is according to `https://auth0.com/docs/rules/context` (actually there’s a discrepancy - it says to use `id_token` which I think is wrong. Regardless `idToken` nor `id_token` worked)

For example in my rule I’m setting:

```
// context.idToken already initialized to empty object {} if it doesn't exist
context.idToken"https://api.mycompany.com/username"] = user.username;

```

Is this intentional or did I miss something? The custom claims seems to be correctly populated in id token when using `grant_type=code`.

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [April 18, 2017, 9:52pm UTC](https://community.auth0.com/t/unable-to-add-namespaced-claims-to-id-token-while-using-delegation-with-a-refresh-token-flow/6253/2 "2017-04-18T21:52:50Z")

</div>

The use of custom namespaced claims was introduced as part of the [OIDC compliance mode](https://auth0.com/docs/api-auth/tutorials/adoption) (which is also in effect if you use any [API Authorization](https://auth0.com/docs/api-auth) related functionality) so this means that **some endpoints** that predate the final OIDC specification follow different rules and **don’t have support for namespaced claims**.

You mention that you have a rule that adds custom claims to access tokens and ID tokens. Given access tokens are opaque values except when issued as part of an API Authorization request for your own API this makes me assume you’re relying on the API Authorization feature set so you should not be using the `/delegation` endpoint for refresh token purposes (the delegation endpoint can currently still be used to obtain third-party API tokens).

The refresh token obtained as part of the authorization code grant (when in OIDC mode or as part of API authorization for an API that allows offline access) can be used at `/oauth/token` endpoint to execute a [refresh token grant](https://auth0.com/docs/tokens/preview/refresh-token) that follows the OIDC rules and as such should return your namespaced claims in the respective tokens.

If you’re starting your implementation and want to make use of OIDC compliance you can force your client application into OIDC mode through the client application advanced OAuth settings, more specifically, the _OIDC Conformant_ toggle. Enabling this has breaking changes like disabling `/oauth/ro` and other legacy endpoints so if this is an existing application you may want to only do this after testing its effects in a development/staging environment.

* * *

For additional reference information check:

- [OIDC-conformant authentication adoption guide](https://auth0.com/docs/api-auth/tutorials/adoption)
- [Delegation and the OIDC-conformant pipeline](https://auth0.com/docs/api-auth/tutorials/adoption/delegation)
- [Differences between /oauth/ro and OIDC /oauth/token](https://auth0.com/docs/api-auth/tutorials/adoption/password)

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [April 18, 2017, 9:59pm UTC](https://community.auth0.com/t/unable-to-add-namespaced-claims-to-id-token-while-using-delegation-with-a-refresh-token-flow/6253/3 "2017-04-18T21:59:01Z")

</div>

In relation to the docs page, you’re correct; there’s a typo on the page, as the properties within the context object are named `idToken` and `accessToken`. This should be fixed soon.

---

<div class="post-metadata">

**Author:** ![jacob.wang](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@jacob.wang](https://community.auth0.com/u/jacob.wang)\
**Post date:** [April 19, 2017, 2:24pm UTC](https://community.auth0.com/t/unable-to-add-namespaced-claims-to-id-token-while-using-delegation-with-a-refresh-token-flow/6253/4 "2017-04-19T14:24:33Z")

</div>

I see. Thanks for the info!

Some suggestion on documentation:

- update the docs on old refresh token with this info
- update the API docs with info on how to use the refresh token (there’s nothing there atm)
- Fix [Context Object Properties in Rules](https://auth0.com/docs/rules/context). To add custom claims it should be idToken not id\_token (similarly, accessToken not access\_token)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:53am UTC](https://community.auth0.com/t/unable-to-add-namespaced-claims-to-id-token-while-using-delegation-with-a-refresh-token-flow/6253/5 "2018-03-02T05:53:19Z")

</div>


