enough-vase-33352
08/22/2025, 3:32 AMbrief-egg-61061
08/22/2025, 3:32 AMbrief-egg-61061
08/22/2025, 3:33 AM/sessions/whoami
endpoint with the tokenize_as
parameter. This process is handled entirely within Kratos, not Hydra. You can find detailed steps for this in the [Session to JWT documentation](https://www.ory.sh/docs/identities/session-to-jwt-cors) and the [API reference](https://www.ory.sh/docs/kratos/reference/api#tag/frontend/operation/toSession) [Convert Ory Sessions to JSON Web Tokens](https://www.ory.sh/docs/identities/session-to-jwt-cors) [Kratos API Reference](https://raw.githubusercontent.com/ory/kratos/master/spec/api.json). - Ory Hydra is an OAuth2 and OpenID Connect provider. It issues its own tokens (access, refresh, ID tokens) as part of OAuth2 flows, but it does not natively convert Kratos sessions to JWTs. Hydra can be configured to include custom claims in its tokens via webhooks, but this is not the same as converting a Kratos session to a JWT [Customizing claims with OAuth2 webhooks](https://www.ory.sh/docs/hydra/guides/claims-at-refresh). How to convert a Kratos session to a JWT: 1. Configure JWT templates in Kratos (not Hydra). 2. Call the /sessions/whoami
endpoint with the tokenize_as
query parameter set to your JWT template key. 3. Receive the JWT in the tokenized
field of the response. Example (using REST API): bash curl -X GET \ -H "Cookie: ory_session...=..." \ "https://$<http://PROJECT_SLUG.projects.oryapis.com/sessions/whoami?tokenize_as=jwt_example_template1|PROJECT_SLUG.projects.oryapis.com/sessions/whoami?tokenize_as=jwt_example_template1>"
The response will include a tokenized
field containing the JWT [Convert Ory Sessions to JSON Web Tokens](https://www.ory.sh/docs/identities/session-to-jwt-cors). Summary: You cannot use Hydra to convert a Kratos session to a JWT. This conversion is a feature of Kratos itself. If you need to use JWTs issued from Kratos sessions, use Kratos' "Session to JWT" functionality as described above. If you need Hydra-issued tokens, use OAuth2 flows with Hydra. If you need to bridge the two, you would need to implement custom logic outside of the built-in features described in the documentation.enough-vase-33352
08/22/2025, 3:34 AMbrief-egg-61061
08/22/2025, 3:34 AMbrief-egg-61061
08/22/2025, 3:35 AMopenid
, offline_access
, email
) [Ory Social Sign-in with Ory](https://www.ory.sh/docs/kratos/social-signin/ory). 2. Configure Kratos to use Hydra as an OIDC Provider: - In the Kratos Console, go to Authentication → Social Sign-In. - Add a new OpenID Connect provider. - Enter the following details from your Hydra setup: - Client ID (from the OAuth2 client you created in Hydra) - Client Secret - Issuer URL (the public URL of your Hydra instance) - Copy the Redirect URI generated by Kratos and add it to the allowed redirect URIs for your OAuth2 client in Hydra. - Save the configuration [Connecting a project to the SSO provider](https://www.ory.sh/docs/kratos/social-signin/ory#connecting-a-project-to-the-sso-provider). 3. (Optional) Adjust Scopes and Data Mapping: - You can customize which OAuth scopes Kratos requests from Hydra and how user data is mapped from Hydra to Kratos identities. Summary of the flow: - When a user chooses to sign in with Ory (Hydra), Kratos will redirect them to Hydra for authentication. - After successful authentication, Hydra will redirect the user back to Kratos with the necessary tokens. - Kratos will use the information from Hydra to create or update the user's identity in its own system. For more details and step-by-step instructions, see the official documentation: [Connecting a project to the SSO provider](https://www.ory.sh/docs/kratos/social-signin/ory#connecting-a-project-to-the-sso-provider)enough-vase-33352
08/22/2025, 3:36 AMbrief-egg-61061
08/22/2025, 3:36 AMbrief-egg-61061
08/22/2025, 3:36 AMenough-vase-33352
08/22/2025, 3:39 AMbrief-egg-61061
08/22/2025, 3:39 AMbrief-egg-61061
08/22/2025, 3:39 AMenough-vase-33352
08/22/2025, 3:55 AMbrief-egg-61061
08/22/2025, 3:55 AMbrief-egg-61061
08/22/2025, 3:55 AMbash ory patch oauth2-config --project <project-id> --workspace <workspace-id> \ --replace "/strategies/access_token=\"jwt\""
Or per client using the Ory SDK: js await ory.patchOAuth2Client({ id, jsonPatch: [ { op: "replace", path: "access_token_strategy", value: "jwt" }, ], })
[JWT Access Tokens](https://www.ory.sh/docs/oauth2-oidc/jwt-access-token#jwt-access-tokens) - Once configured, when a user completes the OAuth2 flow (after authenticating with Kratos), Hydra will issue a JWT access token. ### 5. JWT Assertion Grant (Advanced) - If you want to exchange a JWT for an access token (JWT Assertion Grant), Hydra supports the urn:ietf:params:oauth:grant-type:jwt-bearer
grant type. You must POST to Hydra’s /oauth2/token
endpoint with the JWT in the assertion
parameter and the appropriate grant type [Exchanging JWT assertion for access token](https://www.ory.sh/docs/hydra/guides/jwt#exchanging-jwt-assertion-for-access-token). --- Summary: - Users log in with email/password via Kratos. - OAuth2/OIDC clients authenticate via Hydra, which delegates login to Kratos. - Configure Hydra to issue JWT access tokens. - After the OAuth2 flow, clients receive JWT tokens from Hydra. Note: The knowledge sources do not provide a step-by-step guide for wiring Kratos and Hydra together, but this is the standard integration pattern described in the Ory documentation. If you need to perform a JWT assertion grant, you must ensure the JWT is properly issued and trusted by Hydra as described in the JWT profile documentation [JWT profile for OAuth2](https://www.ory.sh/docs/hydra/guides/jwt).enough-vase-33352
08/22/2025, 4:46 AMbrief-egg-61061
08/22/2025, 4:46 AMbrief-egg-61061
08/22/2025, 4:46 AMenough-vase-33352
08/22/2025, 5:06 AMbrief-egg-61061
08/22/2025, 5:06 AMbrief-egg-61061
08/22/2025, 5:06 AMurls.login
, urls.consent
) to point to your Kratos UI or API [Hydra Self-hosted Configuration](https://www.ory.sh/docs/hydra/self-hosted/configure-deploy#perform-oauth-20-flow). Summary: You do not need to configure Hydra clients in Kratos. You only need to configure Hydra to use Kratos for authentication, and manage OAuth2 clients in Hydra itself. Kratos and Hydra communicate during the OAuth2 flow, but Kratos does not need to be aware of the individual OAuth2 clients registered in Hydra.enough-vase-33352
08/22/2025, 5:09 AMbrief-egg-61061
08/22/2025, 5:09 AMbrief-egg-61061
08/22/2025, 5:09 AMenough-vase-33352
08/22/2025, 5:43 AMbrief-egg-61061
08/22/2025, 5:43 AMbrief-egg-61061
08/22/2025, 5:43 AMclient_id
, client_name
, and other metadata. You can use this information to determine which client the user is interacting with during the login or consent process. For example, in the consent endpoint code, you can access the client information like this: js res.render("consent", { card: UserConsentCard({ consent: body, csrfToken: req.csrfToken(), cardImage: body.client?.logo_uri || "/ory-logo.svg", client_name: body.client?.client_name || "unknown client", requested_scope: body.requested_scope, client: body.client, action: (process.env.BASE_URL || "") + "/consent", }), })
Here, body.client
contains the client details, including the client_id
that identifies which Hydra client initiated the login flow [Consent endpoint code example](https://www.ory.sh/docs/oauth2-oidc/custom-login-consent/flow#consent-endpoint-code-example). Summary: You can identify the Hydra client a user used to log in with by inspecting the client_id
and related client information in the login or consent request payloads handled by your custom login/consent provider during the OAuth2 flow.enough-vase-33352
08/22/2025, 5:44 AMbrief-egg-61061
08/22/2025, 5:44 AMbrief-egg-61061
08/22/2025, 5:44 AM--skip-consent
flag (CLI) or use the "Skip consent" toggle in the Ory Console. This tells Hydra/Ory Network to automatically grant consent for this client, so the user will not see a consent screen during the OAuth2 flow. Example using the Ory CLI: bash ory create oauth2-client \ --skip-consent \ # ... other options
Or update an existing client: bash ory update oauth2-client \ --id <client-id> \ --skip-consent
[Skip consent and logout consent](https://www.ory.sh/docs/oauth2-oidc/skip-consent) [ory create oauth2-client options](https://www.ory.sh/docs/cli/ory-create-oauth2-client#options) - In the Ory Console: Go to OAuth2 Clients, edit your client, and enable the Skip consent toggle in the Consent screen section, then save. How it works: When this flag is set, the consent UI is skipped for that client. The consent endpoint will receive a request with skip: true
and should auto-accept the consent without showing a UI [Consent endpoint code example](https://www.ory.sh/docs/oauth2-oidc/custom-login-consent/flow#consent-endpoint-code-example). Note: This approach is recommended only for first-party (trusted) clients. Skipping consent for third-party clients is not recommended and may break OpenID Connect certification [Previous consent](https://www.ory.sh/docs/oauth2-oidc/custom-login-consent/flow#previous-consent). Summary: Set the skip consent
flag for your OAuth2 client to perform first-party consent without user interaction.enough-vase-33352
08/22/2025, 5:47 AMbrief-egg-61061
08/22/2025, 5:47 AMbrief-egg-61061
08/22/2025, 5:47 AM--skip-consent
flag. This ensures that the consent screen is automatically skipped for trusted, first-party clients: bash ory create oauth2-client \ --skip-consent \ # ... other options
Or update an existing client: bash ory update oauth2-client \ --id <client-id> \ --skip-consent
You can also enable this in the Ory Console by toggling Skip consent for the client in the Consent screen section and saving your changes [Skip consent and logout consent](https://www.ory.sh/docs/oauth2-oidc/skip-consent). ### 2. Identify the Hydra Client Used for Login During the OAuth2 flow, when your login or consent endpoint receives a request from Hydra, the request payload includes information about the OAuth2 client, such as client_id
and client_name
. You can access this information in your consent endpoint handler: js // Example from consent endpoint res.render("consent", { client_name: body.client?.client_name || "unknown client", client: body.client, // ... other data })
Here, body.client
contains the client details, including the client_id
that identifies which Hydra client initiated the login flow [Consent endpoint code example](https://www.ory.sh/docs/oauth2-oidc/custom-login-consent/flow#consent-endpoint-code-example). When skip consent is enabled, your consent endpoint will receive a request with skip: true
and should auto-accept the consent, but you still have access to the client information in the request payload. --- Summary: - Enable the skip consent flag for your first-party OAuth2 clients to bypass the consent screen. - Use the client_id
and related fields in the consent/login request payload to identify which Hydra client the user used to log in [Consent endpoint code example](https://www.ory.sh/docs/oauth2-oidc/custom-login-consent/flow#consent-endpoint-code-example).