bland-finland-95044
04/15/2024, 3:11 PMchilly-king-10285
04/15/2024, 3:11 PMchilly-king-10285
04/15/2024, 3:11 PMbland-finland-95044
04/15/2024, 4:38 PMchilly-king-10285
04/15/2024, 4:38 PMchilly-king-10285
04/15/2024, 4:38 PMbland-finland-95044
04/15/2024, 4:41 PMchilly-king-10285
04/15/2024, 4:41 PMchilly-king-10285
04/15/2024, 4:41 PMbland-finland-95044
04/15/2024, 6:39 PMchilly-king-10285
04/15/2024, 6:39 PMchilly-king-10285
04/15/2024, 6:39 PM/ui/{flow_name}
format. If you want to replace a single flow, you can set a custom UI base URL for that specific flow. When you define a custom UI base URL, you lose access to the Ory Account Experience for that specific flow. The custom UI base URL takes precedence over the SDK Configuration URL. For more details, you can refer to the [Ory documentation](https://www.ory.sh/docs/kratos/bring-your-own-ui/configure-ory-to-use-your-ui).bland-finland-95044
04/17/2024, 4:30 PMchilly-king-10285
04/17/2024, 4:30 PMchilly-king-10285
04/17/2024, 4:31 PMbland-finland-95044
04/26/2024, 2:11 PMchilly-king-10285
04/26/2024, 2:11 PMchilly-king-10285
04/26/2024, 2:11 PMbland-finland-95044
05/08/2024, 7:40 PMchilly-king-10285
05/08/2024, 7:40 PMchilly-king-10285
05/08/2024, 7:41 PMjavascript // Check a permission const isAllowed = await ory .permission .checkPermission({namespace: "n", /* ... */}) .then(({data}) => data.allowed)
In this example, ory
is an instance of the Ory client, permission
is the permissions module, and checkPermission
is the method to check a permission. The method takes an object with the details of the permission to check, and returns a promise that resolves to an object with a data
property. The data
property is an object with an allowed
property, which is true
if the permission is granted and false
otherwise. Please note that you need to replace "n"
and /* ... */
with the actual values for your use case. For more information, you can refer to the [Ory SDK V1 upgrade guide](https://www.ory.sh/docs/guides/upgrade/sdk-v1#permissions--access-control).bland-finland-95044
05/08/2024, 7:54 PMchilly-king-10285
05/08/2024, 7:54 PMchilly-king-10285
05/08/2024, 7:54 PMjavascript import { Configuration, PublicApi, AdminApi } from "@ory/client"
In this example, Configuration
, PublicApi
, and AdminApi
are being imported from the @ory/client
package. For more detailed SDK documentation, you can refer to the autogenerated documentation available on GitHub. Here are some examples: - [OAuth2Api API](https://github.com/ory/hydra-client-go/blob/master/docs/OAuth2Api.md) - [OidcApi API](https://github.com/ory/hydra-client-go/blob/master/docs/OidcApi.md) Please note that these links point to the Go SDK documentation, but they can give you an idea of what methods are available. The JavaScript SDK should have similar methods. For more specific information about the JavaScript SDK, you may want to refer to the [Ory JavaScript SDK documentation](https://www.ory.sh/docs/hydra/sdk/js).bland-finland-95044
05/08/2024, 7:59 PMchilly-king-10285
05/08/2024, 7:59 PMchilly-king-10285
05/08/2024, 7:59 PMopenapi-generator
to generate its SDKs, which means the SDKs are based on an OpenAPI specification. You can view the source code for the generated Ory SDKs on the [Ory SDK GitHub repository](https://github.com/ory/sdk). The OpenAPI specification used to generate the SDKs might be included in the repository, or you might be able to generate it using the openapi-generator
. For more detailed information, you may want to refer to the [Ory SDK documentation](https://www.ory.sh/docs/sdk) or the [openapi-generator
GitHub repository](https://github.com/OpenAPITools/openapi-generator).bland-finland-95044
05/09/2024, 2:13 PMchilly-king-10285
05/09/2024, 2:13 PMchilly-king-10285
05/09/2024, 2:14 PMcheck_permission
API and not any other APIs. This would allow a service to check permissions without being able to modify permissions or perform other potentially harmful operations. For more information on how to manage API keys in Ory, you can refer to the [Ory documentation](https://www.ory.sh/docs/concepts/personal-access-token#authorizing-ory-network-project-admin-apis).bland-finland-95044
05/09/2024, 2:15 PMchilly-king-10285
05/09/2024, 2:15 PMchilly-king-10285
05/09/2024, 2:15 PMbland-finland-95044
05/09/2024, 2:31 PMchilly-king-10285
05/09/2024, 2:31 PMchilly-king-10285
05/09/2024, 2:31 PMbland-finland-95044
05/09/2024, 3:07 PMchilly-king-10285
05/09/2024, 3:07 PMchilly-king-10285
05/09/2024, 3:08 PMbland-finland-95044
05/09/2024, 7:04 PMchilly-king-10285
05/09/2024, 7:04 PMchilly-king-10285
05/09/2024, 7:04 PMPermissionApi
with the TypeScript SDK in Ory. However, you can refer to the [Ory SDK documentation](https://www.ory.sh/docs/sdk) for general information on how to use the SDKs. For more specific examples and guidance, you may want to check the [Ory GitHub repositories](https://github.com/ory/sdk) or seek advice from the Ory community.bland-finland-95044
05/10/2024, 6:05 PMchilly-king-10285
05/10/2024, 6:05 PMchilly-king-10285
05/10/2024, 6:06 PM/sessions/whoami
endpoint. This endpoint uses the HTTP headers in the GET request to determine who is authenticated. When the request is successful, it adds the user ID to the 'X-Kratos-Authenticated-Identity-Id' header in the response. Here's an example of how to call this endpoint from a server-side application: javascript // pseudo-code example router.get('/protected-endpoint', async function (req, res) { const session = await client.toSession(undefined, req.header('cookie')) console.log(session) })
In this example, client.toSession
is called with the cookie
header from the request. The function returns a session object, which includes the user ID. If you're calling this endpoint from a non-browser application (e.g. a mobile app), you must include the session token: javascript // pseudo-code example ... const session = await client.toSession("the-session-token") console.log(session)
In this case, client.toSession
is called with the session token. Again, the function returns a session object, which includes the user ID. For more information, you can refer to the [Ory API Reference](https://www.ory.sh/docs/reference/api).bland-finland-95044
05/10/2024, 6:23 PMchilly-king-10285
05/10/2024, 6:23 PMchilly-king-10285
05/10/2024, 6:24 PMtoSession
method with a cookie using the Ory JavaScript SDK, you can use the FrontendApi
class. Here's an example: javascript import { Configuration, FrontendApi } from "@ory/client" const frontend = new FrontendApi( new Configuration({ basePath: "<http://localhost:4000>", // Use your local Ory Tunnel URL baseOptions: { withCredentials: true, }, }), ) const session = await frontend .toSession({ cookie: "ory_session_...=..." }) .catch((err) => { // Check the error to see if it's a 401 / 403 -> not logged in })
In this example, frontend
is an instance of the FrontendApi
class. The toSession
method is called with an object that includes the cookie
property. The method returns a promise that resolves to a session object if the user is logged in, or rejects with an error if the user is not logged in. Please replace "ory_session_...=..."
with the actual session cookie. For more information, you can refer to the [Ory documentation](https://www.ory.sh/docs/identities/sign-in/check-session-token-cookie-api).bland-finland-95044
05/16/2024, 6:59 PMchilly-king-10285
05/16/2024, 6:59 PMchilly-king-10285
05/16/2024, 7:00 PM&
) at the end of the command. This will run the process in the background. Here's an example: bash $ ory tunnel --project <your-project-slug> <https://www.example.org> &
In this example, replace <your-project-slug>
with the slug of your project. The &
at the end of the command runs the process in the background. For more information, you can refer to the [Ory documentation](https://www.ory.sh/docs/cli/ory-tunnel#ory-tunnel).bland-finland-95044
05/16/2024, 7:46 PMchilly-king-10285
05/16/2024, 7:46 PMchilly-king-10285
05/16/2024, 7:46 PMjavascript const express = require("express") const app = express() const { FrontendApi, Configuration } = require("@ory/client") const ory = new FrontendApi( new Configuration({ basePath: `https://${process.env.PROJECT_SLUG}.<http://projects.oryapis.com|projects.oryapis.com>`, }), ) app.get("/blog/posts", async function (req, res) { const authHeader = req.headers.authorization const hasAuthHeader = authHeader.startsWith("Bearer ") const sessionToken = hasAuthHeader ? authHeader.slice(7, authHeader.length) : null const session = await ory .toSession({ cookie: req.cookies.join("; "), xSessionToken: sessionToken, }) .catch((err) => { // Check the error to see if it's a 401 / 403 -> not logged in }) }) app.listen(3000, function () { console.log("Listening on <http://localhost:3000%22|http://localhost:3000">) })
For more information, you can refer to the [Ory documentation](https://www.ory.sh/docs/hydra/concepts/before-oauth2) and [Ory API Reference](https://www.ory.sh/docs/identities/sign-in/check-session-token-cookie-api).bland-finland-95044
05/21/2024, 7:12 PMchilly-king-10285
05/21/2024, 7:12 PMchilly-king-10285
05/21/2024, 7:12 PMbash ory get jwk some-example-set \ --public \ --project {project.id} --format json-pretty \ > es256-public.jwks.json
In this example, replace some-example-set
with the name of your key set and {project.id}
with the ID of your project. The command exports the public key to a file named es256-public.jwks.json
. Next, you can use the public key to verify the JWT. The exact method to do this depends on the library you're using. For example, if you're using the jsonwebtoken
library in Node.js, you can do something like this: javascript const jwt = require('jsonwebtoken'); const fs = require('fs'); const publicKey = fs.readFileSync('es256-public.jwks.json', 'utf8'); jwt.verify(token, publicKey, (err, decoded) => { if (err) { console.log('Token verification failed:', err); } else { console.log('Token verified successfully:', decoded); } });
In this example, replace token
with the JWT you want to verify. For more information, you can refer to the [Ory documentation](https://www.ory.sh/docs/identities/session-to-jwt-cors#end-to-end-example).bland-finland-95044
05/21/2024, 7:14 PMchilly-king-10285
05/21/2024, 7:14 PMchilly-king-10285
05/21/2024, 7:15 PM/sessions/whoami
endpoint with the tokenize_as
query parameter. Here's an example of how to do this with a curl
command: bash curl -X GET \ -H "Cookie: ory_session...=..." \ "https://{project.slug}.<http://projects.oryapis.com/sessions/whoami?tokenize_as=jwt_example_template1|projects.oryapis.com/sessions/whoami?tokenize_as=jwt_example_template1>"
In this example, replace ory_session...=...
with the actual session cookie and {project.slug}
with the slug of your project. The tokenize_as
query parameter is set to jwt_example_template1
, which should be a valid, configured Ory Session token template. The response from this endpoint will include a tokenized
property, which is the session token: json { "tokenized": "{the-jwt}" }
For more information, you can refer to the [Ory documentation](https://www.ory.sh/docs/identities/session-to-jwt-cors#end-to-end-example).bland-finland-95044
05/22/2024, 3:32 PMchilly-king-10285
05/22/2024, 3:32 PMchilly-king-10285
05/22/2024, 3:33 PMbash ory create project --name "Ory OAuth2 Example" project_id="{set to the project ID from output}"
2. Create an OAuth2 client: bash ory create oauth2-client --project "$project_id" \ --name "Client Credentials Demo" \ --grant-type client_credentials
3. Export the ID and secret of the created client: bash client_id="{set to CLIENT ID from output}" client_secret="{set to CLIENT SECRET from output}"
4. Start the Client Credentials Grant: bash ory perform client-credentials \ --client-id="$client_id" \ --client-secret="$client_secret" \ --project "$project_id"
This will return an access token, which is a JWT that can be used for M2M communication. For more information, you can refer to the [Ory documentation](https://www.ory.sh/docs/getting-started/ory-network-oauth2#client-credentials-grant).bland-finland-95044
05/22/2024, 3:37 PMchilly-king-10285
05/22/2024, 3:37 PMchilly-king-10285
05/22/2024, 3:37 PMjavascript import { Configuration, JsonPatch, OAuth2Api } from "@ory/client" const ory = new OAuth2Api( new Configuration({ basePath: `https://${process.env.ORY_PROJECT_SLUG}.<http://projects.oryapis.com|projects.oryapis.com>`, accessToken: process.env.ORY_API_KEY, }), ) export async function patchOAuth2Client(id: string, patches: JsonPatch[]) { await ory.patchOAuth2Client({ id, jsonPatch: [ ...patches, { op: "replace", path: "access_token_strategy", value: "jwt", }, ], }) }
In this example, ory
is an instance of the OAuth2Api
class. The patchOAuth2Client
method is used to update the client configuration. The access_token_strategy
property is set to "jwt"
, which means that Ory will issue JWT access tokens for this client. For more information, you can refer to the [Ory documentation](https://www.ory.sh/docs/oauth2-oidc/jwt-access-token#per-client-configuration).bland-finland-95044
05/22/2024, 3:42 PMory perform client-credentials --client-id="$client_id" --client-secret="$client_secret" --project "$project_id"
ACCESS TOKEN <long string here>
chilly-king-10285
05/22/2024, 3:42 PMchilly-king-10285
05/22/2024, 3:42 PMACCESS TOKEN
is the JWT itself. JWTs are composed of three parts: a header, a payload, and a signature. Each part is base64Url encoded, and they are concatenated with periods (.
) as separators. This results in a long string, which is what you're seeing. You can decode the JWT to view its contents. Here's an example of how to do this in Node.js: javascript const jwt = require('jsonwebtoken'); const token = '<long string here>'; // replace with your JWT const decoded = jwt.decode(token, { complete: true }); console.log(decoded);
In this example, replace '<long string here>'
with your JWT. The jwt.decode
function decodes the JWT and returns its contents. The { complete: true }
option tells the function to return the complete decoded token, including the header, payload, and signature. Please note that this only decodes the JWT, it does not verify its signature. To verify the signature, you would need the public key that corresponds to the private key used to sign the JWT. You can get this from the Ory server. For more information, you can refer to the [Ory documentation](https://www.ory.sh/docs/oauth2-oidc/jwt-access-token#per-client-configuration) and the [jsonwebtoken documentation](https://github.com/auth0/node-jsonwebtoken#jwtdecodetoken--options).bland-finland-95044
05/22/2024, 3:49 PMchilly-king-10285
05/22/2024, 3:49 PMchilly-king-10285
05/22/2024, 3:49 PMjavascript import { Configuration, OAuth2Api } from "@ory/client" const ory = new OAuth2Api( new Configuration({ basePath: `https://${process.env.ORY_PROJECT_SLUG}.<http://projects.oryapis.com|projects.oryapis.com>`, accessToken: process.env.ORY_API_KEY, }), ) export async function acceptConsent(consentChallenge: string) { const { data } = await ory.getOAuth2ConsentRequest({ consentChallenge }) return await ory .acceptOAuth2ConsentRequest({ consentChallenge: consentChallenge, acceptOAuth2ConsentRequest: { session: { access_token: { some_custom_claim: "some_custom_value", }, id_token: { id_custom_claim: "some_value", }, }, }, }) .then(({ data }) => data) }
In this example, ory
is an instance of the OAuth2Api
class. The acceptConsent
function is used to accept a consent request. The access_token
property of the session
object is set to an object that includes the custom claims. These claims will be included in the JWT. If you want the custom claim to be added to the top level (instead of a nested level) in the access token, you need to modify the /oauth2/allowed_top_level_claims
configuration: bash ory patch oauth2-config {project.id} \ --replace "/oauth2/allowed_top_level_claims=[\"some_custom_claim\"]"
In this example, replace {project.id}
with the ID of your project. The command updates the configuration to allow the some_custom_claim
claim to be added to the top level of the access token. For more information, you can refer to the [Ory documentation](https://www.ory.sh/docs/oauth2-oidc/jwt-access-token#custom-consent-ui-and-custom-claims-for-jwt-access-token).bland-finland-95044
05/22/2024, 4:25 PMchilly-king-10285
05/22/2024, 4:25 PMchilly-king-10285
05/22/2024, 4:25 PMbash GET /relation-tuples/expand?namespace=<namespace>&object=<object>&relation=<relation>&max-depth=<max-depth>
In this example, replace <namespace>
, <object>
, <relation>
, and <max-depth>
with the appropriate values. The max-depth
parameter can be used to limit the depth of the tree to be returned. If the value is less than 1 or greater than the global max-depth, then the global max-depth will be used instead. The Expand API can be used to list who has access to an object, determine why someone has access to an object, and audit permissions in the system. For more details, you can refer to the [Ory Keto API overview](https://www.ory.sh/docs/keto/concepts/api-overview#expand-subject-sets) and the [Ory Keto REST API reference](https://www.ory.sh/docs/keto/reference/rest-api#getexpand).