> 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>'
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mediamelon.com/mediamelon/smartsight-apis/bearer-token-authorization.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
