# Authentication

An integration is software that reaches your Virtualdisplay account through the API: your own system, a script or an
agent. It has a client ID and a secret of its own.

## Make an integration

In Portal, open **Settings › Access** in your own account and create one. The integration belongs to that account and
reaches only that account. Portal shows the client ID and the secret once. Copy the secret then: Portal cannot show it
again, and you can only replace it.

## Get a token

Exchange the client ID and secret at the token endpoint, `POST /v1/oauth/token`, as a form. Use the `client_credentials`
grant:

```sh title="Request"
curl -X POST https://api.virtualdisplay.io/v1/oauth/token \
  -d grant_type=client_credentials \
  -d client_id=$CLIENT_ID \
  -d client_secret=$CLIENT_SECRET
```

Send the ID and secret in the body, as above, or in an HTTP Basic header with the ID and secret joined by a colon. Do not
send both. The response carries the token:

```json title="Response"
{ "access_token": "…", "token_type": "Bearer", "expires_in": 3600 }
```

The token lasts one hour. This grant issues no refresh token: when a token expires, exchange the secret again.

## Use the token

Send the token in the `Authorization` header of every request:

```
Authorization: Bearer <access_token>
```

## Find the base URL

Every path in the reference is on `https://api.virtualdisplay.io`, under `/v1`, the token endpoint included. The
discovery document is on `https://api.portal.virtualdisplay.io`, and names the consent page an app signs in through:

```
GET https://api.portal.virtualdisplay.io/.well-known/oauth-authorization-server
```

## Replace the secret

Rotate the secret in **Settings › Access**. The new secret works at once. The old one keeps working for seven days, so
you can change your system without an outage. Choose to revoke the old secret when you rotate if it may have leaked.

## Revoke an integration

Disable the integration in **Settings › Access**. Its secret stops working, and a token it already holds is refused on
its next call, rather than when it expires.

## Sign in on someone's behalf

An integration that acts for someone who signs in with their Portal account, rather than with credentials of its own,
uses the authorization code grant with PKCE (S256). The discovery document's `authorization_endpoint` is the consent page in Portal, and the
token endpoint is the same `POST /v1/oauth/token`, with `grant_type=authorization_code` and, later, `refresh_token`.