---
title: Authentication
description: 'Use one of the following schemes to authenticate to the InfluxDB OSS v2 API: Token authentication Basic authentication Querystring authentication'
url: https://docs.influxdata.com/influxdb/v2/api/authentication/
estimated_tokens: 1075
product: InfluxDB OSS v2
version: v2
publisher: InfluxData
canonical: https://docs.influxdata.com/influxdb/v2/api/authentication/
---

[Download InfluxDB API Spec](/openapi/influxdb-oss-v2-api.yml)

Use one of the following schemes to authenticate to the InfluxDB OSS v2 API:

* Token authentication
* Basic authentication
* Querystring authentication

## Basic Authentication

### Basic authentication scheme

Use the HTTP Basic authentication scheme for InfluxDB `/api/v2` API operations that support it:

### Syntax

`Authorization: Basic BASE64_ENCODED_CREDENTIALS`

To construct the `BASE64_ENCODED_CREDENTIALS`, combine the username and
the password with a colon (`USERNAME:PASSWORD`), and then encode the
resulting string in [base64](https://developer.mozilla.org/en-US/docs/Glossary/Base64).
Many HTTP clients encode the credentials for you before sending the
request.

***Warning**: Base64-encoding can easily be reversed to obtain the original
username and password. It is used to keep the data intact and does not provide
security. You should always use HTTPS when authenticating or sending a request with
sensitive information.*

### Examples

In the examples, replace the following:

* **`USERNAME`**: InfluxDB username
* **`PASSWORD`**: InfluxDB [API token](/influxdb/v2/reference/glossary/#token)
* **`INFLUX_URL`**: your InfluxDB URL

#### Encode credentials with cURL

The following example shows how to use cURL to send an API request that uses Basic authentication.
With the `--user` option, cURL encodes the credentials and passes them
in the `Authorization: Basic` header.

```sh
curl --get "INFLUX_URL/api/v2/signin"
    --user "USERNAME":"PASSWORD"
```

#### Encode credentials with Flux

The Flux [`http.basicAuth()` function](/flux/v0.x/stdlib/http/basicauth/) returns a Base64-encoded
basic authentication header using a specified username and password combination.

#### Encode credentials with JavaScript

The following example shows how to use the JavaScript `btoa()` function
to create a Base64-encoded string:

```js
btoa('USERNAME:PASSWORD')
```

The output is the following:

```js
'VVNFUk5BTUU6UEFTU1dPUkQ='
```

Once you have the Base64-encoded credentials, you can pass them in the`Authorization` header–for example:

```sh
curl --get "INFLUX_URL/api/v2/signin"
    --header "Authorization: Basic VVNFUk5BTUU6UEFTU1dPUkQ="
```

To learn more about HTTP authentication, see[Mozilla Developer Network (MDN) Web Docs, HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).\_

## Query String Authentication

Use the query string authentication scheme with InfluxDB v1-compatible API operations.
Pass your InfluxDB username and API token as query parameters using `u` for username and `p` for password (API token).

### Syntax

`?u=USERNAME&p=INFLUX_API_TOKEN`

### Example

```sh
curl --get "INFLUX_URL/query" \
    --data-urlencode "u=USERNAME" \
    --data-urlencode "p=INFLUX_API_TOKEN" \
    --data-urlencode "q=SHOW DATABASES"
```

Replace the following:

* *`INFLUX_URL`*: your InfluxDB URL
* *`USERNAME`*: your InfluxDB username
* *`INFLUX_API_TOKEN`*: your [InfluxDB API token](/influxdb/v2/reference/glossary/#token)

> [!Warning]
> Query string authentication exposes your credentials in the URL and server logs.
> Use [Token authentication](#section/Authentication/TokenAuthentication) for production environments.

## Token Authentication

Use the [Token authentication](#section/Authentication/TokenAuthentication)scheme to authenticate to the InfluxDB API.

In your API requests, send an `Authorization` header.
For the header value, provide the word `Token` followed by a space and an InfluxDB API token.
The word `Token` is case-sensitive.

### Syntax

`Authorization: Token INFLUX_API_TOKEN`

### Example

#### Use Token authentication with cURL

The following example shows how to use cURL to send an API request that uses Token authentication:

```sh
curl --request GET "INFLUX_URL/api/v2/buckets" \
    --header "Authorization: Token INFLUX_API_TOKEN"
```

Replace the following:

* *`INFLUX_URL`*: your InfluxDB URL
* *`INFLUX_API_TOKEN`*: your [InfluxDB API token](/influxdb/v2/reference/glossary/#token)

### Related endpoints

* [`/authorizations` endpoints](#tag/Authorizations-(API-tokens))

### Related guides

* [Authorize API requests](/influxdb/v2/api-guide/api_intro/#authentication)
* [Manage API tokens](/influxdb/v2/security/tokens/)
