# Authentication

> Every call carries an API key or a sign-in token in a header.


Every endpoint except [the OpenAPI spec](https://dev.siteswap.pro/api/v1/openapi.json) and signing in needs a key. Send it one of two ways:

```bash
curl -H "Authorization: Bearer ssk_YOUR_KEY" https://dev.siteswap.pro/api/v1/company
curl -H "X-API-Key: ssk_YOUR_KEY" https://dev.siteswap.pro/api/v1/company
```

> Warning: A key in the address (`?key=`, `?api_key=`, `?token=`) is refused with `400 key_in_url`, because addresses end up in logs, browser history and Referer headers. If a key was ever in a link, revoke it.

## Who a key acts for

A key belongs to one company and acts as the owner or admin who asked for it. Everything that person may not do, the key may not do either, and these stop a key at once:

- the person leaves the company, is no longer an owner or admin, is suspended or deletes their account (`403 account_unavailable`);
- the company is suspended or closed;
- SiteSwap publishes new Terms and the person has not accepted them yet (`403 terms_required`). The key works again as soon as they accept on the site.

## Keeping a key safe

- Call the API from your server. There is no CORS: browsers on other sites cannot call it, and a key in a web page can be read by anyone who opens it.
- SiteSwap keeps only a SHA-256 fingerprint of each key and compares it in constant time. Nobody at SiteSwap can read a key back.
- Revoke a key the moment it may have leaked, on [API keys](/developers/api-keys), or from anywhere by sending the key itself:

```bash
curl -X DELETE -H "Authorization: Bearer ssk_YOUR_KEY" https://dev.siteswap.pro/api/v1/keys/self
```

A revoked key stops at once, on every server.

## Scopes

A key asks for what it may do, and a SiteSwap admin grants some or all of it. A call outside the key's scopes answers `403 scope_missing`.

| Scope | What it allows |
|---|---|
| `listings:read` (Read listings) | Search and read listings, company profiles and the product catalog. |
| `listings:write` (Manage own listings and stock) | Post, change, pause and close your company's listings, add photos and update stock. |
| `offers` (Offers) | Read your company's offers, send offers and counteroffers, accept, decline and withdraw. |
| `alerts` (Alerts) | Read and manage the saved searches and notifications of the person who asked for the key. |
| (any key) | `GET /company`, `GET /keys` and revoking keys |

## Phone apps

The phone apps sign a person in with their email and password and get a sign-in token instead of a key. See [Using the API from the phone app](/developers/guides/phone-app).
