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
When using the tunnel, configure your SDK to use the local tunnel 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 || "http://localhost:3000",
}),
)
export default ory
// ory_client.go
package main
import (
"fmt"
"os"
ory "github.com/ory/client-go"
)
// ConfigureOryClient sets up the Ory client for local development with tunnel
func ConfigureOryClient() (*ory.APIClient, string) {
tunnelPort := os.Getenv("ORY_SDK_URL")
if tunnelPort == "" {
tunnelPort = "4000"
}
// Configure baseUrl for local development (equivalent to JavaScript example)
baseUrl := fmt.Sprintf("http://localhost:%s", tunnelPort)
// Configure Ory SDK
configuration := ory.NewConfiguration()
configuration.Servers = ory.ServerConfigurations{{URL: baseUrl}}
// Create and return client
return ory.NewAPIClient(configuration), baseUrl
}
For production environments, configure the SDK to use the Ory Network URL:
- Expressjs
- Next.js
- Go
import { FrontendApi, Configuration } from "@ory/client-fetch"
const ory = new FrontendApi(
new Configuration({
basePath:
process.env.ORY_SDK_URL || "https://$PROJECT_SLUG.projects.oryapis.com",
}),
)
export default ory
import { FrontendApi, Configuration } from "@ory/client-fetch"
const ory = new FrontendApi(
new Configuration({
basePath: process.env.ORY_SDK_URL || "https://$PROJECT_SLUG.projects.oryapis.com",
}),
)
export default ory
// ory_client.go
package main
import (
"fmt"
"os"
ory "github.com/ory/client-go"
)
// ConfigureOryClient sets up the Ory client for either production or development
func ConfigureOryClient() (*ory.APIClient, string) {
// Get project slug from environment
projectSlug := os.Getenv("PROJECT_SLUG")
// Get the Ory SDK URL from environment variables or build from project slug
baseUrl := os.Getenv("ORY_SDK_URL")
if baseUrl == "" {
if projectSlug != "" {
// Use production Ory Network URL with project slug
baseUrl = fmt.Sprintf("https://%s.projects.oryapis.com", projectSlug)
} else {
// Fallback to local development
baseUrl = "http://localhost:4000"
}
}
// Configure Ory SDK
configuration := ory.NewConfiguration()
configuration.Servers = ory.ServerConfigurations{{URL: baseUrl}}
// Create and return client
return ory.NewAPIClient(configuration), baseUrl
}