wooden-manchester-52124
04/25/2025, 5:38 PMbrief-egg-61061
04/25/2025, 5:39 PMbrief-egg-61061
04/25/2025, 5:39 PMory tunnel --dev --project $PROJECT_SLUG <http://localhost:3000>
This command opens port 4000 on your local machine and mirrors your Ory project APIs there. The --dev
flag disables some security checks to make local development easier. [Local Development](https://www.ory.sh/docs/getting-started/local-development#local-development) ## Getting a Session Cookie via cURL After setting up the Ory Tunnel, you can obtain a session cookie by completing the login flow. Here's how to check a session using cURL: curl '<http://localhost:4000/sessions/whoami>' \ -H 'Accept: application/json' \ -H 'Cookie: ory_kratos_session=YOUR_SESSION_COOKIE'
To initially get the session cookie, you need to: 1. Complete the login flow through the browser 2. Copy the ory_kratos_session
cookie from your browser's developer tools 3. Use this cookie in your cURL or Postman requests [Using Ory Session Cookie](https://www.ory.sh/docs/kratos/session-management/overview#using-ory-session-cookie) ## Important Notes for Local Testing - Use either localhost
or 127.0.0.1
consistently, not both, as cookies set on one won't be sent to the other - Make sure all your requests go to <http://localhost:4000>
(or whatever port your Ory Tunnel is using) - Session cookies are automatically set by the browser after successful login - For Postman, you'll need to enable "Send cookies" in your request settings and manually add the cookie after obtaining it from a browser session Remember that Ory's security model requires the API and your application to be on the same domain for cookies to work properly, which is why the Ory Tunnel is necessary for local development.wooden-manchester-52124
04/25/2025, 5:41 PMbrief-egg-61061
04/25/2025, 5:41 PMbrief-egg-61061
04/25/2025, 5:41 PMbash # 1. Initialize the login flow 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> | jq
This returns a flow object with an ID and action URL: bash # 2. Complete the login flow with password method actionUrl=$(curl -s -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>" \ | jq -r '.ui.action') curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" \ -d '{"identifier": "<mailto:user@example.com|user@example.com>", "password": "yourpassword", "method": "password"}' \ "$actionUrl" | jq
Upon successful login, you'll receive a JSON response containing a session token (not a cookie): json { "session_token": "oFZzgLpsacUpUy2cvQPtrGa2046WcXCR", "session": { "id": "8f660ce3-69ec-4aeb-9fda-f9230dc3243f", "active": true, /* additional session data */ } }
You can then use this session token for authentication in subsequent requests: bash curl -s -H "Authorization: Bearer YOUR_SESSION_TOKEN" \ https://$<http://PROJECT_SLUG.projects.oryapis.com/sessions/whoami|PROJECT_SLUG.projects.oryapis.com/sessions/whoami> | jq
[Self-service flows for API clients](https://www.ory.sh/docs/kratos/self-service/flows/user-login#api-clients) ## Important Notes 1. API flows return session tokens instead of cookies 2. Never use API flows for browser-based applications as this opens security vulnerabilities 3. The flow doesn't involve redirects, making it suitable for automation 4. You must handle the token storage and management in your script This approach is ideal for CLI tools, native mobile apps, IoT devices, or any non-browser client that needs to authenticate with Ory. Would you like more details on any specific part of this process?wooden-manchester-52124
04/25/2025, 5:42 PMbrief-egg-61061
04/25/2025, 5:43 PMbrief-egg-61061
04/25/2025, 5:43 PMbash curl -X GET \ -H "Authorization: Bearer YOUR_SESSION_TOKEN" \ "https://$<http://PROJECT_SLUG.projects.oryapis.com/sessions/whoami?tokenize_as=your_jwt_template|PROJECT_SLUG.projects.oryapis.com/sessions/whoami?tokenize_as=your_jwt_template>"
This returns the session with an additional tokenized
field containing a JWT that can be used for authentication. [Convert Ory Sessions to JSON Web Tokens](https://www.ory.sh/docs/identities/session-to-jwt-cors) 3. Server-side proxy: Have your server obtain the session token, then use it to make authenticated requests to Ory on behalf of your client. Remember that the separation between cookies and tokens is a security feature, not a limitation. Each is optimized for different client types and use cases. Does one of these alternative approaches work for your testing scenario?wooden-manchester-52124
04/30/2025, 5:31 PMbrief-egg-61061
04/30/2025, 5:31 PMbrief-egg-61061
04/30/2025, 5:32 PMwooden-manchester-52124
05/01/2025, 8:03 PMbrief-egg-61061
05/01/2025, 8:03 PMbrief-egg-61061
05/01/2025, 8:03 PM.ts
extension, as they are defined as a subset of TypeScript. This can be seen in several examples from the documentation: 1. In the CLI documentation for updating OPL files, the example shows a file path with a .ts
extension: $ ory update opl --file /path/to/namespace_config.ts
[ory update opl](https://www.ory.sh/docs/cli/ory-update-opl#ory-update-opl) 2. When configuring permissions via GitOps, the documentation shows: ory update opl --file permissions.ts
[Manage Ory Network configuration in git](https://www.ory.sh/docs/guides/gitops) 3. In the Ory Console example, the file is named `namespaces.keto.ts`: namespaces.keto.ts
[Get started with Ory Permissions](https://www.ory.sh/docs/guides/permissions/overview#example) The .ts
extension is appropriate since the Ory Permission Language is specifically designed as a subset of TypeScript, allowing you to leverage TypeScript's type checking and editor support while writing your permission rules.