> For the complete documentation index, see [llms.txt](https://p00ls.gitbook.io/token-os/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://p00ls.gitbook.io/token-os/overview/authentication.md).

# Authentication

The TokenOS API uses API keys to authenticate requests. You can view and manage your API keys in the TokenOS Dashboard.

Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth.

Authentication to the API is performed via HTTP basic auth, HTTP body auth, or JWT bearer auth.  All API requests must be made over HTTPS. Calls made over plain HTTP will fail. API requests without authentication will also fail.

### Basic Auth

For HTTP basic auth, the client sends its client ID and client secret as part of the authorization header in an HTTP request.  The Authorization header contains a Base-64 encoded string of {URL-encoded-client-ID}:{URL-encoded-client-secret}.

```javascript
const clientID = "the-client-id"
const clientSecret = "the-secret-id"
const basicAuth = bas64_encode(url_encode(clientID) + ":" + url_encode(clientSecret))

const requestOptions = {
  method: "POST",
  headers: {
    Authorization: "Basic " + basicAuth,
    "Content-Type": "application/x-www-form-urlencoded",
  },
  body: "grant_type=client_credentials&scope=read",
}

fetch("https://your-project.projects.oryapis.com/oauth2/token", requestOptions)
  .then((response) => response.json())
  .then((data) => console.log(data))
```

### JWT Bearer Auth

For JWT bearer auth, this method is similar to basic and body authentication, but instead of sending the client ID and client secret, the client sends a JSON Web Token (JWT) which was signed by its cryptographic key.

```javascript
const clientID = "the-client-id"
const clientSecret = "the-secret-id"

const qs = new URLSearchParams()
qs.set("grant_type", "client_credentials")
qs.set("client_id", clientID)
qs.set("client_secret", clientSecret)
qs.set("scope", read)

const requestOptions = {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: qs.toString(),
}

fetch("https://your-project.projects.oryapis.com/oauth2/token", requestOptions)
  .then((response) => response.json())
  .then((data) => console.log(data))
```

### Enhanced Security Authentication

For clients requiring enhanced security, we do offer

<br>


---

# 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://p00ls.gitbook.io/token-os/overview/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.
