helpful-fish-56090
06/05/2025, 1:50 PMbrief-egg-61061
06/05/2025, 1:50 PMbrief-egg-61061
06/05/2025, 1:51 PMauthenticated_at
via a webhook, you need to ensure that your webhook receives the session object from Ory. The session object contains fields like authenticated_at
, expires_at
, and more. However, the knowledge sources do not explicitly describe a built-in Ory webhook that directly sends session data (such as authenticated_at
) to your endpoint on every session event. Instead, Ory provides APIs to fetch session information, and you can use these APIs in your webhook handler or backend logic. For example, you can use the /sessions/whoami
endpoint to get the current session, which includes the authenticated_at
field: bash curl 'https://$<http://PROJECT_SLUG.projects.oryapis.com/sessions/whoami|PROJECT_SLUG.projects.oryapis.com/sessions/whoami>' \ -H 'Accept: application/json' \ -H 'Cookie: ory_kratos_session=<session-cookie>'
The response will include: json { "id": "...", "active": true, "authenticated_at": "2023-02-03T15:41:22.963917Z", ... }
[Session Checks Example](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#session-checks) If you want to trigger a webhook when a session is created or updated, you would need to configure Ory Actions or use your own backend to listen for such events and then call the session API to fetch the details. The knowledge sources do not provide a direct example of a webhook receiving session data automatically. Summary: - Ory exposes session info (including authenticated_at
) via its API. - To get this info in a webhook, you typically need to call the session API from your webhook handler. - There is no direct mention in the knowledge sources of Ory sending session data to a webhook automatically. If you need more details on how to set up Ory Actions or webhooks for session events, please let me know!helpful-fish-56090
06/05/2025, 1:57 PMflows:
login:
lifespan: 2h
after:
hooks:
- hook: web_hook
config:
# url: <http://localhost:10805/foo?flow=login> # sets via SELFSERVICE_FLOWS_LOGIN_AFTER_HOOKS_0_CONFIG_URL
method: "POST"
body: file:///app/hook.segment_identify.jsonnet
response:
ignore: true
- hook: web_hook
config:
# url: <http://localhost:10805/foo?flow=login> # sets via SELFSERVICE_FLOWS_LOGIN_AFTER_HOOKS_1_CONFIG_URL
method: "POST"
body: file:///app/hook.segment_identify.jsonnet
response:
ignore: true
password:
hooks:
- hook: web_hook
config:
# url: <http://localhost:10805/foo?flow=login> # sets via SELFSERVICE_FLOWS_LOGIN_AFTER_PASSWORD_HOOKS_0_CONFIG_URL
method: "POST"
body: file:///app/hook.segment_identify.jsonnet
response:
ignore: true
- hook: web_hook
config:
# url: <http://localhost:10805/foo?flow=login> # sets via SELFSERVICE_FLOWS_LOGIN_AFTER_PASSWORD_HOOKS_1_CONFIG_URL
method: "POST"
body: file:///app/hook.segment_identify.jsonnet
response:
ignore: true
- hook: require_verified_address
brief-egg-61061
06/05/2025, 1:58 PMbrief-egg-61061
06/05/2025, 1:58 PMpassword
method: yaml flows: login: lifespan: 2h after: hooks: - hook: web_hook config: method: "POST" body: file:///app/hook.segment_identify.jsonnet response: ignore: true - hook: web_hook config: method: "POST" body: file:///app/hook.segment_identify.jsonnet response: ignore: true password: hooks: - hook: web_hook config: method: "POST" body: file:///app/hook.segment_identify.jsonnet response: ignore: true - hook: web_hook config: method: "POST" body: file:///app/hook.segment_identify.jsonnet response: ignore: true - hook: require_verified_address
- The after.hooks
section applies to all login methods unless overridden. - The after.password.hooks
section applies only to the password login method and overrides the global after.hooks
for password logins. - Each hook is a webhook that will POST to your configured endpoint with the specified body. ### 2. When Are Login Hooks Called? Login hooks are called after the user is successfully authenticated, but before the session is issued. This is explicitly stated in the documentation: > The hook runs when the user is successfully authenticated, before the system issues an Ory Session. [Action triggers](https://www.ory.sh/docs/kratos/hooks/configure-hooks#action-triggers) ### 3. Can You Send the Session via the Hook? No, you cannot send the session via the hook, because the session does not exist yet when the after-login hooks are executed. Since the hooks run before the session is created, the session object (including fields like authenticated_at
) is not available to be sent in the webhook payload. This is a key design point in Ory Identities: > The hook runs when the user is successfully authenticated, before the system issues an Ory Session. [Action triggers](https://www.ory.sh/docs/kratos/hooks/configure-hooks#action-triggers) ### Summary - Login after hooks are called after authentication, but before the session is created. - You cannot send session data (like authenticated_at
) in these hooks because the session does not exist yet at this point in the flow. If you need to act on session data, you would need to trigger your logic after the session is created, which is not possible with the standard after-login hooks as per the current Ory design and documentation.helpful-fish-56090
06/05/2025, 2:05 PMbrief-egg-61061
06/05/2025, 2:05 PMbrief-egg-61061
06/05/2025, 2:05 PMSessionIssued
(when a new session is initiated) and SessionChanged
(when a session is updated). These events can be consumed via the Ory Actions live event stream, which allows you to track when sessions are created or updated [Event names](https://www.ory.sh/docs/actions/live-events#event-names). Summary: - There is no Kratos hook that triggers after session creation or update. - You can detect session creation or update by subscribing to the Ory Network live event stream for SessionIssued
and SessionChanged
events. If you need to perform actions after a session is created or updated, consider using the Ory Actions live event stream rather than relying on Kratos hooks.helpful-fish-56090
06/05/2025, 2:11 PMSessionIssued
and SessionChanged
via eventAttributes?brief-egg-61061
06/05/2025, 2:11 PMbrief-egg-61061
06/05/2025, 2:11 PMSessionIssued
and SessionChanged
via its live event streams, and these events include an eventAttributes
field. However, the exact content and schema of the eventAttributes
field for these session events is not documented and is not considered stable. The documentation explicitly notes: > The exact content in the eventAttributes
field is not documented and not considered stable. That means that no backwards compatibility guarantees are made for them. If you need a detailed schema or stability guarantees about the eventAttributes
field, you are advised to [open a support ticket](https://console.ory.sh/support/) [Live event streams](https://www.ory.sh/docs/actions/live-events). Summary: - The specific data you can get from SessionIssued
and SessionChanged
events via eventAttributes
is not documented in the knowledge sources. - The structure and keys in eventAttributes
may change and should not be relied upon for long-term integrations. If you require more details or a stable schema, you should contact Ory support as recommended in the documentation.