> ## Documentation Index
> Fetch the complete documentation index at: https://developers.vibrant-wellness.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Authenticate with OAuth2 client credentials.

The Portal API uses the **OAuth2 client credentials** flow. You generate a **client ID** and
**client secret** in the Portal, exchange them for a short-lived **access token**, and send that
token as a bearer token on every request.

**1. Get your credentials**

In the Portal, create a client and copy its **client ID** and **client secret**. See
[API credentials](https://developers.vibrant-wellness.com/api-keys.md).

**2. Exchange them for an access token**

`POST` to the token endpoint with `grant_type=client_credentials`. Request the scopes you need —
`result report` to read results.

```bash theme={null}
curl -X POST https://api.vibrant-america.com/v1/oauth2/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "grant_type=client_credentials" \
  --data-urlencode "client_id=$VW_CLIENT_ID" \
  --data-urlencode "client_secret=$VW_CLIENT_SECRET" \
  --data-urlencode "scope=result report"
```

```json Response theme={null}
{ "access_token": "eyJhbGci...", "token_type": "Bearer", "expires_in": 3600, "expires_at": 1785355754, "scope": "result report" }
```

> [!NOTE]
>
> 🚧 **Working in progress** — the Report endpoint additionally requires an RS256-signed token.
> Until tokens issued for `result report` are RS256 by default, add
> `--data-urlencode "algorithm=RS256"` to the call above when you intend to read reports.

**3. Call the API with the token**

```bash theme={null}
curl https://api.vibrant-america.com/v1/catalog/products \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

> [!NOTE]
>
> Your account context (customer and clinic) is resolved from the credentials — you never pass those
> ids in a request body. Access tokens are short-lived (about **1 hour**); request a new one when it
> expires (cache and reuse it until then rather than fetching one per request).

## Webhook management and delivery verification

[Webhooks](https://developers.vibrant-wellness.com/concepts/webhooks.md) are enabled per account. Manage your webhook endpoints with your
existing OAuth client; you do not need a second client. Request the access token with
`algorithm=RS256`: the webhook management API rejects tokens signed with any other algorithm with
`401`. An endpoint covers every order of your clinic, including all its providers and
Portal-created orders.

When you create an endpoint, Vibrant returns its signing `secret` (`whsec_…`) once. Store it
securely and use it to verify the signature on incoming events. The secret grants no API access, is
never sent in event requests, and is independent of access-token renewal; rotate it through the
management API when needed.

Continue using an access token with the `result report` scopes when you retrieve the report for an
event. See [Authentication for the management API](https://developers.vibrant-wellness.com/concepts/webhooks.md#authentication-for-the-management-api)
and [Verify the signature](https://developers.vibrant-wellness.com/concepts/webhooks.md#verify-the-signature).

## Third-party payment authorization

> [!NOTE]
>
> **WIP — coming soon.** Platform-paid orders use an additional signed payment authorization.
> This contract may change; confirm environment availability with Vibrant before testing.

For `POST /orders` with `chargeIndicator: "T"`, keep the provider's access token in
`Authorization`. Add a fresh **RS256 JWT signed by your platform** in `X-Payment-Authorization`
and your issued `platformId` in the body. The provider token identifies whose order it is;
the platform JWT authorizes payment by the platform.

The platform JWT goes directly on each order request. There is no platform client secret or
platform token exchange. See [Third-party payment](https://developers.vibrant-wellness.com/guides/third-party-payment.md) for setup,
JWT claims, and a complete request example.

## Scopes

| Scope | Grants |
| :- | :- |
| `result` | Read finalized lab results. |
| `report` | Read report status and issues. |

Catalog, quote, patient, and order calls don't require a scope; request `result report` when you'll
retrieve results — **on the same client**. Scopes are permissions of your one client, managed in
[API credentials](https://developers.vibrant-wellness.com/api-keys.md); you never need a separate credential to read results.

## Environments

| Environment | Token endpoint |
| :- | :- |
| Production | `https://api.vibrant-america.com/v1/oauth2/token` |
| Staging | `https://api-sandbox.vibrant-america.com/v1/oauth2/token` |

A token issued by one environment is not valid in the other. See [Environments](https://developers.vibrant-wellness.com/platform/environments.md).

## Keep your secret safe

> [!WARNING]
>
> Your client secret grants full access to your account's data. Treat it like a password.

* Store the client secret in a secret manager — never in source control or client-side code.
* Use **staging** credentials for development; reserve production for live orders.
* Rotate credentials periodically and immediately if one may be exposed. See
  [API credentials](https://developers.vibrant-wellness.com/api-keys.md).


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