# How to get token with jku claim

**URL:** <https://community.auth0.com/t/how-to-get-token-with-jku-claim/75877>\
**Category:** Get Help\
**Tags:** claims, jwt, auth0\
**Created:** [January 5, 2022, 9:21pm UTC](https://community.auth0.com/t/how-to-get-token-with-jku-claim/75877 "2022-01-05T21:21:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![david.rouchet](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/david.rouchet/32/33194_2.png) [@david.rouchet](https://community.auth0.com/u/david.rouchet)\
**Post date:** [January 5, 2022, 9:21pm UTC](https://community.auth0.com/t/how-to-get-token-with-jku-claim/75877/1 "2022-01-05T21:21:30Z")

</div>

Hi there,

I’m using Auth0 to generate API tokens, but I haven’t find a way to have the jku claim provided in the generated token. The header does contain the kid claim, but no jku claim. I’d expect to have the jku pointing to `https://YOUR_DOMAIN/.well-known/jwks.json`

Does anyone know how to do this, is there a settings that I missed?

Tnx

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 5, 2022, 11:08pm UTC](https://community.auth0.com/t/how-to-get-token-with-jku-claim/75877/3 "2022-01-05T23:08:50Z")

</div>

Hi @david.rouchet,

Welcome to the Auth0 Community!

Unfortunately, the `jku` claim is not part of the [standard claims](https://auth0.com/docs/security/tokens/json-web-tokens/json-web-token-claims) from what I’ve found.

In this case, you have the option and appending the `jku` claim with the `https://YOUR_DOMAIN/.well-known/jwks.json` value using either an Auth0 [Rule](https://auth0.com/docs/configure/apis/scopes/sample-use-cases-scopes-and-claims#add-custom-claims-to-a-token) or [Action](https://auth0.com/docs/actions/triggers/post-login#add-user-roles-to-id-and-access-tokens).

Once you’ve done so, your tokens will include the `jku` claim.

Please let me know how this works for you.

Thank you.

---

<div class="post-metadata">

**Author:** ![david.rouchet](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/david.rouchet/32/33194_2.png) [@david.rouchet](https://community.auth0.com/u/david.rouchet)\
**Post date:** [January 6, 2022, 2:21pm UTC](https://community.auth0.com/t/how-to-get-token-with-jku-claim/75877/4 "2022-01-06T14:21:48Z")

</div>

Hi @rueben.tiow

Thanks for your feedback. I’ve indeed thought of that option, but not very familiar with either Rule or Actions. I actually gave it a try but not succeeded, do you have some guidelines to provide to do so, especially to alter the header section of the token?

Thank you

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 6, 2022, 4:31pm UTC](https://community.auth0.com/t/how-to-get-token-with-jku-claim/75877/5 "2022-01-06T16:31:13Z")

</div>

Hi @david.rouchet,

Sure, let me explain further.

In this case, I recommend using a [Post-Login Action](https://auth0.com/docs/actions/triggers/post-login) to append custom claims to the Token. Head over to your Auth0 _Dashboard \> Actions \> Flows \> Login_ and click on the plus symbol (+) to create a new custom Action. In that script, use the code below.

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://my-app.example.com';
  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/jku`, "https://YOUR_DOMAIN/.well-known/jwks.json");
    api.accessToken.setCustomClaim(`${namespace}/jku`, "https://YOUR_DOMAIN/.well-known/jwks.json");
  }
}

```

Please don’t forget to **Deploy** the Action and [attach the Action to the flow](https://auth0.com/docs/actions/write-your-first-action#attach-the-action-to-a-flow). You will need to drag the Action into your Post-Login Flow, and press **Apply**.

Once that is done, the `jku` claim will be in both the access token and ID token.

> **[Login Flow](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow)**
>
> Learn about the Actions Login Flow and the post-login Action trigger, which is executed after a user logs in and when a Refresh Token is requested.

> **[Write Your First Action](https://auth0.com/docs/customize/actions/write-your-first-action)**
>
> Learn how to write an Action, which includes choosing a flow, creating an Action and configuring it, and binding it to the flow.

Please let me know if there’s anything else I can do to help.

Thanks.

---

<div class="post-metadata">

**Author:** ![david.rouchet](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/david.rouchet/32/33194_2.png) [@david.rouchet](https://community.auth0.com/u/david.rouchet)\
**Post date:** [January 6, 2022, 7:05pm UTC](https://community.auth0.com/t/how-to-get-token-with-jku-claim/75877/6 "2022-01-06T19:05:46Z")

</div>

Hi @rueben.tiow

many thanks for these guide lines. I’m actually using a client credential flow, so I created an action into the Machine-to-Machine flow. According to the logs, the action is being executed (no errors) when calling the ‘/oauth/token’ endpoint to get the token, but the token doesn’t contain any new claim.

The action code is as follow:

```auto
exports.onExecuteCredentialsExchange = async (event, api) => {
  const namespace = 'https://edu-orange.eu.auth0.com';
  const jkuValue = namespace + "/.well-known/jwks.json";
  const jkuName = namespace + "/jku";

  let res = api.accessToken.setCustomClaim( jkuName, jkuValue );
  console.log( `value added to token as jku: ${jkuName}:${jkuValue}`)
  console.log( `ops result: ${JSON.stringify(res)}`)
};

```

any idea?

Thanks

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 6, 2022, 7:12pm UTC](https://community.auth0.com/t/how-to-get-token-with-jku-claim/75877/7 "2022-01-06T19:12:47Z")

</div>

Hi @david.rouchet,

Thank you for your response!

I forgot to mention that you should use any non Auth0 HTTP or HTTPS URL as the namespace identifier. Auth0 domains cannot be used as namespace identifiers, which includes:

- [auth0.com](http://auth0.com)
- [webtask.io](http://webtask.io)
- webtask.run

> **[Create Custom Claims](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims)**
>
> Learn how to create collision-resistant names for custom claims.

I recommend that you modify your namespace to one that qualifies, and you’ll be able to see it in the claims.

Thank you.

---

<div class="post-metadata">

**Author:** ![david.rouchet](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/david.rouchet/32/33194_2.png) [@david.rouchet](https://community.auth0.com/u/david.rouchet)\
**Post date:** [January 7, 2022, 10:38pm UTC](https://community.auth0.com/t/how-to-get-token-with-jku-claim/75877/8 "2022-01-07T22:38:22Z")

</div>

Hi @rueben.tiow

so, thanks for the last tip, it works now. However, it seems that claims without a url schema in the name (ex: `myclaim`) are not supported, is this correct?

Also, is there a way to add claims in the header of the token?

Thank you

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 7, 2022, 11:16pm UTC](https://community.auth0.com/t/how-to-get-token-with-jku-claim/75877/9 "2022-01-07T23:16:15Z")

</div>

Hi @david.rouchet,

Thank you for your response, and I’m happy that it works now!

> [@david.rouchet](#):
>
> (ex: `myclaim` ) are not supported, is this correct?

That’s correct. Custom claims must be appended with a somewhat arbitrary namespace.

> [@david.rouchet](#):
>
> Also, is there a way to add claims in the header of the token?

Unfortunately, no, this is not possible.

Please let me know if you have any further questions.

Thanks!

---

<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:** [January 22, 2022, 11:16pm UTC](https://community.auth0.com/t/how-to-get-token-with-jku-claim/75877/10 "2022-01-22T23:16:28Z")

</div>

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