rough-airplane-18783
04/22/2025, 9:20 AMbrief-egg-61061
04/22/2025, 9:20 AMbrief-egg-61061
04/22/2025, 9:20 AMrough-airplane-18783
04/25/2025, 12:38 PMbrief-egg-61061
04/25/2025, 12:38 PMbrief-egg-61061
04/25/2025, 12:39 PMrough-airplane-18783
07/16/2025, 7:38 AMbrief-egg-61061
07/16/2025, 7:38 AMbrief-egg-61061
07/16/2025, 7:39 AMGET /self-service/login/api
This endpoint is specifically designed for native apps (such as mobile devices, smart TVs, etc.) and should not be used in browser-based applications. It initializes a login flow and returns all the necessary data for rendering the login UI in your native app. On successful login, Ory issues a session token that can be used to authenticate subsequent requests from the app. Example cURL request: bash curl -X GET \ -H "Accept: application/json" \ https://$<http://PROJECT_SLUG.projects.oryapis.com/self-service/login/api|PROJECT_SLUG.projects.oryapis.com/self-service/login/api>
Replace $PROJECT_SLUG
with your actual Ory project slug or domain. Important notes: - Do not use this endpoint in browser or SPA applications, as it does not provide CSRF protection and is intended only for native environments. - On successful login, you will receive a session token (not a cookie) to use for authenticating further API requests from your app. For more details, see the official documentation: [Create Login Flow for Native Apps](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#create-login-flow) and [API Reference](https://raw.githubusercontent.com/ory/kratos/master/spec/api.json).rough-airplane-18783
07/16/2025, 7:39 AMrough-airplane-18783
07/16/2025, 7:40 AMbrief-egg-61061
07/16/2025, 7:41 AMbrief-egg-61061
07/16/2025, 7:41 AMGET /self-service/login/api
This endpoint initializes a login flow for API clients such as mobile devices. After initializing the flow, you will receive a JSON response containing the flow ID and UI nodes, which you use to render the login form in your app. To submit the login credentials, you send a POST request to the action URL provided in the flow response. Example flow: 1. Initialize the login flow: bash curl -X GET \ -H "Accept: application/json" \ https://<your-ory-domain>/self-service/login/api
This returns a JSON object with the flow details, including the ui.action
URL and form fields to render. 2. Submit the login form: bash curl -X POST \ -H "Content-Type: application/json" \ -d '{"method":"password","identifier":"<mailto:email@example.com|email@example.com>","password":"yourpassword"}' \ "https://<your-ory-domain>/self-service/login?flow=<flow-id>"
Replace <your-ory-domain>
and <flow-id>
with your actual values. Note: - This is for self-service flows, not the Ory Console. - Do not use this endpoint in browser-based apps; it is intended for native/mobile clients only. For more details, see the official documentation on [API flows for native apps](https://www.ory.sh/docs/kratos/self-service#api-flows-native-mobile--desktop-apps-command-line-interfaces-smart-tvs-and-more) and [custom UI integration](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#create-login-flow).rough-airplane-18783
07/17/2025, 10:59 AMbrief-egg-61061
07/17/2025, 10:59 AMbrief-egg-61061
07/17/2025, 10:59 AMyaml session: cookie: domain: $<http://PROJECT_SLUG.projects.oryapis.com|PROJECT_SLUG.projects.oryapis.com> name: ory_session_{name} path: / persistent: false same_site: Lax lifespan: 720h # Set to 30 days, for example
After updating the configuration, apply it to your project using the Ory CLI: bash ory update identity-config --project <project-id> --workspace <workspace-id> --file identity-config.yaml
The lifespan
value determines how long the session token (for native apps) or session cookie (for browsers) remains valid before the user must re-authenticate. You can use hours (h
), minutes (m
), and seconds (s
) to define the interval (e.g., 72h
, 10m
, 1h13m3s
). Note: This setting affects all sessions, including those for native apps. There is no separate session lifespan setting specifically for native app tokens; the same configuration applies to both session types[Session lifespan](https://www.ory.sh/docs/kratos/session-management/session-lifespan). If you want to allow sessions to be refreshed (extended) before they expire, you can also adjust the earliest_possible_extend
setting in your configuration[Refresh threshold](https://www.ory.sh/docs/kratos/session-management/refresh-extend-sessions#refresh-threshold). If you need more granular control (such as privileged session duration), see the [privileged sessions documentation](https://www.ory.sh/docs/kratos/session-management/session-lifespan#privileged-sessions).rough-airplane-18783
07/17/2025, 12:42 PMrough-airplane-18783
07/17/2025, 12:42 PMbrief-egg-61061
07/17/2025, 12:42 PMbrief-egg-61061
07/17/2025, 12:42 PMrefresh=true
query parameter. This will prompt the user to re-authenticate, and upon successful login, the session's authenticated_at
and expires_at
will be updated. Endpoint: GET /self-service/login/api?refresh=true
This is the recommended way for native/mobile apps to refresh a session, as it ensures the user is still present and authorized. [See: Refreshing a session](https://www.ory.sh/docs/kratos/self-service/flows/user-login#refreshing-a-session) --- ### 2. Administrator-Initiated Session Extension If you have administrative privileges, you can programmatically extend a user's session using the [Extend Session API](https://www.ory.sh/docs/reference/api#tag/identity/operation/extendSession). Go SDK Example: go session, _, err = ory.IdentityApi.ExtendSession(ContextWithToken(ctx), sessionId). Execute()
You need the session ID, which you can obtain by calling the /sessions/whoami
endpoint or using the toSession
SDK method. [See: Refreshing sessions as administrator](https://www.ory.sh/docs/kratos/session-management/refresh-extend-sessions) --- Note: - Ory does not use "refresh tokens" in the OAuth2 sense for session tokens. Instead, session refresh is handled by re-authentication or admin extension. - For OAuth2 access/refresh tokens, see the [OAuth2 refresh token grant documentation](https://www.ory.sh/docs/oauth2-oidc/refresh-token-grant). If you need to allow users to refresh their session before it expires, ensure your configuration allows it by setting the earliest_possible_extend
property appropriately[Refresh threshold](https://www.ory.sh/docs/kratos/session-management/refresh-extend-sessions#refresh-threshold).