> For the complete documentation index, see [llms.txt](https://docs.k9.io/key9-identity/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.k9.io/key9-identity/highvolt/highvolt-server/authentication.md).

# Authentication

`highvolt-server` uses a two-stage authentication scheme:

1. A long-lived **Personal Access Token (PAT)** is exchanged for a short-lived **JWT**.
2. All protected endpoints require the JWT as a `Bearer` token in the `Authorization` header.

## Obtaining a token

```http
POST /api/v1/highvolt/auth/token
Content-Type: application/json

{ "token": "<your-PAT>" }
```

**Success response:**

```json
{
  "access_token": "<JWT>",
  "expires_in": 3600
}
```

`expires_in` is in seconds (the configured expiry in minutes × 60).

**Error responses:**

| HTTP Status | Meaning                               |
| ----------- | ------------------------------------- |
| 400         | Missing `token` field in request body |
| 401         | PAT is invalid or expired             |
| 500         | Internal error generating JWT         |

## Using the token

Include the JWT in the `Authorization` header for all `/api/v1/highvolt/submit` and `/api/v1/highvolt/query` requests:

```http
Authorization: Bearer <JWT>
```

When the JWT expires the server returns `401`. Clients should re-authenticate with the PAT and retry.

## Rate limiting

The `/auth/token` endpoint is rate-limited per client IP to prevent brute-force attacks. Requests exceeding the limit receive HTTP `429 Too Many Requests`.

## Security headers

Every response includes:

```
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000; includeSubDomains  (TLS only)
```

## PAT validation

The server compares the submitted PAT against the value in `HIGHVOLT_PAT` using a **constant-time comparison** (`crypto/subtle.ConstantTimeCompare`) to prevent timing-based enumeration attacks.


---

# 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 dynamically by asking a question.

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

```
GET https://docs.k9.io/key9-identity/highvolt/highvolt-server/authentication.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
