gorgeous-motorcycle-71764
09/02/2025, 7:54 AMchilly-king-10285
09/02/2025, 7:54 AMchilly-king-10285
09/02/2025, 7:54 AMhttp(s)://<domain-of-ory-kratos>:<public-port>/self-service/methods/oidc/callback/google
Replace <domain-of-ory-kratos>
and <public-port>
with your actual Kratos public endpoint and port. - Save the Client ID and Client Secret for later use. ### 2. Configure Ory Kratos for Google OIDC Edit your Kratos configuration (e.g., kratos.yml
) to add Google as an OIDC provider: yaml selfservice: methods: oidc: config: providers: - id: google provider: google client_id: <GOOGLE_CLIENT_ID> client_secret: <GOOGLE_CLIENT_SECRET> issuer_url: <https://accounts.google.com> mapper_url: "base64://{YOUR_BASE64_ENCODED_JSONNET_HERE}" scope: - openid - email - profile enabled: true
- The mapper_url
is a [Jsonnet](https://www.ory.sh/docs/kratos/social-signin/data-mapping) snippet (Base64-encoded) that maps Google claims to your identity schema. See the [data mapping example](https://www.ory.sh/docs/kratos/social-signin/google#data-mapping) for details. Example Jsonnet mapping: jsonnet local claims = { email_verified: false, } + std.extVar('claims'); { identity: { traits: { [if 'email' in claims && claims.email_verified then 'email' else null]: claims.email, first_name: claims.given_name, last_name: claims.family_name, [if 'hd' in claims && claims.email_verified then 'hd' else null]: claims.hd, }, }, }
Encode this with Base64 and use it in `mapper_url`<br> [More on data mapping](https://www.ory.sh/docs/kratos/social-signin/google#data-mapping). ### 3. (Optional) Add the Session Hook To ensure users are logged in immediately after registration, add the session hook: yaml selfservice: flows: registration: after: oidc: hooks: - hook: session
[See details](https://www.ory.sh/docs/self-hosted/kratos/configuration/oidc) ### 4. Update Your Custom Login UI - When rendering the login form, fetch the login flow from Kratos. - For each OIDC provider (e.g., Google), render a button that submits a POST request to the Kratos login flow endpoint with the provider value set to google
. Example HTML: html <form action="http://<kratos-public>/self-service/login?flow=<flow-id>" method="POST"> <input type="submit" name="provider" value="google" /> </form>
[See UI integration details](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration#login) ### 5. Test the Flow - When a user clicks "Sign in with Google," they are redirected to Google for authentication. - After successful authentication, Google redirects back to Kratos, which then creates or logs in the user and issues a session. --- Note: Ory Hydra is not directly involved in the social login flow with Kratos, unless you are using OAuth2 flows for your own APIs. Kratos handles the user authentication and session management, while Hydra is used for OAuth2 authorization for your APIs. For more details, see: - [Self-hosted OIDC configuration](https://www.ory.sh/docs/self-hosted/kratos/configuration/oidc) - [Google social sign-in setup](https://www.ory.sh/docs/kratos/social-signin/google) - [Custom UI integration](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration#login)gorgeous-motorcycle-71764
09/02/2025, 8:22 AMchilly-king-10285
09/02/2025, 8:23 AMchilly-king-10285
09/02/2025, 8:23 AMreturn_to
parameter when initializing the login flow, and the URL is whitelisted in your Kratos config, the user will be redirected to that URL after successful login. - If no return_to
is set, Kratos will use the configured redirect URLs in your kratos.yml
file. The order of precedence is: 1. selfservice.flows.login.after.oidc.default_browser_return_url
(for OIDC logins) 2. selfservice.flows.login.after.default_browser_return_url
3. selfservice.default_browser_return_url
For example: yaml selfservice: default_browser_return_url: <https://always-end-up-here-per-default/> flows: login: after: default_browser_return_url: <https://end-up-here-after-login/> oidc: default_browser_return_url: <https://end-up-here-after-login-with-oidc/>
If you set oidc.default_browser_return_url
, the user will be redirected there after a successful Google sign-in. If not, the next available configured URL is used. If none are set, the default is used. If you use the return_to
parameter, it takes precedence but must be whitelisted in selfservice.allowed_return_urls
[Redirection configuration](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion#redirection) [Redirect flows](https://www.ory.sh/docs/concepts/redirects#redirect-flows). Summary: After successful Google sign-in, the user is redirected to the URL specified by your Ory Kratos configuration or the return_to
parameter, following the precedence described above.gorgeous-motorcycle-71764
09/02/2025, 8:35 AMchilly-king-10285
09/02/2025, 8:35 AMchilly-king-10285
09/02/2025, 8:36 AMreturn_to
parameter when initiating a login flow with Ory Kratos, you include it as a query parameter in the URL you use to start the login flow. For example: https://<kratos-public-endpoint>/self-service/login/browser?return_to=<https://your-app.com/dashboard>
This tells Kratos to redirect the user to <https://your-app.com/dashboard>
after a successful login, provided that this URL is allow-listed in your Kratos configuration. If the URL is not allow-listed, the request will fail for security reasons [Browser redirects and flow completion](https://www.ory.sh/docs/concepts/redirects#redirect-flows) [Redirection](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion#redirection). Example with curl: sh curl -X GET 'https://<kratos-public-endpoint>/self-service/login/browser?return_to=<https://your-app.com/dashboard>'
Note: Make sure to add your desired return URLs to the selfservice.allowed_return_urls
in your Kratos config to prevent open redirect attacks. For more details, see the [Ory documentation on redirects](https://www.ory.sh/docs/concepts/redirects#redirect-flows).gorgeous-motorcycle-71764
09/02/2025, 8:38 AMchilly-king-10285
09/02/2025, 8:38 AMchilly-king-10285
09/02/2025, 8:38 AMreturn_to
parameter when initiating the login flow, and the URL is included in the selfservice.allowed_return_urls
whitelist in your Kratos configuration, Ory Kratos will redirect the user to the specified return_to
URL after a successful Google login (OIDC flow). This is the documented and intended behavior for browser-based flows [Redirection](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion#redirection) [Advanced integration](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration). If the return_to
parameter is not set or the URL is not whitelisted, Kratos will use the default redirect URLs configured in your kratos.yml
file. > It's also possible to redirect someone back to the original URL. ... To achieve that, you append ?return_to=<https://www.myapp.com/blog/write>
when initializing the Login / Registration /Settings flow. ... you need to whitelist the domain in your Ory Identities config when using the ?return_to=
query parameter. > — [Redirection](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion#redirection) So, after a successful Google login, Kratos will redirect to the return_to
value if it is properly set and allowed.gorgeous-motorcycle-71764
09/02/2025, 8:41 AMchilly-king-10285
09/02/2025, 8:41 AMchilly-king-10285
09/02/2025, 8:41 AM/oauth2/auth
API, the flow works as follows: 1. User is redirected to Hydra's /oauth2/auth
endpoint The OAuth2 client (your app) initiates the flow by redirecting the user to Hydra's /oauth2/auth
endpoint with the appropriate parameters (e.g., client_id
, redirect_uri
, scope
, etc.). 2. Hydra checks for an authenticated session If the user is not already authenticated, Hydra redirects the user to the login provider (in this case, your custom login UI backed by Kratos) with a login_challenge
parameter in the URL [Custom login and consent flow](https://www.ory.sh/docs/oauth2-oidc/custom-login-consent/flow#flow-steps). 3. Your login UI (using Kratos) presents login options The login UI fetches the login flow from Kratos and presents options, including "Sign in with Google." - If the user chooses Google, the Kratos OIDC flow is started. 4. User authenticates with Google The user is redirected to Google, authenticates, and is redirected back to Kratos. 5. Kratos completes the login flow After successful authentication, Kratos creates a session for the user. 6. Kratos notifies Hydra of the successful login Your login UI (or backend) must accept the Hydra login request by calling Hydra's /admin/oauth2/auth/requests/login/accept
endpoint, passing the login_challenge
and the authenticated user's subject (ID). Hydra responds with a redirect URL [Hydra API reference](https://raw.githubusercontent.com/ory/hydra/master/spec/api.json). 7. User is redirected back to Hydra The user is redirected to the URL provided by Hydra, which continues the OAuth2 flow (typically to the consent screen). 8. Consent flow (if required) If consent is required, the user is shown a consent screen. After consent, the flow continues and the user is finally redirected to the original redirect_uri
of the OAuth2 client, completing the sign-in process. Key Points: - The return_to
parameter in Kratos is not the final app URL, but should point back to the next step in the OAuth2 flow (usually the consent screen or the /oauth2/auth
endpoint), not directly to the client app [Github issue discussion](https://github.com/ory/network/issues/264). - The flow must ensure that after Google login, the user is returned to Hydra to complete the OAuth2 process, not directly to the application. Summary: The end-to-end flow is: OAuth2 client → Hydra /oauth2/auth
→ Kratos login UI (with Google) → Google → Kratos → Accept Hydra login request → Hydra (consent) → OAuth2 client redirect. If the user is redirected directly to the client app after Google login (bypassing Hydra), the OAuth2 flow will not complete correctly. The correct approach is to return the user to Hydra after authentication so the flow can continue as designed [Custom login and consent flow](https://www.ory.sh/docs/oauth2-oidc/custom-login-consent/flow#flow-steps) [Github issue discussion](https://github.com/ory/network/issues/264).gorgeous-motorcycle-71764
09/02/2025, 8:55 AMchilly-king-10285
09/02/2025, 8:55 AMchilly-king-10285
09/02/2025, 8:55 AMprovider
as google
. - Ory Kratos then redirects the user to Google for authentication. - After the user authenticates with Google, Google redirects the user back to Ory Kratos, which completes the login flow and creates a session. This ensures that the OIDC flow is managed securely and that Kratos can handle session creation, data mapping, and any hooks you have configured. The front-end should only interact with Kratos, not with Google directly [Social sign-in flow](https://www.ory.sh/docs/kratos/self-service/flows/user-login#login-with-google-facebook-github--openid-connect--oauth-20) [Custom UI integration](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration#login) [Self-hosted OIDC configuration](https://www.ory.sh/docs/self-hosted/kratos/configuration/oidc). Summary: The front-end should initiate the login with Kratos, and Kratos will handle the redirection to Google—not the front-end itself.gorgeous-motorcycle-71764
09/02/2025, 8:59 AMchilly-king-10285
09/02/2025, 8:59 AMchilly-king-10285
09/02/2025, 9:00 AMaction
and method
provided in the login flow data. The request should include the provider
field set to google
. The URL to invoke is: https://<kratos-public-endpoint>/self-service/login?flow=<flow-id>
- <kratos-public-endpoint>
is your Kratos public API endpoint. - <flow-id>
is the ID of the current login flow, which you obtain when initializing the login flow. Example HTML form: html <form action="https://<kratos-public-endpoint>/self-service/login?flow=<flow-id>" method="POST"> <input type="submit" name="provider" value="google" /> </form>
This will trigger Kratos to handle the OIDC login with Google and redirect the user accordingly [Custom UI integration](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration#login) [Login flow payloads](https://www.ory.sh/docs/kratos/self-service/flows/user-login#login-with-google-facebook-github--openid-connect--oauth-20).gorgeous-motorcycle-71764
09/02/2025, 9:12 AMchilly-king-10285
09/02/2025, 9:12 AMchilly-king-10285
09/02/2025, 9:12 AMGET /self-service/login/browser
This endpoint initializes a browser-based login flow and returns a flow object containing the flow ID and other relevant information. You can call it directly in the browser or via AJAX (with Accept: application/json
for a JSON response). Example request: sh curl -X GET \ -H "Accept: application/json" \ https://<kratos-public-endpoint>/self-service/login/browser
Example response: json { "id": "ff0c97c4-a7bb-49a5-a8a6-ebf174877fa5", "type": "browser", "expires_at": "2021-07-09T11:25:12.136099226Z", "issued_at": "2021-07-09T10:25:12.136099226Z", "request_url": "<http://playground.projects.oryapis.com/self-service/login/browser>", "ui": { "action": "<https://playground.projects.oryapis.com/self-service/login?flow=ff0c97c4-a7bb-49a5-a8a6-ebf174877fa5>", "method": "POST", "nodes": [ /* ... */ ] }, "created_at": "2021-07-09T10:25:12.137554Z", "updated_at": "2021-07-09T10:25:12.137554Z", "forced": false }
The id
field in the response is the login flow ID you need for subsequent login submissions [Login for client-side (AJAX) browser clients](https://www.ory.sh/docs/kratos/self-service/flows/user-login#login-for-client-side-ajax-browser-clients) [API reference](https://raw.githubusercontent.com/ory/kratos/master/spec/api.json). Note: - For native/mobile apps, use /self-service/login/api
instead. - The ui.action
field provides the URL for submitting the login form, including the flow ID as a query parameter.gorgeous-motorcycle-71764
09/02/2025, 9:14 AMchilly-king-10285
09/02/2025, 9:14 AMchilly-king-10285
09/02/2025, 9:15 AMui.nodes
field. Each node with the group "oidc"
represents a configured social login provider (such as Google, GitHub, etc.). For example, after calling the login flow initialization endpoint (/self-service/login/browser
), the response might include: json "ui": { "action": "<http://127.0.0.1:4455/self-service/login?flow=<flow-id>>", "method": "POST", "nodes": [ { "type": "input", "group": "oidc", "attributes": { "name": "provider", "type": "submit", "value": "github", "disabled": false }, "meta": { "label": { "text": "Sign in with github" } } }, { "type": "input", "group": "oidc", "attributes": { "name": "provider", "type": "submit", "value": "google", "disabled": false }, "meta": { "label": { "text": "Sign in with google" } } } ] }
The front-end should look for nodes where group
is "oidc"
and use the value
and label
fields to display the available social login options to the user. This approach is documented in the Ory Kratos login flow payloads and custom UI integration guides [Login flow payloads](https://www.ory.sh/docs/kratos/self-service/flows/user-login#login-with-google-facebook-github--openid-connect--oauth-20) [Custom UI integration](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration). There is no separate API to list providers; the information is always included in the login (or registration) flow response.gorgeous-motorcycle-71764
09/02/2025, 9:18 AMchilly-king-10285
09/02/2025, 9:18 AMchilly-king-10285
09/02/2025, 9:18 AMlogin_challenge
throughout the social login process is to pass it along as a query parameter in your application's URLs and forms during the entire authentication flow. This ensures that after the social login (e.g., with Google) completes and Kratos returns success, your front-end or backend can use the original login_challenge
to accept the login request with Hydra and continue the OAuth2 flow. This approach is discussed in Ory community discussions and issues, where it is noted that the login_challenge
should be kept in the flow and used to retrieve or accept the OAuth2 login request after authentication is complete. For example, when the login UI is first loaded (after Hydra redirects to your login page with ?login_challenge=...
), you should store this value—commonly by including it as a hidden field in your forms or as a query parameter in your redirect URLs. This way, after the social login completes, you can use the preserved login_challenge
to call Hydra's /admin/oauth2/auth/requests/login/accept
endpoint and finish the flow [Custom login and consent flow](https://www.ory.sh/docs/oauth2-oidc/custom-login-consent/flow#flow-steps) [Github issue discussion](https://github.com/ory/kratos/issues/4024). Key points: - Do not store the login_challenge
in cookies or local storage, as this can introduce security issues and is not recommended by Ory. - Always pass the login_challenge
explicitly through your application's URLs, forms, or state management as the user moves through the login and social login process. This method ensures the login_challenge
is available when you need to notify Hydra of a successful login, as required by the OAuth2 flow.gorgeous-motorcycle-71764
09/02/2025, 9:36 AMchilly-king-10285
09/02/2025, 9:36 AMchilly-king-10285
09/02/2025, 9:36 AMgorgeous-motorcycle-71764
09/02/2025, 9:53 AMchilly-king-10285
09/02/2025, 9:53 AMchilly-king-10285
09/02/2025, 9:54 AMreturn_to
Query Parameter: If the login flow was initiated with a return_to
parameter (and the URL is whitelisted in selfservice.allowed_return_urls
), Kratos will redirect the user to this URL after successful login. 2. OIDC-Specific Redirect URL: If no return_to
is set, Kratos checks for an OIDC-specific redirect URL in the configuration: yaml selfservice: flows: login: after: oidc: default_browser_return_url: <https://end-up-here-after-login-with-oidc/>
This URL is used for successful OIDC (e.g., Google) logins. 3. General Login Redirect URL: If the OIDC-specific URL is not set, Kratos uses the general login redirect: yaml selfservice: flows: login: after: default_browser_return_url: <https://end-up-here-after-login/>
4. Global Default Redirect URL: If neither of the above are set, Kratos falls back to the global default: yaml selfservice: default_browser_return_url: <https://always-end-up-here-per-default/>
This precedence is documented in the Ory Kratos documentation: > Post-login redirection considers the following configuration keys: > - selfservice.flows.login.after.oidc.default_browser_return_url
> - selfservice.flows.login.after.default_browser_return_url
> - selfservice.default_browser_return_url
> If you append ?return_to=...
when initializing the Login flow, and the URL is whitelisted, it takes precedence over the config values > [Redirection](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion#redirection) So, Kratos decides the redirect URL after Google login based on the return_to
parameter (if present and allowed), otherwise it uses the OIDC-specific, general login, or global default redirect URL in that order.gorgeous-motorcycle-71764
09/02/2025, 9:55 AMchilly-king-10285
09/02/2025, 9:55 AMchilly-king-10285
09/02/2025, 9:56 AMreturn_to
parameter or as a redirect URL in the Kratos configuration, but there are important considerations: - Kratos is designed to redirect to browser-accessible URLs (i.e., web pages), not to API endpoints that expect non-browser clients. The redirect is performed as an HTTP 303 (See Other) or similar, which is intended for browsers to follow. If you specify an API endpoint, the browser will be redirected there, and unless your API endpoint is prepared to handle browser requests (including cookies, CSRF, etc.), this may not work as intended [Redirection](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion#redirection). - Security: The return_to
URL must be whitelisted in your Kratos configuration under selfservice.allowed_return_urls
to prevent open redirect attacks. If your backend API endpoint is not whitelisted, Kratos will reject the redirect [Redirection](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion#redirection). - Intended Use: The typical use case is to redirect to a frontend route (e.g., a dashboard or home page), not a backend API. If you need to pass information to your backend after login, consider redirecting to a frontend page that then communicates with your backend API as needed. Summary: Technically, you can set your backend API endpoint as a redirect target if it is whitelisted, but this is not the recommended or typical pattern for Ory Kratos, and may not work as expected for browser-based flows [Redirection](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion#redirection).gorgeous-motorcycle-71764
09/02/2025, 9:59 AMchilly-king-10285
09/02/2025, 9:59 AMchilly-king-10285
09/02/2025, 9:59 AMlogin_challenge
value is preserved throughout the OAuth2/OIDC flow (Hydra + Kratos + social login) and is available to the front-end after redirection, you should explicitly pass the login_challenge
as a query parameter in all relevant URLs and forms during the authentication process. How to preserve and retrieve `login_challenge`: 1. Initial Redirect from Hydra: When Hydra redirects the user to your login UI, it appends the login_challenge
as a query parameter (e.g., /login?login_challenge=...
). Your front-end should extract and store this value (e.g., in the URL, in a hidden form field, or in application state). 2. Pass Along During Social Login: When the user chooses "Sign in with Google," ensure that any redirects or form submissions to Kratos (and subsequently to Google) include the login_challenge
as a query parameter or hidden field. This way, after the social login completes and the user is redirected back to your app, the login_challenge
is still available. 3. After Kratos Login Completion: Once Kratos completes the login (after Google authentication), it will redirect the user to the URL specified by the return_to
parameter or your configured redirect. To ensure the front-end receives the login_challenge
, include it in the return_to
URL when initiating the login flow. For example: /self-service/login/browser?return_to=<https://your-frontend.com/oauth/callback?login_challenge=>...
This way, after all redirections, the front-end receives the login_challenge
as a query parameter and can use it to continue the OAuth2 flow with Hydra. Key points from the knowledge sources: - The recommended way is to pass the login_challenge
explicitly through URLs and forms, not via cookies or local storage, to avoid security issues and ensure it is always available when needed [Github issue discussion](https://github.com/ory/kratos/issues/4024). - This approach is necessary so that, after social login, your front-end can use the preserved login_challenge
to call Hydra's /admin/oauth2/auth/requests/login/accept
endpoint and complete the OAuth2 flow [Custom login and consent flow](https://www.ory.sh/docs/oauth2-oidc/custom-login-consent/flow#flow-steps). Summary: Always propagate the login_challenge
as a query parameter in your application's URLs and forms throughout the flow. When you set the return_to
parameter for Kratos, include the login_challenge
in its value so that, after all redirections, your front-end receives it and can continue the OAuth2 process with Hydra.gorgeous-motorcycle-71764
09/02/2025, 12:14 PMchilly-king-10285
09/02/2025, 12:14 PMchilly-king-10285
09/02/2025, 12:15 PM/oauth2/auth
endpoint The OAuth2 client (your app) starts the flow by redirecting the user to Hydra’s /oauth2/auth
endpoint. 2. Hydra checks for authentication and redirects to your login UI If the user is not authenticated, Hydra redirects to your login UI with a login_challenge
parameter. 3. Your login UI starts a Kratos login flow The front-end calls Kratos’ /self-service/login/browser?login_challenge=...
endpoint to initialize the login flow, passing along the login_challenge
as a query parameter [Custom login and consent flow](https://www.ory.sh/docs/oauth2-oidc/custom-login-consent/flow#flow-steps). 4. User enters phone number The UI presents a form for the user to enter their phone number. 5. Kratos sends an OTP via SMS Kratos sends a one-time code to the user’s phone number, using the passwordless code method. The user receives the code via SMS [Enable SMS one-time-code (OTP)](https://www.ory.sh/docs/kratos/passwordless/one-time-code#enable-sms-one-time-code-otp). 6. User enters the OTP The user enters the received code in the UI. The front-end submits this code to Kratos to complete the login flow. 7. Kratos authenticates the user If the code is valid, Kratos authenticates the user and creates a session. If this is the first login with that phone number, Kratos creates a new identity. 8. Front-end uses the preserved login_challenge
to accept the login with Hydra After successful login, the front-end uses the original login_challenge
(which should be preserved throughout the flow as a query parameter) to call Hydra’s /admin/oauth2/auth/requests/login/accept
endpoint, passing the authenticated user’s ID [Custom login and consent flow](https://www.ory.sh/docs/oauth2-oidc/custom-login-consent/flow#flow-steps). 9. Hydra redirects to consent or the client app Hydra continues the OAuth2 flow, possibly showing a consent screen, and finally redirects the user to the OAuth2 client’s redirect_uri
. Important notes: - The phone number must be marked as a code login identifier in your identity schema [Passwordless one-time code login identifier](https://www.ory.sh/docs/kratos/manage-identities/customize-identity-schema#passwordless-one-time-code-login-identifier). - The SMS channel must be configured in Kratos [Enable SMS one-time-code (OTP)](https://www.ory.sh/docs/kratos/passwordless/one-time-code#enable-sms-one-time-code-otp). - The login_challenge
must be preserved and passed through all redirects and form submissions, just as with social login [Github issue discussion](https://github.com/ory/kratos/issues/4024). Summary: The flow is: OAuth2 client → Hydra /oauth2/auth
→ Kratos login UI (phone/OTP) → Kratos (sends/validates OTP) → Accept Hydra login request with login_challenge
→ Hydra (consent) → OAuth2 client redirect. This is nearly identical to the social login flow, but uses the passwordless code method for authentication.gorgeous-motorcycle-71764
09/04/2025, 1:29 PMchilly-king-10285
09/04/2025, 1:29 PMchilly-king-10285
09/04/2025, 1:29 PMgorgeous-motorcycle-71764
09/04/2025, 1:41 PMchilly-king-10285
09/04/2025, 1:41 PMchilly-king-10285
09/04/2025, 1:41 PMsession
hook in the phone number/OTP (code
method) flows if you want users to be automatically logged in (i.e., receive a session) immediately after successful OTP verification and registration. By default, Kratos does not issue a session after registration to prevent account enumeration attacks, so enabling the session
hook is necessary for this behavior. You can configure this in your Kratos config like this: yaml selfservice: flows: registration: after: code: hooks: - hook: session
This ensures that after a user registers using the phone number/OTP method, they are automatically signed in and receive a session cookie, just like with other methods such as password or OIDC. This is also the recommended approach for a seamless user experience [Successful registration](https://www.ory.sh/docs/kratos/self-service/flows/user-registration#successful-registration) [Github issue: Configure session after Registration via code in Console](https://github.com/ory/network/issues/340). If you do not enable the session
hook, users will need to log in again after registration to receive a session.