> For the complete documentation index, see [llms.txt](https://docs.mediamelon.com/mediamelon/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mediamelon.com/mediamelon/smartsight-apis/bearer-token-authorization.md).

# Bearer token authorization

Use bearer token authentication if your workflow signs in through SmartSight identity services.

### Get a bearer token

Request a bearer token from the SmartSight identity server.

#### Token endpoint

`POST https://identity.mediamelon.com/realms/mediamelon/protocol/openid-connect/token`

#### Prerequisites

You need:

1. Your SmartSight username
2. Your SmartSight password

{% hint style="info" %}
If you do not have SmartSight identity credentials, contact your MediaMelon representative.
{% endhint %}

#### Example request

{% code overflow="wrap" lineNumbers="true" %}

```bash
curl 'https://identity.mediamelon.com/realms/mediamelon/protocol/openid-connect/token' \
-X POST \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=<email-id>' \
--data-urlencode 'password=<password>' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=smartsight-backend' \
--data-urlencode 'scope=openid'
```

{% endcode %}

#### Required form fields

| Field        | Type   | Description                  |
| ------------ | ------ | ---------------------------- |
| `username`   | string | Your SmartSight username     |
| `password`   | string | Your SmartSight password     |
| `grant_type` | string | Must be `password`           |
| `client_id`  | string | Must be `smartsight-backend` |
| `scope`      | string | Use `openid`                 |

#### Example response

{% code lineNumbers="true" %}

```json
{
  "access_token": "<access_token>",
  "expires_in": 900,
  "refresh_expires_in": 1800,
  "refresh_token": "<refresh_token>",
  "token_type": "Bearer",
  "id_token": "<id_token>",
  "session_state": "<session_state>",
  "scope": "openid email profile"
}
```

{% endcode %}

### Use the bearer token

Send the `access_token` in the `Authorization` header.

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

{% hint style="info" %}
Use the `access_token` for API requests. Refresh or re-request a token when it expires.
{% endhint %}

### Example API request

```bash
curl --request GET \
  --url 'https://smartsight3.mediamelon.com/mm-apis/metricquery/199493832?period=start=1775749920,end=1775836379&metrics=latency,viewercount&aggby=timestamp&granularity=hour&orderby=timestamp&order=asc' \
  --header 'Authorization: Bearer <access_token>'
```
