Skip to main content

Setting up Ory Identity

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:

  1. An Ory Network account (or self-hosted Ory installation)
  2. Your Ory project slug or API URL
  3. Your development environment set up with your framework of choice

1. Install SDK for your framework

First, install the Ory SDK for your framework:

npm install @ory/client --save

2. Configure the SDK

Next, configure the SDK with your Ory project URL:

const { Configuration, FrontendApi } = require("@ory/client")

// Initialize the SDK
const ory = new FrontendApi(
new Configuration({
basePath: "https://$PROJECT_SLUG.projects.oryapis.com",
baseOptions: {
withCredentials: true,
},
}),
)

3. 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:

# Install Ory CLI
npm install -g @ory/cli

# Start the tunnel (replace with your project slug)
ory tunnel --dev https://$PROJECT_SLUG.projects.oryapis.com --port 4000
To learn more about the Ory Tunnel, read the

dedicated section of the Ory CLI documentation. :::

When using the tunnel, configure your SDK to use the local tunnel URL:

// For local development with tunnel
const ory = new FrontendApi(
new Configuration({
basePath: "http://localhost:4000",
baseOptions: {
withCredentials: true,
},
}),
)

4. Verify the setup

Let's test the connection to make sure everything is working:

// Test connection
ory
.toSession()
.then(({ data }) => {
console.log("Connected to Ory successfully:", data)
})
.catch((err) => {
console.log("Not authenticated, which is expected:", err.response?.status)
})

Next Steps

Now that you have set up the Ory SDK and verified the connection, you're ready to implement authentication flows in your application.

In the next section, we'll cover how to implement registration and login flows using browser-based authentication.