orange-manchester-16482
04/16/2024, 2:46 PMchilly-king-10285
04/16/2024, 2:46 PMchilly-king-10285
04/16/2024, 2:46 PMjavascript 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: 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).