> For the complete documentation index, see [llms.txt](https://docs.bsvblockchain.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bsvblockchain.org/network-topology/spv-wallet/developer-docs/block-headers-service/authentication.md).

# Authentication

## Enabled by Default

By default, it is assumed that you want to use Authentication, which requires a single environment variable.

`BHS_HTTP_AUTH_TOKEN=replace_me_with_token_you_want_to_use_as_admin_token`

## Disabling Auth Requirement

To disable authentication and expose all endpoints openly, set the following environment variable.\
This is available if you prefer to use your own authentication in a separate proxy or similar.\
We do not recommend you expose the server to the internet without authentication,\
as it would then be possible for anyone to prune your headers at will.

`BHS_HTTP_USE_AUTH=false`

## Authenticate with admin token

After the setup of authentication you can use provided token to authenticate.\
To do it, just add the following header to all the requests to Block Headers Service.

```
Authorization: Bearer replace_me_with_token_you_want_to_use_as_admin_token
```

## Additional tokens

If you have a need for additional tokens to authenticate in Block Headers Service.\
you can generate such with the following request:

```http
POST https://{{block-headers-service_url}}/api/v1/access
Authorization: Bearer replace_me_with_token_you_want_to_use_as_admin_token
```

In response, you should receive something similar to the following:

```json
{
  "token": "some_token_created_by_server",
  "createdAt": "2023-05-11T10:20:16.227582Z",
  "isAdmin": false
}
```

Now, you can take the value from the 'token' property in the response and use it in all requests to the server by setting it as a header.

```http
Authorization: Bearer some_token_created_by_server
```

If at some point you want to revoke this additional token you can make a request:

```http
DELETE https://{{block-headers-service_url}}/api/v1/access/{{some_token_created_by_server}}
Authorization: Bearer replace_me_with_token_you_want_to_use_as_admin_token
```

After this request succeeded the token can't be used to authenticate in Block Headers Service.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.bsvblockchain.org/network-topology/spv-wallet/developer-docs/block-headers-service/authentication.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
