careful-honey-27437
04/08/2025, 9:35 PMbrief-egg-61061
04/08/2025, 9:35 PMbrief-egg-61061
04/08/2025, 9:35 PMAuthorization: Bearer <your-session-token>
As shown in the documentation, you can verify a session with: curl -H "Authorization: Bearer {your-session-token}" \ "https://$<http://PROJECT_SLUG.projects.oryapis.com/sessions/whoami|PROJECT_SLUG.projects.oryapis.com/sessions/whoami>"
## Using Session Cookies Alternatively, if you want to test browser-based flows, you'll need to: 1. Enable cookie storage in Insomnia 2. Make sure to set the withCredentials: true
option (or equivalent in Insomnia) 3. Include the cookie in requests: curl -H "Cookie: ory_session_...=..." \ "https://$<http://PROJECT_SLUG.projects.oryapis.com/sessions/whoami|PROJECT_SLUG.projects.oryapis.com/sessions/whoami>"
## Session Verification When testing your APIs, you can verify sessions by calling the /sessions/whoami
endpoint, which will return session information if valid or a 401 error if not. For more detailed information about Ory Sessions and authentication flows, you may want to check the [Session Management documentation](https://www.ory.sh/docs/kratos/session-management/overview) and [Check Session Status documentation](https://www.ory.sh/docs/identities/sign-in/check-session-token-cookie-api).careful-honey-27437
04/08/2025, 9:36 PMbrief-egg-61061
04/08/2025, 9:36 PMbrief-egg-61061
04/08/2025, 9:37 PMbash actionUrl=$( curl -s -X GET -H "Accept: application/json" \ "<https://playground.projects.oryapis.com/self-service/login/api>" \ | jq -r '.ui.action' )
### Step 2: Complete the Login Flow Then, submit your credentials to the action URL: bash curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" \ -d '{"identifier": "<mailto:user@example.com|user@example.com>", "password": "your-password", "method": "password"}' \ "$actionUrl" | jq
The response will include a session token and session information: json { "session_token": "oFZzgLpsacUpUy2cvQPtrGa2046WcXCR", "session": { "id": "8f660ce3-69ec-4aeb-9fda-f9230dc3243f", "active": true, "expires_at": "2020-08-25T13:42:15.7411522Z", "authenticated_at": "2020-08-24T13:42:15.7411522Z", "issued_at": "2020-08-24T13:42:15.7412042Z", "identity": { "id": "bf32596a-f853-47c4-91e6-a3f41cf4949d", "schema_id": "default", "schema_url": "<https://playground.projects.oryapis.com/schemas/default>", "traits": { "email": "<mailto:user@example.com|user@example.com>", "name": { "last": "User", "first": "API" } } // Additional identity information... } } }
### Step 3: Using the Session Token You can now use the session token for authenticated requests: bash curl -s -H "Authorization: Bearer svX8bE9HTiVpMr7r55TtKtcOkLRhAq1a" \ <https://playground.projects.oryapis.com/sessions/whoami> | jq
This will return the session information if the token is valid. [Ory Kratos Self-Service Login Flow for API Clients](https://www.ory.sh/docs/kratos/self-service/flows/user-login#api-clients) Remember that this approach is specifically for API clients and native applications, not for browser-based applications which should use the browser flow with cookies instead.careful-honey-27437
04/08/2025, 9:54 PMcareful-honey-27437
04/08/2025, 9:58 PMbrief-egg-61061
04/08/2025, 9:58 PMbrief-egg-61061
04/08/2025, 9:58 PMbash # Step 1: Initialize the login flow flowId=$( curl -s -X GET -H "Accept: application/json" \ "<https://your-project.projects.oryapis.com/self-service/login/api>" \ | jq -r '.id' ) # Step 2: Submit the provider choice curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" \ -d '{"provider": "google", "method": "oidc"}' \ "<https://your-project.projects.oryapis.com/self-service/login?flow=$flowId>"
This will return a redirect URL that the user needs to visit to authenticate with Google. After successful authentication, Google redirects back to your application with an authorization code. [OAuth2 and OpenID Connect](https://www.ory.sh/docs/guides/oauth2-oidc) ### 2. For Native Mobile Applications For native apps, you can use the Google SDK approach which provides a better user experience: 1. Configure a Google social sign-in provider in Ory using the same client_id
as in your app 2. Obtain an id_token
directly from Google using their SDK 3. Submit this token to Ory: bash curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" \ -d '{ "method": "oidc", "provider": "google", "id_token": "YOUR_GOOGLE_ID_TOKEN" }' \ "<https://your-project.projects.oryapis.com/self-service/login?flow=$flowId>"
This approach doesn't require browser redirection and provides a more integrated experience. [Using the Google SDK on native apps](https://www.ory.sh/docs/kratos/social-signin/google#using-the-google-sdk-on-native-apps) ### Example Flutter Implementation Here's a Flutter code example for implementing Google Sign-In with Ory: dart import 'package:flutter/material.dart'; import 'package:google_sign_in/google_sign_in.dart'; import 'package:one_of/one_of.dart'; import 'package:ory_client/ory_client.dart'; class SignInWithGoogleButton extends StatelessWidget { final String flowId; final OryClient ory; final GoogleSignIn _googleSignIn = GoogleSignIn( scopes: [ 'email', // Add additional scopes, if you require that data in your Jsonnet mapping ], ); SignInWithGoogleButton({super.key, required this.flowId, required this.ory}); void handleGoogleSignIn(GoogleSignInAccount? value) { value?.authentication.then((value) { var idToken = value.idToken; if (idToken == null) { // If we end up here, but there is no ID token, something went wrong print("No idToken found"); return; } // Create the payload for the updateRegistrationFlow endpoint with the idToken from Google var body = UpdateRegistrationFlowWithOidcMethod( (b) => b ..idToken = idToken ..method = 'oidc' ..provider = 'google', ); // Submit the updateRegistrationFlow endpoint with the payload ory.getFrontendApi().updateRegistrationFlow( flow: flowId, updateRegistrationFlowBody: UpdateRegistrationFlowBody( (b) => b..oneOf = OneOf.fromValue1(value: body)), ); }); } @override Widget build(BuildContext context) { return TextButton( child: const Text("Sign in with Google"), onPressed: () => {_googleSignIn.signIn().then(handleGoogleSignIn)}, ); } }
For login flows, you would use updateLoginFlow
instead of updateRegistrationFlow
with similar parameters. [Using the Google SDK on native apps](https://www.ory.sh/docs/kratos/social-signin/google#using-the-google-sdk-on-native-apps) Remember that you need to configure the Google social sign-in provider in your Ory project first before these flows will work.