<@U04UQ68083H> is it possible to include identity ...
# ory-copilot
c
@chilly-king-10285 is it possible to include identity metadata from kratos in hydra custom scope?
b
A message from kapa.ai
Yes, it is possible to include identity metadata from Ory Kratos in Ory Hydra custom scopes. This can be achieved through a custom consent flow in Ory Hydra. Here's how you can do it: 1. First, you need to set up a custom consent endpoint in Ory Hydra. This endpoint will handle the consent request and allow you to customize the data included in the tokens. 2. In your custom consent endpoint, you can access the identity information from Ory Kratos, including the metadata. 3. When accepting the consent request, you can include the metadata in the session data, which will then be included in the ID token or access token. Here's a simplified example of how you might include metadata in the consent flow:
Copy code
javascript // Inside your consent endpoint oauth2.acceptOAuth2ConsentRequest({   consentChallenge: challenge,   acceptOAuth2ConsentRequest: {     grant_scope: grantScope,     session: {       id_token: {         // Include metadata here         metadata: identity.metadata_public       }     }   } })
This approach allows you to include the public metadata from Kratos in the ID token. The specific implementation may vary depending on your setup and requirements. It's important to note that you should be cautious about what data you include in tokens, especially considering privacy and security implications. For more detailed information on customizing the consent flow, you can refer to the [Ory Hydra Custom Login and Consent Flow documentation](https://www.ory.sh/docs/oauth2-oidc/custom-login-consent/flow#consent-endpoint-code-example). Additionally, you might want to review the [Ory Kratos Identity Metadata documentation](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata) to understand what metadata is available and how to use it.