---
title: "Migrate to OAuth from private key authentication"
description: "Switch to OAuth to ensure your app is discoverable in Klaviyo's app marketplace."
url: "https://developers.klaviyo.com/en/docs/migrate_to_oauth_from_private_key_authentication"
category: "Partner resources"
lastUpdated: "2026-11-10"
related: ["https://developers.klaviyo.com/en/docs/llms.txt"]
---

# Migrate to OAuth from private key authentication

> This is the Markdown version of https://developers.klaviyo.com/en/docs/migrate_to_oauth_from_private_key_authentication

Switch to OAuth to ensure your app is discoverable in Klaviyo's app marketplace.

## You will learn

If you’re here, it’s likely that your Klaviyo app uses private key authentication. We now require  all of our published partners to use OAuth when integrating with Klaviyo. This guide covers how you can migrate and the benefits you’ll get in doing so.

> [!NOTE]
> Migrating to OAuth will not break your app. Your integration will continue to work as expected.

## Why update to OAuth?

> [!CAUTION]
> Your app will be delisted if you do not upgrade to OAuth. Only apps using OAuth will be considered for inclusion in Klaviyo's App Marketplace.

Switching your app from private key authentication to OAuth allows for greater exposure to our customers, simpler integration workflows, and access to all new items our R&D team is developing. Here are some benefits you’ll get from the switch:

