full-notebook-65880
07/11/2024, 6:14 PMchilly-king-10285
07/11/2024, 6:14 PMchilly-king-10285
07/11/2024, 6:14 PMjson { "created_at": "2006-01-02T15:04:05+07:00" }
This format is used across various Ory APIs such as the frontend, oAuth2, project, and workspace APIs. Sources: - [Ory's REST design](https://www.ory.sh/docs/ecosystem/api-design) - [Ory API Reference](https://www.ory.sh/docs/reference/api)full-notebook-65880
07/12/2024, 8:05 PMchilly-king-10285
07/12/2024, 8:05 PMchilly-king-10285
07/12/2024, 8:05 PMjson { "password": "new-password", "method": "password" }
This payload is sent to the action URL that you get from the settings API. Here is an example of how you can get the action URL and send the payload: bash password=ByS8NWuFSkDgMjbe actionUrl=$(curl -s -H "Accept: application/json" \ -H "Authorization: bearer $sessionToken" \ '<https://playground.projects.oryapis.com/self-service/settings/api>' | jq -r '.ui.action') curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" \ -H "Authorization: bearer $sessionToken" \ -d '{"password": "'$password'", "method": "password"}' \ "$actionUrl" | jq
In this example, ByS8NWuFSkDgMjbe
is the new password and $sessionToken
is the session token of the user who wants to change their password. Sources: - [Ory Kratos User Settings & Profile Management](https://www.ory.sh/docs/kratos/self-service/flows/user-settings#api-clients-and-clients-without-browsers) - [Ory Kratos User Settings & Profile Management - Update Password](https://www.ory.sh/docs/kratos/self-service/flows/user-settings#update-password)full-notebook-65880
07/12/2024, 8:53 PMfull-notebook-65880
07/12/2024, 8:53 PM2006-01-02T15:04:05+07:00
full-notebook-65880
07/13/2024, 9:54 AMchilly-king-10285
07/13/2024, 9:54 AMchilly-king-10285
07/13/2024, 9:55 AMYYYY-MM-DD
. The year may be 0000
, indicating that it is omitted. To represent only the year, YYYY
format is allowed. Here is an example: json { "birthdate": "2000-01-01" }
Please note that depending on the underlying platform's date related function, providing just year can result in varying month and day. So the implementers need to take this factor into account to correctly process the dates. Sources: - [Ory API Reference - oidc](https://www.ory.sh/docs/reference/api) - [Hydra API Reference - oidc](https://www.ory.sh/docs/hydra/reference/api)full-notebook-65880
07/13/2024, 10:55 AMchilly-king-10285
07/13/2024, 10:55 AMchilly-king-10285
07/13/2024, 10:55 AMbash password=ByS8NWuFSkDgMjbe actionUrl=$(curl -s -H "Accept: application/json" \ -H "Authorization: bearer $sessionToken" \ '<https://playground.projects.oryapis.com/self-service/settings/api>' | jq -r '.ui.action') curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" \ -H "Authorization: bearer $sessionToken" \ -d '{{"password": "'$password'", "method": "password"}}' \ "$actionUrl" | jq
In this example, ByS8NWuFSkDgMjbe
is the new password and $sessionToken
is the session token of the user who wants to change their password. Possible validation errors include not providing the password or providing a password which doesn't match the password policy. For additional security, you can also configure Ory to terminate all active sessions of the user when they change their password. To do this, you add the revoke_active_sessions
action to the hooks
configuration in the config file: yaml selfservice: flows: settings: after: password: hooks: - hook: revoke_active_sessions
Sources: - [Ory Kratos User Settings & Profile Management](https://www.ory.sh/docs/kratos/self-service/flows/user-settings#api-clients-and-clients-without-browsers) - [Ory Kratos User Settings & Profile Management - Update Password](https://www.ory.sh/docs/kratos/self-service/flows/user-settings#update-password-1) - [Ory Kratos Session Management - Revoke Sessions](https://www.ory.sh/docs/kratos/session-management/revoke-sessions-hook)full-notebook-65880
08/31/2024, 7:58 AMchilly-king-10285
08/31/2024, 7:58 AMchilly-king-10285
08/31/2024, 7:59 AM/sessions/token-exchange
API endpoint is used to exchange a session token. This is part of the Ory API and is used in the frontend. Here are the parameters it requires: - `init_code`: This is a string that is part of the code returned when initializing the flow. It is a required query parameter. - `return_to_code`: This is a string that is part of the code returned by the return_to URL. It is also a required query parameter. The operation does not require authentication. Here's an example of how it might be used in a native app authentication flow: 1. The native app initializes a login or registration flow and receives the first part of the session token exchange code from the Ory Network. 2. After the user performs the social sign-in, the user is redirected back to the native application via an iOS Universal Link or Android App Link. 3. The native application then exchanges the session token exchange code for a session token using the first part of the code returned from the flow initialization, and the second part of the code returned from the return_to
query parameter. Sources: - [Ory API Reference](https://www.ory.sh/docs/reference/api) - [Kratos API Reference](https://www.ory.sh/docs/kratos/reference/api) - [Social sign-in for native and mobile apps](https://www.ory.sh/docs/kratos/social-signin/native-apps#the-native-app-authentication-flow)full-notebook-65880
08/31/2024, 8:00 AMchilly-king-10285
08/31/2024, 8:00 AMchilly-king-10285
08/31/2024, 8:01 AMreturn_to_code
and init_code
parameters with the /sessions/token-exchange
API endpoint. The return_to_code
is part of the code returned by the return_to
URL, not the return_to
parameter itself. Here's a simplified example of how it might work: 1. Your Flutter app initializes a login or registration flow with Ory, and receives the first part of the session token exchange code (init_code
). 2. After the user completes the login or registration process, they are redirected back to your Flutter app. The redirection URL will include a code
parameter, which is the second part of the session token exchange code (return_to_code
). 3. Your Flutter app then makes a GET request to the /sessions/token-exchange
endpoint, including the init_code
and return_to_code
as query parameters. Please note that the actual implementation might be more complex and depends on the specifics of your application and your Ory configuration. Sources: - [Ory API Reference](https://www.ory.sh/docs/reference/api) - [Kratos API Reference](https://www.ory.sh/docs/kratos/reference/api) - [Social sign-in for native and mobile apps](https://www.ory.sh/docs/kratos/social-signin/native-apps#the-native-app-authentication-flow)full-notebook-65880
09/06/2024, 8:13 PMchilly-king-10285
09/06/2024, 8:13 PMchilly-king-10285
09/06/2024, 8:13 PM<http://ory.bar.com|ory.bar.com>
and <http://app.bar.com|app.bar.com>
will work; > - <http://ory.bar.com|ory.bar.com>
and <http://bar.com|bar.com>
will work; > - <http://ory.bar.com|ory.bar.com>
and <http://not-bar.com|not-bar.com>
will not work. If your Next.js app and Ory Kratos are not on the same domain, you'll need to adjust your setup to ensure they are. Additionally, you need to ensure that all cookies are sent using the appropriate CORS and includeCredentials
configurations. This is especially important if you're making AJAX requests. If you're still encountering issues after checking these points, you might want to look into your server's CORS configuration to ensure it's allowing requests from the correct origins. Sources: - [Ory Kratos User Settings & Profile Management](https://www.ory.sh/docs/kratos/self-service/flows/user-settings#initialize-settings-flow) - [Ory Kratos User Settings & Profile Management - Client-Side (AJAX) Browser Clients](https://www.ory.sh/docs/kratos/self-service/flows/user-settings#user-and-profile-settings-for-client-side-ajax-browser-clients)full-notebook-65880
09/06/2024, 8:14 PMchilly-king-10285
09/06/2024, 8:14 PMchilly-king-10285
09/06/2024, 8:14 PMlocalhost
domain. Ory APIs must be available on the same domain (so localhost
) as your application to avoid issues with third-party cookies (e.g. when using Ory Session Cookies). The easiest way to expose Ory on your localhost
domain is to use the Ory CLI Tunnel. Here's an example of how to do this: bash ory tunnel --dev --project $PROJECT_SLUG <http://localhost:3000>
In this command, $PROJECT_SLUG
is the project slug from your project's Connect page. You can also set up environment variables for your local development. Here's an example of how to do this: bash # Unix export VITE_ORY_SDK_URL=<http://localhost:4000> # Windows $Env:VITE_ORY_SDK_URL = "<http://localhost:4000>"
In this example, <http://localhost:4000>
is the URL where your Ory APIs are exposed. Sources: - [Ory Local Development](https://www.ory.sh/docs/getting-started/local-development#local-development) - [Ory Custom UI with Ory Elements](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-ory-elements#run-the-sample-application) - [Ory Integrate Authentication into React](https://www.ory.sh/docs/getting-started/integrate-auth/react#run-your-react-app)full-notebook-65880
09/06/2024, 8:23 PMchilly-king-10285
09/06/2024, 8:23 PMchilly-king-10285
09/06/2024, 8:24 PMjavascript import axios from 'axios'; const api = axios.create({ baseURL: '<https://your-ory-endpoint.com>', withCredentials: true, }); api.get('/self-service/settings/browser') .then(response => { // Handle the response }) .catch(error => { // Handle the error });
In this example, <https://your-ory-endpoint.com>
should be replaced with the URL of your Ory instance. Please note that you need to make sure your server is set up to accept cross-origin requests from your site's domain, otherwise you might encounter CORS errors. Sources: - [Ory Kratos User Settings & Profile Management - Client-Side (AJAX) Browser Clients](https://www.ory.sh/docs/kratos/self-service/flows/user-settings#user-and-profile-settings-for-client-side-ajax-browser-clients) - [Ory Kratos Bring-your-own-ui - Single-page application](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#single-page-application)full-notebook-65880
09/16/2024, 5:55 PMbrief-egg-61061
09/16/2024, 5:55 PMbrief-egg-61061
09/16/2024, 5:55 PMreturn_to
query parameter when initializing a login or registration flow. This parameter should be set to the URL of the page the user was trying to access. Here's an example of how you can do this in a Next.js application: javascript import { Configuration, FrontendApi } from "@ory/client"; import { useRouter } from "next/router"; const ory = new FrontendApi( new Configuration({ basePath: "<http://localhost:4000>", // Use your local Ory Tunnel URL baseOptions: { withCredentials: true, // we need to include cookies }, }) ); export const Login = () => { const router = useRouter(); const [searchParams] = useSearchParams(); useEffect(() => { const returnTo = searchParams.get("return_to"); ory .createBrowserLoginFlow({ returnTo: returnTo || "/", // redirect to the original path after login }) .then(({ data: flow }) => { // set the flow data }) .catch((err) => { // handle the error }); }, []); };
In this example, returnTo
is the URL of the page the user was trying to access. If the user was not trying to access a specific page, they are redirected to the root path ("/") after login. Please note that the return_to
query parameter doesn't automatically persist across different flows and must be added to new flows. For example, if the user starts a login flow with return_to
URL set and then switches to a registration flow, the return_to
URL isn't used for the registration flow. In such a case, your application can re-use the same return_to
from the login flow by extracting the return_to
URL from the login flow's flow.return_to
and adding it to the registration flow. Sources: - [Ory Kratos Bring-your-own-ui - Advanced integration - Advanced redirects](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration#advanced-redirects) - [Ory Getting-started - Integrate-auth - Integrate authentication into Next.js - Require login to access the home page](https://www.ory.sh/docs/getting-started/integrate-auth/nextjs#require-login-to-access-the-home-page)full-notebook-65880
09/16/2024, 6:05 PMbrief-egg-61061
09/16/2024, 6:05 PMbrief-egg-61061
09/16/2024, 6:05 PMreturn_to
URL is not on the allow list. Ory uses an allow list to prevent Open Redirect Attacks by only allowing certain domains or paths on a domain. To fix this issue, you need to add the domain of your return_to
URL to the allow list in your Ory configuration. Here's an example of how to do this: yaml selfservice: allowed_return_urls: - <https://www.myapp.com/>
In this example, <https://www.myapp.com/>
is the domain that you want to allow. Replace this with the domain of your return_to
URL. Please note that you need to match the sub-domain and path exactly. For example, if you allow <https://sub.domain.myapp.com/only/path>
, other redirects using <http://myapp.com|myapp.com>
will fail. Sources: - [Ory Kratos Concepts - HTTP redirection configuration - Redirection](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion#redirection) - [Ory Kratos Concepts - Browser redirects and flow completion](https://www.ory.sh/docs/concepts/redirects)