### Install Ory Kratos Go SDK Source: https://www.ory.com/docs/kratos/self-hosted/go Installs the Ory Kratos Go SDK using `go get`. ```bash go get github.com/ory/kratos-client-go@v26.2.0 ``` -------------------------------- ### Initialize Express.js App with Ory SDK Source: https://www.ory.com/docs/getting-started/oauth2-openid/add-oauth2-openid-connect-nodejs-expressjs Set up a basic Express.js application and install necessary packages. This snippet shows the initial project setup and dependency installation. ```bash mkdir example cd example npm init -y npm install express-openid-connect express ``` -------------------------------- ### Ory Hydra Quickstart Configuration Source: https://www.ory.com/docs/hydra/self-hosted/quickstart Example configuration for Ory Hydra, specifying cookie settings, URLs, and secrets. ```yaml serve: cookies: same_site_mode: Lax urls: self: issuer: http://127.0.0.1:4444 consent: http://127.0.0.1:3000/consent login: http://127.0.0.1:3000/login logout: http://127.0.0.1:3000/logout device: verification: http://127.0.0.1:3000/device/verify success: http://127.0.0.1:3000/device/success secrets: system: - youReallyNeedToChangeThis oidc: subject_identifiers: supported_types: - pairwise - public pairwise: salt: youReallyNeedToChangeThis ``` -------------------------------- ### Enable and Start Kratos Service with systemd Source: https://www.ory.com/docs/kratos/guides/deploy-kratos-example Enable the Kratos service to start on boot and then start the service immediately. ```bash systemctl enable kratos.service systemctl start kratos.service ``` -------------------------------- ### Local Development Setup with Bind Mount Source: https://www.ory.com/docs/kratos/guides/docker Start the standard Docker container with SQLite support and mount local configuration files. This approach is recommended for local development only. ```bash docker run -it -e DSN="memory" \ --mount type=bind,source="$(pwd)"/contrib/quickstart/kratos/email-password,target=/home/ory \ oryd/kratos:{version} serve --config /home/ory/kratos.yml ``` -------------------------------- ### Create OAuth 2.0 Client and Parse JSON Output Source: https://www.ory.com/docs/cli/ory-create-oauth2-client This example demonstrates creating an OAuth 2.0 client with JSON output and then parsing the client ID and secret using `jq`. Ensure `jq` is installed for this to work. ```bash client=$(ory create oauth2-client \ --format json \ ...) echo $client # Parse the JSON response using jq to get the client ID and client secret: client_id=$(echo $client | jq -r '.client_id') client_secret=$(echo $client | jq -r '.client_secret') ``` -------------------------------- ### Example Usage Source: https://www.ory.com/docs/hydra/cli/hydra-introspect-token An example of how to introspect a token with a specific project ID. ```bash hydra introspect token AYjcyMzY3ZDhiNmJkNTY --project 32197be3-8e57-4009-becd-9d38dbde129c ``` -------------------------------- ### Install Ory Kratos Node.js UI Source: https://www.ory.com/docs/kratos/guides/deploy-kratos-example Installs the Ory Kratos Node.js UI by creating a user, downloading the UI, installing dependencies, and setting ownership. ```bash useradd -s /bin/false -m -d /opt/uinode uinode cd /opt/uinode wget https://github.com/ory/kratos-selfservice-ui-node/archive/refs/tags/v26.2.0.zip unzip v26.2.0.zip rm v26.2.0.zip mv kratos-selfservice-ui-node-26.2.0/ ui cd ui npm i chown -R uinode /opt/uinode ``` -------------------------------- ### Run Ory Hydra with HSM using Docker Source: https://www.ory.com/docs/hydra/self-hosted/hsm-support Starts a quickstart Docker container that sets up SoftHSM, builds, and runs Ory Hydra with HSM configuration enabled. Ensure Docker and Docker Compose are installed. ```bash docker-compose -f quickstart-hsm.yml up --build ``` -------------------------------- ### Download Quickstart Configuration Files Source: https://www.ory.com/docs/kratos/guides/deploy-kratos-example Download the necessary configuration files for Ory Kratos quickstart. ```bash cd ../config wget https://raw.githubusercontent.com/ory/kratos/v26.2.0/contrib/quickstart/kratos/email-password/identity.schema.json wget https://raw.githubusercontent.com/ory/kratos/v26.2.0/contrib/quickstart/kratos/email-password/kratos.yml ``` -------------------------------- ### Incoming Request Example Source: https://www.ory.com/docs/network/oathkeeper/quickstarts An example of an incoming HTTP GET request to Ory Oathkeeper. ```http GET /my-service/whatever HTTP/1.1 Host: oathkeeper-proxy:4455 Authorization: bearer some-token ``` -------------------------------- ### Set Up Environment Variables Source: https://www.ory.com/docs/polis/install Copy the example environment file to create a new .env file for local configuration. ```bash cp .env.example .env ``` -------------------------------- ### Run Quickstart with MySQL Source: https://www.ory.com/docs/kratos/quickstart Use this command to run the Ory Kratos Quickstart with a MySQL database. ```bash docker compose -f quickstart.yml -f quickstart-standalone.yml -f quickstart-mysql.yml up --build --force-recreate ``` -------------------------------- ### Clone Repository and Start Example Source: https://www.ory.com/docs/keto/quickstart Clone the Ory Keto repository and start the video sharing example using Docker Compose or a bash script. This sets up the necessary services and initializes relationships. ```bash # clone the repository if you don't have it yet git clone git@github.com:ory/keto.git && cd keto # Alternatively, you can use 'https' to clone if ssh cloning gives permission denied error. (Configure ssh keys in github to resolve the issue.) git clone https://github.com/ory/keto.git && cd keto docker-compose -f contrib/cat-videos-example/docker-compose.yml up # or ./contrib/cat-videos-example/up.sh # output: all initially created relationships # NAMESPACE OBJECT RELATION NAME SUBJECT # videos /cats/1.mp4 owner videos:/cats#owner # videos /cats/1.mp4 view videos:/cats/1.mp4#owner # videos /cats/1.mp4 view * # videos /cats/2.mp4 owner videos:/cats#owner # videos /cats/2.mp4 view videos:/cats/2.mp4#owner # videos /cats owner cat lady # videos /cats view videos:/cats#owner ``` -------------------------------- ### Run Quickstart with PostgreSQL Source: https://www.ory.com/docs/kratos/quickstart Use this command to run the Ory Kratos Quickstart with a PostgreSQL database. ```bash docker compose -f quickstart.yml -f quickstart-standalone.yml -f quickstart-postgres.yml up --build --force-recreate ``` -------------------------------- ### Clone Example Next.js App Source: https://www.ory.com/docs/getting-started/integrate-auth/auth-js Clone the Ory Next.js example application and install dependencies. ```bash git clone https://github.com/ory/next-auth-example.git cd next-auth-example npm install cp .env.local.example .env.local npx auth secret ``` -------------------------------- ### Run Quickstart with CockroachDB Source: https://www.ory.com/docs/kratos/quickstart Use this command to run the Ory Kratos Quickstart with a CockroachDB database. ```bash docker compose -f quickstart.yml -f quickstart-standalone.yml -f quickstart-crdb.yml up --build --force-recreate ``` -------------------------------- ### Install Ory Elements for Next.js Source: https://www.ory.com/docs/getting-started/overview Install the necessary Ory packages for your Next.js application. This command is used when starting a new project with Ory. ```bash npm install @ory/elements-react @ory/nextjs ``` -------------------------------- ### Create New Go Project Source: https://www.ory.com/docs/kratos/self-hosted/go Sets up a new Go project directory and initializes a Go module. ```bash mkdir myproject cd myproject go mod init myproject ``` -------------------------------- ### Set Up Local Database Instances Source: https://www.ory.com/docs/polis/install Create database instances for local development using Docker. Ensure Docker is installed. ```bash npm run dev-dbs ``` -------------------------------- ### Start Ory Talos with Docker Compose Source: https://www.ory.com/docs/talos/quickstart Starts Talos with SQLite, Jaeger, and the Admin UI using Docker Compose. Ensure Docker is installed. ```bash docker compose -f docker-compose.oss.yaml up --build -d ``` -------------------------------- ### Build and Run Doctest Example Source: https://www.ory.com/docs/talos/integrate/sdk/talos-go-sdk Compile and execute the Go SDK doctest example. This is useful for verifying the SDK's functionality. ```bash go build -o .bin/doctest-go-sdk ./tools/doctest/examples/go_sdk ./.bin/doctest-go-sdk ``` -------------------------------- ### Get Access Rule by ID Source: https://www.ory.com/docs/oathkeeper/cli/oathkeeper-rules-get Example of how to get a specific access rule by its ID using the Oathkeeper CLI. Ensure the endpoint is correctly set. ```bash oathkeeper rules --endpoint=http://localhost:4456/ get rule-1 ``` -------------------------------- ### Create Go Project Files Source: https://www.ory.com/docs/getting-started/integrate-auth/go Initializes a new Go project by creating necessary files and initializing the Go module. ```bash mkdir your-project cd your-project touch main.go handler.go middleware.go index.html go mod init github.com//your-project ``` -------------------------------- ### Install Node.js 16 and Dependencies Source: https://www.ory.com/docs/hydra/self-hosted/deploy-hydra-example Installs Node.js version 16.x, npm, jq, and unzip on a Ubuntu system using NodeSource setup script. ```bash curl -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh ``` ```bash bash /tmp/nodesource_setup.sh ``` ```bash apt-get install nodejs npm jq unzip ``` -------------------------------- ### Install Dependencies and Run Application Source: https://www.ory.com/docs/getting-started/integrate-auth/react-native Navigate into the cloned directory, install project dependencies using npm, and then run the application on an iOS simulator. ```bash # Change directory cd kratos-selfservice-ui-react-native # Install dependencies npm i # Run on iOS simulator npm run ios ``` -------------------------------- ### Deny Authorizer Access Rule Example Source: https://www.ory.com/docs/oathkeeper/pipeline/authz An example of an access rule using the 'deny' authorizer. This rule denies GET requests to '/some-route' after anonymous authentication. ```json [{ "id": "some-id", "upstream": { "url": "http://my-backend-service" }, "match": { "url": "http://my-app/some-route", "methods": [ "GET" ] }, "authenticators": [{ "handler": "anonymous" }], "authorizer": { "handler": "deny" }, "mutators": [{ "handler": "noop" }] }] ``` -------------------------------- ### Allow Authorizer Access Rule Example Source: https://www.ory.com/docs/oathkeeper/pipeline/authz An example of an access rule using the 'allow' authorizer. This rule permits GET requests to '/some-route' after anonymous authentication. ```json [{ "id": "some-id", "upstream": { "url": "http://my-backend-service" }, "match": { "url": "http://my-app/some-route", "methods": [ "GET" ] }, "authenticators": [{ "handler": "anonymous" }], "authorizer": { "handler": "allow" }, "mutators": [{ "handler": "noop" }] }] ``` -------------------------------- ### Run Development Server (NPM) Source: https://www.ory.com/docs/getting-started/integrate-auth/nextjs-pages-router-quickstart Start the Next.js development server using NPM. ```bash npm run dev ``` -------------------------------- ### Example Login Configuration JSON Source: https://www.ory.com/docs/identities/sign-in/actions An example JSON output from `ory get identity-config` showing configured hooks for login. This helps in identifying the index of hooks for removal. ```json { hooks: [ { hook: "some_other_hook", // The index of this hook is '0'. }, { hook: "revoke_active_sessions", // The index of this hook is '1'. }, ], oidc: { hooks: [], }, password: { hooks: [], }, webauthn: { hooks: [], }, } ``` -------------------------------- ### Forwarded Request Example Source: https://www.ory.com/docs/network/oathkeeper/quickstarts The HTTP GET request after being forwarded by Ory Oathkeeper to the upstream service. ```http GET /my-service/whatever HTTP/1.1 Host: my-backend-service:4455 Authorization: bearer some-token ``` -------------------------------- ### Run Development Server (Bun) Source: https://www.ory.com/docs/getting-started/integrate-auth/nextjs-pages-router-quickstart Start the Next.js development server using Bun. ```bash bun dev ``` -------------------------------- ### Get Identities by Recovery Email Domain Source: https://www.ory.com/docs/kratos/cli/kratos-get-identity Fetches identities whose recovery email addresses end with a specific domain. This example demonstrates combining the list and get commands with 'jq' for filtering. ```bash kratos get identity $(kratos ls identities --format json | jq -r 'map(select(.recovery_addresses[].value | endswith("@ory.sh"))) | .[].id') ``` -------------------------------- ### Copy Environment Example File Source: https://www.ory.com/docs/polis/guides/service Copy the example environment file to create your own .env configuration file. ```bash cp .env.example .env ``` -------------------------------- ### Serve with Configuration File Source: https://www.ory.com/docs/kratos/guides/docker Run the Kratos container and specify the location of the configuration file using the --config flag. ```bash docker run {image-name} serve --config /home/ory/kratos.yml ``` -------------------------------- ### Get Help for a Specific Ory CLI Command Source: https://www.ory.com/docs/guides/cli/cli-basics Use the --help flag with any command to get detailed information about its usage, flags, and modifiers. This example shows help for the 'ory auth' command. ```bash ory auth --help ``` -------------------------------- ### Synopsis of ory perform authorization-code Source: https://www.ory.com/docs/cli/ory-perform-authorization-code This is the basic command structure for starting the example OAuth 2.0 client. ```bash ory perform authorization-code [flags] ``` -------------------------------- ### Initialize Golang SDK Client Source: https://www.ory.com/docs/guides/upgrade/sdk-v1 Example of initializing the Ory Golang SDK client with configuration, including server URL and API key context. ```go import ory "github.com/ory/client-go" var client = NewSDK() // Use this context to access Ory APIs which require an Ory API Key. var oryAuthedContext = context.WithValue(context.Background(), ory.ContextAccessToken, os.Getenv("ORY_API_KEY")) func NewSDK() *ory.APIClient { conf := ory.NewConfiguration() conf.Servers = ory.ServerConfigurations{{ URL: "https://{your-project}.projects.oryapis.com/", }} // If you want the SDK to use a custom HTTP Client, set: // conf.HTTPClient = &http.Client{ /* ... */ } return ory.NewAPIClient(conf) } ``` -------------------------------- ### Download Quickstart Configuration Source: https://www.ory.com/docs/hydra/self-hosted/deploy-hydra-example Downloads the default Ory Hydra quickstart configuration file. ```bash cd ../config wget https://raw.githubusercontent.com/ory/hydra//contrib/quickstart/5-min/hydra.yml ``` -------------------------------- ### Example Hydra Configuration in YAML Source: https://www.ory.com/docs/hydra/self-hosted/kubernetes-helm-chart An example of a YAML configuration file for Ory Hydra, demonstrating how to set specific configuration values like access token TTL. This file is used with `helm install -f`. ```yaml # hydra-config.yaml hydra: config: # example: ttl: access_token: 1h # ... ``` -------------------------------- ### Install Tempo Helm Chart Source: https://www.ory.com/docs/self-hosted/oel/monitoring Install the Tempo Helm chart with default parameters. Tempo requires no specific configuration to run as a single pod. ```bash helm install tempo grafana/tempo ``` -------------------------------- ### Get Flow Error (JavaScript) Source: https://www.ory.com/docs/guides/upgrade/sdk-v1 Fetches a flow error using `ory.frontend.getFlowError`. This is the JavaScript equivalent of the Golang example and replaces `ory.v0alpha2.getSelfServiceError`. ```javascript - const error = await ory.v0alpha2 - .getSelfServiceError(errorId) + const error = await ory.frontend + .getFlowError({ id: errorId }) .then(({ data }) => data) ``` -------------------------------- ### Install Ory Python SDK via Setuptools Source: https://www.ory.com/docs/keto/sdk/python Install the Ory Python SDK using Setuptools. ```bash python setup.py install --user ``` -------------------------------- ### Run Development Server Source: https://www.ory.com/docs/getting-started/integrate-auth/auth-js Start the Next.js development server to test the authentication flow locally. ```bash npm run dev ``` -------------------------------- ### Get Identities by Recovery Email Domain Source: https://www.ory.com/docs/cli/ory-get-identity This example demonstrates how to retrieve identities whose recovery email addresses belong to a specific domain. It combines `ory ls identities` with `jq` to filter and extract the IDs, which are then passed to `ory get identity`. ```bash ory get identity $(ory ls identities --format json | jq -r 'map(select(.recovery_addresses[].value | endswith("@ory.sh"))) | .[].id') ``` -------------------------------- ### Cancel Webhook Request Source: https://www.ory.com/docs/guides/integrate-with-ory-cloud-through-webhooks Cancel a webhook request by raising an error based on a condition. This example cancels for identities with emails starting with 'test-'. ```function function(ctx) if std.startsWith(ctx.identity.traits.email, "test-") then error "cancel" else { user_id: ctx.identity.id } ``` -------------------------------- ### Get Identities by Recovery Email Domain Source: https://www.ory.com/docs/kratos/cli/kratos-identities-get This example demonstrates how to retrieve identities whose recovery email addresses end with a specific domain ('ory.sh'). It combines 'kratos identities list' with 'jq' to filter and extract the IDs, then uses those IDs with 'kratos identities get'. ```bash kratos identities get $(kratos identities list --format json | jq -r 'map(select(.recovery_addresses[].value | endswith("@ory.sh"))) | .[].id') ``` -------------------------------- ### Install Golang SDK v1.1.10 Source: https://www.ory.com/docs/guides/upgrade/sdk-v1 Use this command to install the specified version of the Golang SDK. ```bash go get github.com/ory/client-go@1.1.10 ``` -------------------------------- ### Get JSON Web Key Set Use Source: https://www.ory.com/docs/cli/ory-get-jwk This example shows how to extract the 'use' field from a JSON Web Key Set using `jq`. ```bash ory get jwk | jq -r '.[].use' ``` -------------------------------- ### Create Recovery Flow Source: https://www.ory.com/docs/kratos/bring-your-own-ui/custom-ui-basic-integration This function initiates a recovery flow using the Ory Kratos frontend API. It's a basic example of how to start a recovery process. ```typescript export async function createRecovery() { return await frontend.createNativeRecoveryFlow() } ``` -------------------------------- ### Get Ory Permissions Configuration Source: https://www.ory.com/docs/cli/ory-get-permission-config Retrieves the Ory Permissions configuration for a specific project and saves it to a YAML file. Ensure you have the Ory CLI installed and configured. ```bash ory get permission-config --project ecaaa3cb-0730-4ee8-a6df-9553cdfeef89 --format yaml > permission-config.yaml ``` -------------------------------- ### Run Go Application Source: https://www.ory.com/docs/getting-started/integrate-auth/go Start your Go application locally. ```bash go run . ``` -------------------------------- ### Run Ory Hydra with Default Configuration Source: https://www.ory.com/docs/hydra/self-hosted/quickstart Start Ory Hydra using Docker Compose with the default configuration. This command is suitable for basic setups or when using SQLite. ```bash docker compose -f quickstart.yml up ``` -------------------------------- ### Start the Sample Node.js Application Source: https://www.ory.com/docs/hydra/guides/custom-ui-oauth2 Run the sample Node.js application on port 3000 using npm start. Ensure this terminal remains open as the application must be running to perform the OAuth2 flow. ```bash npm start ``` -------------------------------- ### Identity Data Structure Example Source: https://www.ory.com/docs/oss/guidelines/rest-api-guidelines Defines the Go struct for an 'identity' object, including its ID and other potential fields. Also shows request structures for getting and listing identities. ```Go // An Identity // // Represents an identity (e.g. user). // // swagger:model identity type identity struct { ID uuid.UUID `json:"id"` // ... } // Get Identity Request // // The request object for getting an identity. // // swagger:parameters getIdentity type getIdentityRequest struct { tokenpagination.ResponseHeaderAnnotation // Request Body // // in: body Body getIdentityRequestBody // In GET requests we do not have a body but we keep this for the example's sake. // // Alternatively if a model already exists: // // in: body // Body identity // Foo Bar // // Some description // // in: path Foo string `json:"foo"` // ... } // Request Body for Getting an Identity // // swagger:model type getIdentityRequestBody struct { // Perform search. Search string `json:"search"` } // swagger:route GET /admin/identities identities getIdentity // // ... // // Responses: // ... // ... func listIdentities(w http.ResponseWriter, r *http.Request) {} ``` -------------------------------- ### Create and Import an example OAuth2 Client Source: https://www.ory.com/docs/hydra/cli/hydra-import-client This example demonstrates how to create a JSON file with example OAuth2 clients and then import them using the hydra import client command. It shows the expected JSON structure for client configurations. ```bash cat > ./file.json <) { return ( {children} ) } ``` -------------------------------- ### Bearer Token Access Rule with Token Prefix Source: https://www.ory.com/docs/oathkeeper/pipeline/authn This example demonstrates configuring the `bearer_token` authenticator to only handle requests where the token starts with a specific prefix. This can be used for more granular control over token handling. ```yaml # Some Access Rule Handling a Token with a Specified Prefix: access-rule-3.yaml id: access-rule-2 # match: ... ``` -------------------------------- ### Start HTTP Server (PHP) Source: https://www.ory.com/docs/getting-started/integrate-auth/php Use this command to start a local PHP development server for testing your application. ```bash php -S 127.0.0.1:3000 ```