# Authentication

This guide walks users through how to use authenticate requests using the Alluvial APIs.

## Client Credentials Flow

Below is a ladder diagram showing the flow to create an access token.

This flow involves 3 parties:

* Platform Server: the client looking to access the Alluvial API and which has previously been given a Client ID and Client Secret credentials.
* Alluvial Authorization Server: responsible for validating credentials and generating JWT Access Token.
* Alluvial API: the target resource to be accessed.

<figure><img src="/files/BNJ5Iyw98ER4XJTvenYc" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
To obtain a Client ID and Client Secret reach out to your Alluvial representative.
{% endhint %}

## Getting Access Token

To obtain an access token, use the a request below using your client id and secret.

**Request:**

{% hint style="info" %}
Make sure you are using the correct audience URL. Staging: <https://api.staging.alluvial.finance> Production: <https://api.alluvial.finance>
{% endhint %}

{% code title="" overflow="wrap" lineNumbers="true" %}

```bash
curl  'https://auth.alluvial.finance/oauth/token' \
--header 'content-type: application/json' \
--data '{
 "audience": "https://api.staging.alluvial.finance",
 "grant_type": "client_credentials",
 "client_id": "<YOUR_CLIENT_ID>",
 "client_secret": "<YOUR_CLIENT_SECRET>"
}'
```

{% endcode %}

**Response:**

{% code title="" overflow="wrap" lineNumbers="true" %}

```json
{
  "access_token": "eyJhbGci…CVm5g",
  "scope": "read:eth-oracle read:eth-contracts read:eth-operators",
  "expires_in": 86400,
  "token_type": "Bearer"
}
```

{% endcode %}

### Refreshing Access Token

Access Token should be reused for every request until it expires, in which case they should go through the Client Credential Flow again to obtain a fresh Access Token.

#### Sample request

To use the access token, pass it via the HTTP header `Authorization: Bearer`

{% code title="" overflow="wrap" lineNumbers="true" %}

```bash
curl 'https://api.staging.alluvial.finance/v0/wallets/0x2B7ff5d4C14A9Da8d5C9354c7A52aB40DdC1C01e' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer eyJh...b'
```

{% endcode %}

If you receive a 2xx response, you are now able to make fully authenticated requests.

If you receive a 4xx response, check if your access token is expired.

You are now ready to make requests! Please check out our guides on [staking](https://docs.alluvial.finance/guides/staking) and [redemptions](https://docs.alluvial.finance/guides/redemptions).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.alluvial.finance/guides/supplemental_guides/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
