<@U04UQ68083H> Can i use Custom consent UI and cus...
# ory-copilot
n
@chilly-king-10285 Can i use Custom consent UI and custom claims for (JWT) access token and still host in Ory Network?
c
A message from kapa.ai
Yes, you can use a custom consent UI and add custom claims to every access token during consent acceptance while hosting in Ory Network. Here is an example of how you can add custom claims to every access token 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)   }
If you want
some_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:
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 information, 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).