numerous-stone-43519
10/27/2023, 9:04 AMchilly-king-10285
10/27/2023, 9:04 AMchilly-king-10285
10/27/2023, 9:06 AMstd.extVar('claims')
. 2. Once you have the user's email, you can add it as a custom claim to the access token during consent acceptance. Here's an example of how to do this: 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: { user_email: "user's email", }, id_token: { id_custom_claim: "some_value", }, }, }, }) .then(({ data }) => data) }
This code is based on the example provided in the [Ory documentation](https://www.ory.sh/docs/oauth2-oidc/jwt-access-token). Replace "user's email"
with the actual email you obtained from the API call. 3. If you want the custom claim to be added to the top level in the access token, you need to modify the /oauth2/allowed_top_level_claims
configuration: bash ory patch oauth2-config {project.id} \ --replace "/oauth2/allowed_top_level_claims=[\"user_email\"]"
This command is also based on the example provided in the [Ory documentation](https://www.ory.sh/docs/oauth2-oidc/jwt-access-token). Please note that the actual implementation may vary depending on your specific use case and setup.