> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stora.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication overview

> Choose an authentication path for API exploration, managed-account integrations, or partner apps.

## Prerequisites

You'll need a [Developer Portal](https://docs.stora.co/2025-09/guides/developer-portal.md) account.

Use the Developer Portal to create a test operator, manage API access for a connected operator account, or create a partner app. You do not need to connect a real operator account just to explore the API.

> [!TIP]
>
> Create a test operator first if you're exploring the API. Test operators let you try credentials, requests, and webhook setup before working with real operator data.

## Choose your connection method

Choose **Operator integration** for your own operator account or when you manage API access on an operator's behalf. Choose **Partner app** for a product that operators authorise independently.

All paths use the same `Authorization: Bearer <token>` header for API requests. They differ in how you obtain and renew the token.

> [tab] Operator integration
>
> Start with [Connect an account](https://docs.stora.co/2025-09/guides/connect-account.md), then create credentials for that operator through the Developer Portal.
>
> * For short-lived tasks, use an [Access Token](#option-a-access-token).
> * For ongoing backend access, use [Client Credentials](#option-b-oauth-2-0-%E2%80%94-client-credentials).

> [tab] Partner app
>
> [Create a partner app](https://docs.stora.co/2025-09/guides/partner-integrations.md), then use the [Authorization Code flow](#option-c-oauth-2-0-%E2%80%94-authorization-code). Each operator authorises your app independently. Use refresh tokens to maintain that connection.

## Option A: Access token

Use an expiring Access Token for one-time scripts, API exploration, or short-lived AI-agent tasks. Choose a short expiry and only the scopes your task needs.

Follow [Use an Access Token](https://docs.stora.co/2025-09/guides/managed-account-authentication.md#use-an-access-token) to create an expiring token for your test operator or connected account. Use it directly in the bearer header of your [first API request](https://docs.stora.co/2025-09/guides/first-request.md).

## Option B: OAuth 2.0 — Client Credentials

Use this when your backend needs ongoing access to an account you manage, without user interaction. Follow [Use an OAuth Client](https://docs.stora.co/2025-09/guides/managed-account-authentication.md#use-an-oauth-client) for client creation, token exchange, authenticated requests, and renewal.

OAuth access tokens expire after 2 hours. Client Credentials does not issue a refresh token. Your backend obtains a replacement access token by repeating the `client_credentials` exchange.

## Option C: OAuth 2.0 — Authorization Code

An operator's staff member authorises your partner app to access their data through the flow below.

### Step 1: Redirect the user to authorise

Generate an unpredictable, single-use `state` value with a cryptographically secure random generator. Store the value in the initiating browser session on your server, with a short expiry.

The `state` value binds the callback to the session that started the connection and protects against cross-site request forgery (CSRF).

Direct the user's browser to the following URL. Replace `STATE` with the value you stored:

```text theme={null}
https://app.stora.co/oauth2/authorize?
  client_id=YOUR_CLIENT_ID&
  redirect_uri=https://yourapp.com/callback&
  response_type=code&
  scope=public.contact:read public.order:read&
  state=STATE
```

The user logs in to Stora and approves the requested scopes. Stora redirects back to your `redirect_uri` with an authorisation code and the same `state` value:

```text theme={null}
https://yourapp.com/callback?code=AUTHORIZATION_CODE&state=STATE
```

### Step 2: Validate the callback

Before exchanging the code, validate the callback on your server:

1. Read the stored state from the browser session that initiated the connection.
2. Check that the callback includes `state` and that it exactly matches the stored value.
3. Check that the stored state has not expired or already been used.
4. Consume the stored state so another callback cannot reuse it. Make validation and consumption atomic so concurrent callbacks cannot both succeed.

If the state is missing, mismatched, expired, or already used, reject the callback. Do not exchange the code. Require the user to start a new connection attempt.

### Step 3: Exchange the code for tokens

```bash theme={null}
curl -X POST "https://public-api.stora.co/oauth2/token" \
  -H "content-type: application/json" \
  -d '{
    "grant_type": "authorization_code",
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET",
    "code": "AUTHORIZATION_CODE",
    "redirect_uri": "https://yourapp.com/callback"
  }'
```

Response:

```json theme={null}
{
  "access_token": "ACCESS_TOKEN",
  "token_type": "Bearer",
  "expires_in": 7200,
  "scope": "public.contact:read public.order:read",
  "created_at": 1710000000,
  "refresh_token": "REFRESH_TOKEN"
}
```

### Refreshing tokens

Access tokens expire after 2 hours. A request with an expired token returns `401 Unauthorized` with the code [`invalid_token`](https://docs.stora.co/2025-09/guides/errors#invalid_token). Use the refresh token to get a new one without requiring the user to re-authorise:

```bash theme={null}
curl -X POST "https://public-api.stora.co/oauth2/token" \
  -H "content-type: application/json" \
  -d '{
    "grant_type": "refresh_token",
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET",
    "refresh_token": "REFRESH_TOKEN"
  }'
```

The response includes a new `access_token` and a new `refresh_token`. The previous refresh token is revoked.

### PKCE (optional)

[PKCE](https://oauth.net/2/pkce/) (Proof Key for Code Exchange) protects the Authorization Code flow against code interception. Use it when your OAuth client is a single-user application running on a user-owned device — a mobile app, a desktop app, or a CLI tool.

> [!WARNING]
>
> If you're distributing your integration as code that runs outside infrastructure you control (WordPress plugin, browser extension, client-side app extension, packaged on-premise tool, etc.), PKCE alone is not sufficient. Follow [Distributing a public plugin](https://docs.stora.co/2025-09/guides/distributing-public-plugins.md) instead — the broker pattern it describes is the safe way to keep OAuth credentials and tokens out of distributed code.

Generate a `code_verifier` and `code_challenge` before redirecting:

```bash theme={null}
CODE_VERIFIER=$(openssl rand -base64 64 | tr -d '=/+\n' | head -c 128)
CODE_CHALLENGE=$(echo -n "$CODE_VERIFIER" | openssl dgst -sha256 -binary | base64 | tr -d '=' | tr '/+' '_-')
```

Add the challenge to the authorisation URL. Include the session-bound `state` from [Step 1](#step-1-redirect-the-user-to-authorise) and [validate the callback](#step-2-validate-the-callback) before exchanging the code:

```text theme={null}
https://app.stora.co/oauth2/authorize?
  client_id=YOUR_CLIENT_ID&
  redirect_uri=https://yourapp.com/callback&
  response_type=code&
  scope=public.contact:read public.order:read&
  state=STATE&
  code_challenge=CODE_CHALLENGE&
  code_challenge_method=S256
```

Include the `code_verifier` when exchanging the code:

```bash theme={null}
curl -X POST "https://public-api.stora.co/oauth2/token" \
  -H "content-type: application/json" \
  -d '{
    "grant_type": "authorization_code",
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET",
    "code": "AUTHORIZATION_CODE",
    "redirect_uri": "https://yourapp.com/callback",
    "code_verifier": "CODE_VERIFIER"
  }'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.