# Refresh an access token

Canonical page: https://docs.ovok.com/authentication/account/refresh-token

| Method | Path |
| --- | --- |
| `POST` | `/v1/auth/refresh-token` |

[Authentication](/authentication) · [Account routes](/authentication#account-routes)

Exchanges a refresh token for a new access token and a new refresh token. Call it before the access token expires to keep a session alive.

<Callout type="info">

This is an account-level route. It has no `/v1/auth/tenant/` variant. Use the `refreshToken` that a [tenant sign-in](/authentication) or registration returned.

</Callout>

**Auth:** None. The refresh token in the body is the credential.
**Scope:** The session the refresh token belongs to.

## Request [#request]

### Body [#body]

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `refresh_token` | `string` | Yes | The refresh token of the session. At least 1 character. The request field stays in snake case. |

## Behaviour [#behaviour]

- The answer uses `accessToken`, `refreshToken` and `expiresIn`. It also includes the deprecated `access_token`, `refresh_token` and `expires_in` fields for one release; read only the camelCase fields. `refreshToken` may be `null`.
- Store the new `refreshToken` and use it for the next refresh.
- The access token is valid for one hour. `expiresIn` is in seconds.
- A refused refresh token (spent, expired, revoked or not a refresh token) gives `401`; sign in again. A token-store failure with no OAuth error stays `400`.
- A session of a patient whose project turned [`PATIENT_LOGIN_ENABLED`](/settings-and-features/settings/patient-login-enabled) off, or of a practitioner whose project turned [`PRACTITIONER_LOGIN_ENABLED`](/settings-and-features/settings/practitioner-login-enabled) off, gives `403` with `Login is not enabled for this project.` That ends the session: the refresh token is used up, and signing in again is refused while login is off.
- A practitioner who is a project admin is not refused, so a signed-in admin can still turn login back on. They cannot sign in again while it is off.
- The route is rate limited to 600 requests per minute for each caller. Over the limit the answer is `429`, which can sign a user out, so refresh once per token lifetime and not in a loop.

## Example [#example]

```bash
curl -X POST 'https://api.sandbox.ovok.com/v1/auth/refresh-token' \
  -H 'Content-Type: application/json' \
  -d '{
    "refresh_token": "<refresh token from sign-in>"
  }'
```

## Successful response [#successful-response]

`201` — A new token pair.

```json
{
  "accessToken": "<new access token>",
  "refreshToken": "<new refresh token>",
  "expiresIn": 3600,
  "access_token": "<deprecated duplicate>",
  "refresh_token": "<deprecated duplicate>",
  "expires_in": 3600
}
```

| Field | Type | Description |
| --- | --- | --- |
| `accessToken` | `string` | Bearer access token. Valid for one hour. |
| `refreshToken` | `string \| null` | The refresh token to use next, or `null`. |
| `expiresIn` | `integer` | Lifetime of the access token, in seconds. |
| `access_token` | `string` | Deprecated duplicate; read `accessToken`. Removed one release after this compatibility period. |
| `refresh_token` | `string \| null` | Deprecated duplicate; read `refreshToken`. Removed one release after this compatibility period. |
| `expires_in` | `integer` | Deprecated duplicate; read `expiresIn`. Removed one release after this compatibility period. |

## Errors [#errors]

| Status | Meaning |
| --- | --- |
| [`400`](/errors/malformed-request) | The token store could not process the request and returned no OAuth error, or `refresh_token` is missing or empty. |
| [`401`](/errors/unauthenticated) | The refresh token is spent, expired, revoked or not a refresh token. The response includes `WWW-Authenticate: Bearer`; sign in again. |
| [`403`](/errors/forbidden) | Login is switched off for the project of a patient or of a non-admin practitioner. The session ends. |
| [`429`](/errors/too-many-requests) | More than 600 requests in a minute from the same caller. |
