<@U04UQ68083H> how to app custom claims in jwt acc...
# ory-copilot
o
@chilly-king-10285 how to app custom claims in jwt access token through cli while requesting for access token
c
A message from kapa.ai
To add custom claims to a JWT access token, you can use the following code during consent acceptance:
Copy code
javascript import { Configuration, OAuth2Api } from "@ory/client"      const ory = new OAuth2Api(    new Configuration({    basePath: `https://${process.env.ORY_PROJECT_SLUG}.<http://projects.oryapis.com|projects.oryapis.com>`,    accessToken: process.env.ORY_API_KEY,    }),   )      export async function acceptConsent(consentChallenge: string) {    const { data } = await ory.getOAuth2ConsentRequest({ consentChallenge })       return await ory    .acceptOAuth2ConsentRequest({    consentChallenge: consentChallenge,    acceptOAuth2ConsentRequest: {    session: {    access_token: {    some_custom_claim: "some_custom_value",    },    id_token: {    id_custom_claim: "some_value",    },    },    },    })    .then(({ data }) => data)   }
This will result in an access token with the custom claim under the
ext
field. If you want the custom claim to be added to the top level (instead of a nested level) in the access token, you need to modify the
/oauth2/allowed_top_level_claims
configuration using the Ory CLI:
Copy code
bash ory patch oauth2-config {project.id} \    --replace "/oauth2/allowed_top_level_claims=[\"some_custom_claim\"]"
Please note that required JWT claims can't be overwritten by custom claims. For more details, you can refer to the [Ory documentation](https://www.ory.sh/docs/oauth2-oidc/jwt-access-token#custom-consent-ui-and-custom-claims-for-jwt-access-token).