* **Increased marketplace and in-product visibility**

    Maintain exposure to 150,000+ customers by keeping your app listed and discoverable on the [App Marketplace](https://marketplace.klaviyo.com/en-us). We expect there to be roughly 5-10x more unique visitors to the App Marketplace due to new improvements.

* **App-branded event metrics**

    Say goodbye to the generic gear icon and get branded exposure on the Klaviyo platform.

* **Seamless integration**

    Streamline the integration process to as little as a few clicks, ensuring a smooth experience for customers, increasing adoption and satisfaction rates.

* **Marketing & enablement opportunities**

    Eligibility for inclusion in marketing newsletters and other enablement initiatives.

* **Exclusive API access**

    Unlock powerful API features, including our Universal Content and Webhooks APIs.

> [!NOTE]
> Check out our YouTube video on [Why create an app with Klaviyo](https://www.youtube.com/watch?v=PbLcJIZ9eHM) for more information.

## Migrate to OAuth with an AI agent

```prompt Migrate this app from private key authentication to OAuth
Move this app from Klaviyo private API keys to OAuth, so each account connects by granting consent instead of pasting a key.

First read https://developers.klaviyo.com/en/docs/migrate_to_oauth_from_private_key_authentication.md, then https://developers.klaviyo.com/en/docs/set_up_oauth.md and https://developers.klaviyo.com/en/docs/handle_your_apps_oauth_flow.md.

Ask me for these before you change anything, unless I've already given them:
- The OAuth app's client ID, and the name of the environment variable that holds its client secret. Don't ask me to paste the secret here. If I haven't created the app yet, stop and point me to https://developers.klaviyo.com/en/docs/create_a_public_oauth_app; that's done in Klaviyo.
- The redirect URL, which must also be listed on the app in Klaviyo, and the scopes the app needs.

Then, following this app's language, framework and conventions:
1. Find where the app takes, stores and sends private API keys, and list it for me before you change anything.
2. Add the OAuth authorization, deny and uninstall flows the two linked guides describe, and change the connect UI to use OAuth instead of a private key.
3. Store each account's access and refresh tokens in the database, encrypted at rest, with `expires_in` or a calculated `expires_at`, and refresh before they expire.
4. Send `Authorization: Bearer <access token>` on every API call. On a `401 Unauthorized`, refresh the token, save the new tokens and retry the call once.
5. Add a flow that asks each account still using a private key to reconnect with OAuth. Keep the private key path working until I say those accounts have moved; don't delete stored keys.

Read the client secret from the environment, and keep it and all tokens out of source control and logs. Don't do the steps that happen outside the code, such as the security assessment, help docs or app review.

When you're done, tell me what you changed and how to run the connect flow end to end with a test account.
```

## How to migrate to OAuth

If your app was previously published using private key authentication, we estimate that a single engineer will need 1-2 sprints (2-4 weeks) to complete the migration to OAuth. When migrating to OAuth, each step listed below should take roughly 1 week:

1. **OAuth implementation**
   - [Create your OAuth app](https://developers.klaviyo.com/en/docs/create_a_public_oauth_app.md). Please note that after creation, your app will require at least 5 active users to meet our listing requirements before submission.
   - Ensure you properly handle refresh tokens and token expiration.
   - Start completing our [Testing & Review Template](https://docs.google.com/document/d/1_KiNf2HnmiPujtmoSctrQIUWswhIRYfQNZaOMq-Rktg/edit?tab=t.0#heading=h.kumz85nckbuh) .
2. **UI and OAuth workflow updates**
   - Update your app’s UI/UX to support connecting to Klaviyo with OAuth.
   - [Initiate the OAuth authorization/deny/uninstall flows](https://developers.klaviyo.com/en/docs/handle_your_apps_oauth_flow.md) and eliminate the private key connection option in your app.
   - Ensure that your app meets our [app listing requirements](https://developers.klaviyo.com/en/docs/klaviyo_app_listing_requirements.md)**.**
3. **Security and documentation**
   - [Complete the security assessment form](https://klaviyo-surveys.typeform.com/to/aXcnD2vi?typeform-source=www.google.com) and address feedback from our Security and Trust team.
   - Create and update [help documentation](https://developers.klaviyo.com/en/docs/drive_integration_adoption.md) for your app.
   - Set up and use [branding for your app metrics](https://developers.klaviyo.com/en/docs/understanding_branded_events.md).
4. **Review and submission**
   - Review our [Pass your app review guide](https://developers.klaviyo.com/en/docs/pass_your_app_review.md) to ensure your app follows best practices.
   - [Submit your OAuth app](https://developers.klaviyo.com/en/docs/submit_your_app_for_review.md) for the Klaviyo team’s approval.
   - Respond and update your app based on Klaviyo review feedback.

> [!CAUTION]
> Within 3 months of migrating your app to OAuth, you should migrate all customers currently using private key authentication to your OAuth app. This transition will offer enhanced security and an improved product experience for our shared customers.

## Your fast track migration plan

```prompt Run Klaviyo's OAuth demo locally
Set up and run Klaviyo's OAuth demo (a small Flask app) on this machine.

First read https://developers.klaviyo.com/en/docs/migrate_to_oauth_from_private_key_authentication.md.

Ask me for these before you change anything, unless I've already given them:
- The client ID of an OAuth app that has the redirect URL `http://localhost:5000/auth/callback` and the scopes `accounts:read profiles:read`. If I haven't created it yet, stop and tell me; that's done in Klaviyo's Developer Console.
- The name of the environment variable that holds the app's client secret.
- Where to create the demo folder. Don't put it inside an existing project unless I say so.

Then:
1. Create `klaviyo-oauth-demo`, make a virtual environment with `python3 -m venv .venv`, activate it and run `pip install flask requests python-dotenv`.
2. Save the code from https://gist.github.com/nickohara-klaviyo/15f45b2619d2618fe5147bda7916e3d6 as `oauth_flow.py`. Read it before running it, and tell me if it doesn't match the guide.
3. Create `.env.local` with `CLIENT_ID`, `CLIENT_SECRET` (from the environment variable), `REDIRECT_URI=http://localhost:5000/auth/callback`, `KLAVIYO_SCOPES="accounts:read profiles:read"` and a randomly generated `FLASK_SECRET_KEY`. Don't print the secret. If the folder is under git, make sure `.env.local` is ignored.
4. Start the server with `python oauth_flow.py`.

Don't sign in for me. Tell me to open http://localhost:5000/auth/start, log in to Klaviyo and grant consent; the access and refresh tokens come back as JSON. Then give me the guide's two checks to run with those tokens: `POST http://localhost:5000/auth/refresh` with `{"refresh_token": "..."}`, and `GET http://localhost:5000/whoami` with `Authorization: Bearer <access token>`.
```

We've built a working OAuth demo in Flask to help you expedite your migration. Follow the steps below to get started.

### 1. Get your Klaviyo OAuth app credentials

1. Go to your Klaviyo Developer Console
2. Create an OAuth app
3. Add the redirect URL: `http://localhost:5000/auth/callback`
4. Add the following scopes: accounts:read profiles:read
5. Grab your Client ID and Client Secret

### 2. Clone the demo project

First,  run the following code to set up your virtual environment.

```bash
mkdir klaviyo-oauth-demo && cd klaviyo-oauth-demo
python3 -m venv .venv
source .venv/bin/activate
pip install flask requests python-dotenv
```

You can access the [demo Python code here](https://gist.github.com/nickohara-klaviyo/15f45b2619d2618fe5147bda7916e3d6). Save the provided code sample as `oauth_flow.py` and create a `.env.local` file with your credentials:

```
CLIENT_ID=your_client_id_here
CLIENT_SECRET=your_client_secret_here
REDIRECT_URI=http://localhost:5000/auth/callback
KLAVIYO_SCOPES="accounts:read profiles:read"
FLASK_SECRET_KEY=super-secret-for-local-dev  
# Note: for production, do not hardcode FLASK_SECRET_KEY.
# Instead, generate a strong random GUID/hex string and import via a secure env var or secrets manager.
```

### 3. Run the OAuth flow locally

Start the server:

```bash
python oauth_flow.py
```

Kick off the flow in your browser: `http://localhost:5000/auth/start`

You'll log into Klaviyo, grant consent, and immediately get back your access token and refresh token in JSON.

### 4. Refresh tokens automatically

We've built a `/auth/refresh` endpoint to handle token rotation for you:

```bash
curl -X POST http://localhost:5000/auth/refresh \
  -H "Content-Type: application/json" \
  -d '{"refresh_token": "YOUR_REFRESH_TOKEN"}'
```

This ensures you'll never run into expired token issues.

### 5. Test real Klaviyo API calls

Use the `/whoami` endpoint with your access token to hit Klaviyo's API directly:

```bash
curl -X GET http://localhost:5000/whoami \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```

This verifies end-to-end that your migration works.

## What this means for your team

* **Engineering leaders:** You don't need to commit weeks of dev time. With our starter code, your teams can cut migration down to a few days.
* **Security & compliance:** OAuth eliminates key sprawl, enables scoped permissions, and simplifies audits.
* **Future-proofing:** This is the industry standard. Your engineers will integrate faster with other modern systems once OAuth is the norm.

## How to productionize your OAuth migration

The demo code gets you from private key → OAuth in minutes. But before rolling this into production, here are the must-dos for a secure, scalable integration:

### 1. Store tokens in your database

Save both the access token and refresh token securely in your database, encrypted at rest. Record `expires_in` (or calculate `expires_at`) so you can proactively refresh before expiry.

### 2. Handle token expiry gracefully

Every Klaviyo API call must include the access token in the `Authorization: Bearer <token>` header. If you receive a `401 Unauthorized`, your access token has expired. At that point:

1. Use the refresh token to request a new access token
2. Save the new tokens to your DB
3. Retry the original API call transparently

This ensures a seamless experience with no downtime for your users.

### 3. Migrate your existing users

Any users who are using the private key integration will need to re-authenticate using OAuth. Build a simple re-authentication flow into your app to request consent from each user. Once migrated, you can deprecate private key support entirely.

### 4. Metrics auto migration

Good news: any metrics previously tracked via private keys will automatically migrate to branded metrics. This means your data continuity is preserved, and you get all the benefits of OAuth without losing visibility. Learn more about branded metrics here.

## Additional resources

* [Make API calls using OAuth](https://developers.klaviyo.com/en/docs/set_up_oauth.md)
* [Build an OAuth app (Academy course)](https://academy.klaviyo.com/en-us/courses/build-an-oauth-app-with-klaviyo)
* [YouTube Playlist](https://www.youtube.com/playlist?list=PLHkNfHgtxcUZFU_vpOM8vAKai0BC6yxzB)
* [OAuth Code Example](https://gist.github.com/nickohara-klaviyo/15f45b2619d2618fe5147bda7916e3d6)
* [OAuth Code Example ReadMe](https://gist.github.com/nickohara-klaviyo/5fcf3b3fe8687b17df1e01271028f076)
* Developer Docs
   * [Create a Public OAuth App](https://developers.klaviyo.com/en/docs/create_a_public_oauth_app.md)
   * [Make API Calls Using OAuth](https://developers.klaviyo.com/en/docs/set_up_oauth.md)
   * [Handle Your App’s OAuth Flow](https://developers.klaviyo.com/en/docs/handle_your_apps_oauth_flow.md)
   * [Branding for app metrics](https://developers.klaviyo.com/en/docs/understanding_branded_events.md)
