breezy-zebra-64533
07/29/2024, 11:58 AMchilly-king-10285
07/29/2024, 11:58 AMchilly-king-10285
07/29/2024, 11:58 AMbash ory patch oauth2-config $PROJECT_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. Handle the webhook in your endpoint: Use the request payload to decide how Ory should proceed in the token exchange with the client. To modify the claims of the issued tokens and instruct Hydra to proceed with the token exchange, return 200 with a JSON response body. Here's an example of how to do it: json { "session": { "access_token": { "your:custom:access-token-claim": "any value you like", "your:second:access-token-claim": 124390123 }, "id_token": { "your:custom:id-token-claim": "another value", "your:second:id-token-claim": 2394123 } } } 3. Tokens issued by Ory to the OAuth2 client will contain the data from your webhook response. For more information, you can refer to the [Ory Hydra documentation](https://www.ory.sh/docs/hydra/guides/claims-at-refresh).breezy-zebra-64533
07/29/2024, 11:59 AMchilly-king-10285
07/29/2024, 12:00 PMchilly-king-10285
07/29/2024, 12:01 PM/oauth2/auth?client_id=...&your_custom_param=.... 2. Retrieve the custom data using the challenge code: Both Login and Consent Requests have a request url which contains the original OAuth2 Authorize URL. This URL is typically not needed, but might come in handy if you want to deal with additional request parameters. For more information, you can refer to the [Ory Hydra documentation](https://www.ory.sh/docs/hydra/faq#how-can-i-store-custom-data-).breezy-zebra-64533
07/29/2024, 12:05 PMchilly-king-10285
07/29/2024, 12:05 PMchilly-king-10285
07/29/2024, 12:05 PM/oauth2/auth?client_id=...&your_custom_param=.... This custom data can then be retrieved along with the login request using the challenge code that Hydra creates. It's not directly included in the token exchange request. For more details, please refer to the [Ory Hydra documentation](https://www.ory.sh/docs/hydra/faq#how-can-i-store-custom-data-).breezy-zebra-64533
07/29/2024, 3:54 PMchilly-king-10285
07/29/2024, 3:54 PMchilly-king-10285
07/29/2024, 3:55 PMlogin_challenge is included in the token exchange request. When you initiate an OAuth2 flow (like the Authorization Code or Implicit flow), Hydra creates a login_challenge. This login_challenge is used to fetch information about the login request and is included in the token exchange request. For more information, you can refer to the [Ory Hydra documentation](https://www.ory.sh/docs/hydra/faq#how-can-i-store-custom-data-).breezy-zebra-64533
07/29/2024, 3:58 PMchilly-king-10285
07/29/2024, 3:58 PMchilly-king-10285
07/29/2024, 3:58 PMlogin_challenge is not directly included in the token exchange request. Instead, it's used to fetch the login request from Hydra. Once you have the login request, you can use the challenge property of the oauth2_login_request object to get the login_challenge. Here's an example of how it's structured in the login request: json 'oauth2_login_request': { 'properties': { 'challenge': { 'description': 'ID is the identifier ("login challenge") of the login request. It is used to identify the session.', 'type': 'string' }, ... } } For more information, you can refer to the [Ory Kratos API documentation](https://www.ory.sh/docs/kratos/reference/api).