> For the complete documentation index, see [llms.txt](https://docs.eseye.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.eseye.com/api-reference/api-reference-pt-br/authentication/request-access-token.md).

# Solicitar token de acesso

Retorne um token de portador OAuth 2.0 para uma conta de serviço da API.

Os tokens são emitidos usando a concessão de credenciais do cliente, que autentica sua conta de serviço em vez de um usuário individual.

## Request a token

> Exchange your Base64-encoded service account credentials for an OAuth2 access token.

```json
{"openapi":"3.1.0","info":{"title":"Authentication","version":"1.0.0"},"tags":[{"name":"Authentication","description":"Tokens are issued using the client credentials grant, which authenticates your service account rather than an individual user.\n\nFor a step-by-step walkthrough, see [Generate a bearer token](generate-a-bearer-token)."}],"servers":[{"url":"https://eseye-idp-{env}.auth.{region}.amazoncognito.com","description":"Eseye identity provider","variables":{"env":{"default":"prod","enum":["qan","stage","prod"],"description":"The environment you are working in."},"region":{"default":"eu-west-1","description":"The AWS region your OAuth service is hosted in, for example `eu-west-1` or `us-east-1`."}}}],"paths":{"/oauth2/token":{"post":{"summary":"Request a token","operationId":"get-token","tags":["Authentication"],"description":"Exchange your Base64-encoded service account credentials for an OAuth2 access token.","requestBody":{"required":true,"content":{"application/x-www-form-urlencoded":{"schema":{"type":"object","required":["grant_type","scope"],"properties":{"grant_type":{"type":"string","description":"The OAuth2 grant type. Always `client_credentials`, because your service account authenticates as itself rather than on behalf of a user."},"scope":{"type":"string","description":"The scope of the access token. Always `api/api`."}}}}}},"responses":{"200":{"description":"An access token was issued.","content":{"application/json":{"schema":{"type":"object","required":["access_token","token_type","expires_in"],"properties":{"access_token":{"type":"string","description":"The bearer token to send on every API request."},"token_type":{"type":"string","description":"The type of token issued."},"expires_in":{"type":"integer","description":"The lifetime of the token in seconds. Tokens are issued with a lifetime of one hour."}}}}}},"400":{"description":"The request was rejected. `invalid_client` means the credentials in the `Authorization` header were not accepted.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","description":"The reason the request was rejected."}}}}}}},"parameters":[{"name":"Authorization","in":"header","required":true,"description":"Enter `Basic`, a space, and your Base64-encoded `ClientID:ClientSecret` (the only value you need to edit).","schema":{"type":"string","default":"Basic <Base64Encoded(ClientID:ClientSecret)>"}}]}}}}
```

Retorna um token bearer OAuth 2.0 para uma conta de serviço da API.

```http
POST /oauth2/token
```

### Endpoint

```
https://eseye-idp-prod.auth.<region>.amazoncognito.com/oauth2/token
```

Substitua `<region>` pela região da AWS fornecida pela Eseye.

### Cabeçalhos da solicitação

| Cabeçalho       | Valor                               | Obrigatório |
| --------------- | ----------------------------------- | ----------- |
| `Authorization` | `Basic <credentials>`               | Sim         |
| `Content-Type`  | `application/x-www-form-urlencoded` | Sim         |

`<credentials>` é a forma codificada em Base64 de `<client-id>:<client-secret>`.

### Parâmetros do formulário

| Parâmetro    | Valor                | Obrigatório | Descrição                       |
| ------------ | -------------------- | ----------- | ------------------------------- |
| `grant_type` | `client_credentials` | Sim         | Autentica a conta de serviço.   |
| `scope`      | `api/api`            | Sim         | Solicita acesso à API da Eseye. |

### Exemplo de solicitação

```bash
curl --request POST \
  --url "https://eseye-idp-prod.auth.eu-west-1.amazoncognito.com/oauth2/token" \
  --user "${ESEYE_CLIENT_ID}:${ESEYE_CLIENT_SECRET}" \
  --header "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "grant_type=client_credentials" \
  --data-urlencode "scope=api/api"
```

### Resposta com sucesso

Uma solicitação aceita retorna HTTP `200`:

```json
{
  "access_token": "eyJraWQiOiJhYmMxMjMiLCJhbGciOiJSUzI1NiJ9...",
  "token_type": "Bearer",
  "expires_in": 3600
}
```

Reutilize o token até ele expirar; depois solicite outro token.

### Resposta de erro

O endpoint retorna HTTP `400` quando rejeita uma solicitação. Um `invalid_client` erro significa que as credenciais não foram aceitas.


---

# 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.eseye.com/api-reference/api-reference-pt-br/authentication/request-access-token.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.
