|
1 |
| -Manage tokens to authenticate and authorize access to resources and data in your |
2 |
| -{{< product-name >}} instance. |
| 1 | +Manage tokens to authenticate and authorize access to resources and data in your {{< product-name >}} instance. |
| 2 | + |
| 3 | +## Provide your token |
| 4 | + |
| 5 | +Before running CLI commands or making HTTP API requests, you must provide a valid token to authenticate. |
| 6 | +The mechanism for providing your token depends on the client you use to interact with {{% product-name %}}--for example: |
| 7 | + |
| 8 | +{{< tabs-wrapper >}} |
| 9 | + |
| 10 | +{{% tabs %}} |
| 11 | +[influxdb3 CLI](#influxdb3-cli-auth) |
| 12 | +[cURL](#curl-auth) |
| 13 | +{{% /tabs %}} |
| 14 | + |
| 15 | +{{% tab-content %}} |
| 16 | + |
| 17 | +When using the `influxdb3` CLI, you can use the `--token` option to provide your authorization token. |
| 18 | + |
| 19 | +{{% code-placeholders "YOUR_TOKEN" %}} |
| 20 | +```bash |
| 21 | +# Include the --token option in your influxdb3 command |
| 22 | +influxdb3 query \ |
| 23 | + --token YOUR_TOKEN \ |
| 24 | + --database example-db \ |
| 25 | + "SELECT * FROM 'example-table' WHERE time > now() - INTERVAL '10 minutes'" |
| 26 | +``` |
| 27 | +{{% /code-placeholders %}} |
| 28 | + |
| 29 | +You can also set the `INFLUXDB3_AUTH_TOKEN` environment variable to automatically provide your |
| 30 | +authorization token to all `influxdb3` commands. |
| 31 | + |
| 32 | +{{% code-placeholders "YOUR_TOKEN" %}} |
| 33 | +```bash |
| 34 | +# Export your token as an environment variable |
| 35 | +export INFLUXDB3_AUTH_TOKEN=YOUR_TOKEN |
| 36 | + |
| 37 | +# Run an influxdb3 command without the --token option |
| 38 | +influxdb3 query \ |
| 39 | + --database example-db \ |
| 40 | + "SELECT * FROM 'example-table' WHERE time > now() - INTERVAL '10 minutes'" |
| 41 | +``` |
| 42 | +{{% /code-placeholders %}} |
| 43 | + |
| 44 | +Replace `YOUR_TOKEN` with your authorization token. |
| 45 | + |
| 46 | +{{% /tab-content %}} |
| 47 | + |
| 48 | +{{% tab-content %}} |
| 49 | + |
| 50 | +{{% code-placeholders "AUTH_TOKEN" %}} |
| 51 | +```bash |
| 52 | +# Add your token to the HTTP Authorization header |
| 53 | +curl "http://{{< influxdb/host >}}/api/v3/query_sql" \ |
| 54 | + --header "Authorization: Bearer AUTH_TOKEN" \ |
| 55 | + --data-urlencode "db=example-db" \ |
| 56 | + --data-urlencode "q=SELECT * FROM 'example-table' WHERE time > now() - INTERVAL '10 minutes'" |
| 57 | +``` |
| 58 | +{{% /code-placeholders %}} |
| 59 | + |
| 60 | +Replace `AUTH_TOKEN` with your actual InfluxDB 3 token. |
| 61 | + |
| 62 | +{{% /tab-content %}} |
| 63 | + |
| 64 | +{{< /tabs-wrapper >}} |
3 | 65 |
|
4 | 66 | {{< children hlevel="h2" readmore=true hr=true >}}
|
0 commit comments