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:
- Expressjs
- Next.js
- Go
npm install @ory/client-fetch --save
npm install @ory/client-fetch --save
go get github.com/ory/client-go
2. 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
# Install Ory CLI using Homebrew
brew install ory/tap/cli
# Verify installation
ory help
After installing the CLI, start the tunnel to connect your local application with Ory's APIs:
# Start the tunnel (replace with your project id)
ory tunnel --project $PROJECT_ID http://localhost:3000
To learn more about the Ory Tunnel, read the dedicated section of the Ory CLI documentation.
3. Configure the SDK
Configure your SDK to use the URL:
- Expressjs
- Next.js
- Go
import { Configuration, FrontendApi } from "@ory/client-fetch"
const baseUrl = process.env.ORY_SDK_URL || "http://localhost:4000"
const ory = new sdk.FrontendApi(
new sdk.Configuration({
basePath: baseUrl,
}),
)
import { FrontendApi, Configuration } from "@ory/client-fetch"
const ory = new FrontendApi(
new Configuration({
basePath: process.env.ORY_SDK_URL,
}),
)
export default ory
// ory_client.go
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