# Authentication
Source: https://docs.aden.space/docs/developers/api/authentication

Bearer tokens: team API keys from your server, Supabase sessions for apps people sign in to.
Every authenticated request carries a bearer token in the `Authorization`
header:

```http
GET /api/v1/tracks?teamId=216 HTTP/1.1
Host: aden.space
Authorization: Bearer <token>
```

A token that starts with &#x2A;*`aden_`** is a [team API key](#team-api-keys).
Anything else is read as a [Supabase session token](#supabase-session-tokens).

Public data needs no token at all: see [Anonymous access](#anonymous-access).

## Team API keys [#team-api-keys]

* Created on **Team → API → New key** in Aden, by a team admin, on the Lite
  plan or higher.
* Format: `aden_` followed by 64 hex characters. Shown once; Aden stores only
  its hash.
* Bound to the team it was made in. Pass that team as `teamId` on list
  endpoints; any other team is refused.
* **Server only.** A request with an `Origin` header (every browser sends one)
  is refused with `403 server_only`: a key in a web page is readable by every
  visitor. For a public website, use the
  [site feed](/docs/developers/website#the-site-feed).

```bash
curl "https://aden.space/api/v1/tracks?teamId=216&limit=5" \
  -H "Authorization: Bearer $ADEN_API_KEY"
```

Your team id is the number in the API page's address
(`aden.space/app/teams/216/api`).

### Access [#access]

| Key          | Can do                                                                                           |
| ------------ | ------------------------------------------------------------------------------------------------ |
| Read only    | `GET` on every endpoint below. Anything else is `403 insufficient_scope`, even if the key leaks. |
| Read & write | The same reads, plus creating and changing milestones, tasks, contacts, webhooks and app data.   |

### Endpoints [#endpoints]

Keys reach these resources and every route under them:

`/tracks` (with versions and stems), `/albums`, `/playlists`, `/events`,
`/tours`, `/posts`, `/milestones`, `/todos`, `/contacts`, `/webhooks`,
`/app-data`.

Everything else answers a key with `403 endpoint_not_allowed` before the key
is even checked. Uploading audio, creating tracks, adding collaborators, chat
and team management need a signed-in member.

### Revoking [#revoking]

**Team → API → Revoke** turns a key off within a minute. Found someone else's
Aden key in public (a repository, a chat)? Report it and its team is told.

## Supabase session tokens [#supabase-session-tokens]

Apps that people sign in to send that person's Supabase access token, the
same one the Aden web app uses. Requests run as that person and reach the
teams they belong to.

```ts
const {
    data: { session },
} = await supabase.auth.getSession()

const res = await fetch('https://aden.space/api/v1/auth/me', {
    headers: { Authorization: `Bearer ${session?.access_token}` },
})
```

* The token expires and refreshes on Supabase's schedule.
* `auth.me`, `user.*` and team management take a session token, never a key.
* One app may send 300 requests a minute and 9,000 an hour per person.

## Choosing a mode [#choosing-a-mode]

| You're building                              | Use                       |
| -------------------------------------------- | ------------------------- |
| A public website showing releases and shows  | Site feed, no key         |
| A website showing private data               | API key, from your server |
| A cron job, CI step, CLI tool or sync script | API key                   |
| An app people sign in to                     | Supabase session          |

## Anonymous access [#anonymous-access]

These need no token:

* `GET /api/v1/public/sites/:handle`: an artist's
  [site feed](/docs/developers/website#the-site-feed).
* `GET /api/v1/health`
* `GET /api/v1/testimonials`

Everything else returns `401 { "error": "Unauthorized" }` without a valid
token.