<@U04UQ68083H> is it possible to change the email ...
# ory-copilot
c
@chilly-king-10285 is it possible to change the email scope value using the token hook in ory hydra ?
b
A message from kapa.ai
Yes, it is possible to change the email scope value using the token hook in Ory Hydra. The token hook allows you to customize claims in the access token and introspection data. According to the [Ory documentation on customizing claims with OAuth2 webhooks](https://www.ory.sh/docs/hydra/guides/claims-at-refresh), you can modify aspects of the OpenID Connect and access tokens returned from Hydra's OAuth2 token endpoint. This includes adding custom claims to the tokens issued by Ory OAuth2/Ory Hydra. To achieve this, you need to register a webhook endpoint in your OAuth2 configuration. Before the token is issued to the client, Ory will call your HTTPS endpoint with information about the OAuth client requesting the token. Your endpoint's response to the webhook will be used to customize the token that Ory issues to the OAuth client. Here's how you can set it up: 1. Configure the token hook using the Ory CLI:
Copy code
ory patch oauth2-config --project <project-id> --workspace <workspace-id> \ --add '/oauth2/token_hook/url="<https://my-example.app/token-hook>"' \ --add '/oauth2/token_hook/auth/type="api_key"' \ --add '/oauth2/token_hook/auth/config/in="header"' \ --add '/oauth2/token_hook/auth/config/name="X-API-Key"' \ --add '/oauth2/token_hook/auth/config/value="MY API KEY"' \ --format yaml
2. Implement your webhook endpoint to modify the email scope value. Your endpoint will receive a POST request with a JSON payload containing the session and request information. 3. In your webhook response, you can modify the claims, including the email scope value, by returning a JSON object with the desired changes. Remember that the specific implementation details of modifying the email scope value will depend on your use case and how you want to handle the email information in your application. [Customizing claims with OAuth2 webhooks](https://www.ory.sh/docs/hydra/guides/claims-at-refresh) provides more detailed information on how to implement and use the token hook in Ory Hydra.