Configure Ory
This guide shows how to set up the necessary dependencies and configurations to integrate Ory's identity management features into your application.
Prerequisites
Before starting, ensure you have:
- An Ory network account
- Your Ory project id
- Your development environment set up with your framework of choice
First, install the Ory SDK for your framework:
- Express (JS)
- Go
npm install @ory/client-fetch --save
npm install @ory/client-fetch --save
go get github.com/ory/client-go
Set up local development with Ory Tunnel
For local development, you'll need to use Ory Tunnel to connect your local application with Ory's APIs:
- macOS
- Linux
- Windows
Install the Ory CLI using homebrew on macOS:
brew install ory/tap/cli
ory help
Install the Ory CLI on Linux using bash <(curl ...):
bash <(curl https://raw.githubusercontent.com/ory/meta/master/install.sh) -d -b . ory <version-you-want>
./ory help
You may want to move the Ory CLI to your $PATH:
sudo mv ./ory /usr/local/bin/
ory help
Install the Ory CLI on Windows using Scoop:
scoop bucket add ory https://github.com/ory/scoop.git
scoop install ory
ory help
After installing the CLI, start the tunnel to connect your local application with Ory's APIs:
ory tunnel --project $ORY_PROJECT_ID --port 4000 http://localhost:3000
This proxies Ory's APIs on http://localhost:4000 and forwards all other traffic to your application at http://localhost:3000.
Running the tunnel is required for local development because Ory's session cookies must be set on the same domain as your
application.
To learn more about the Ory Tunnel, read the dedicated section of the Ory CLI documentation.
Configure the SDK
Configure your SDK to use the URL:
- Express (JS)
- Next.js
- Go
import { Configuration, FrontendApi } from "@ory/client-fetch"
export const baseUrl = process.env.ORY_SDK_URL || "http://localhost:4000"
export const ory = new FrontendApi(
new Configuration({
basePath: baseUrl,
}),
)
import { FrontendApi, Configuration } from "@ory/client-fetch"
const ory = new FrontendApi(
new Configuration({
basePath: process.env.NEXT_PUBLIC_ORY_SDK_URL,
credentials: "include",
}),
)
export default ory
package main
import (
"os"
ory "github.com/ory/client-go"
)
// ConfigureOryClient sets up the Ory client for local development with tunnel
func ConfigureOryClient() (*ory.APIClient, string) {
baseUrl := os.Getenv("ORY_SDK_URL")
// Configure Ory SDK
configuration := ory.NewConfiguration()
configuration.Servers = ory.ServerConfigurations{{URL: baseUrl}}
// Create and return client
return ory.NewAPIClient(configuration), baseUrl
}
For local development, set the ORY_SDK_URL environment variable to the local tunnel URL:
export ORY_SDK_URL=http://localhost:4000
For production environments, set the ORY_SDK_URL environment variable to the production URL:
export ORY_SDK_URL=https://$PROJECT_SLUG.projects.ory.sh
