> For the complete documentation index, see [llms.txt](https://docs.assine.online/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.assine.online/api/api/autenticacao.md). Agents can also search and read this documentation through its [MCP server](https://docs.assine.online/~gitbook/mcp).

# Sessão

Sessão e autenticação de usuário

A autenticação ocorre por [OAuth2](https://oauth.net/2/) com GrantType Password, ou através da geração de um token de acesso de API na interface da conta administrativa.

Chave de aplicação (token de acesso) será fornecida pela equipe Soluti.

## Gerar token de acesso

<mark style="color:green;">`POST`</mark> `https://api-v1.assine.online/oauth`

Após o login, use o `access_token` nos demais endpoints informando no header `Authorization` no formato `Authorization: Bearer <access-token>`.

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| Content-Type | string | application/json |
| Accept       | string | application/json |

#### Request Body

| Name           | Type   | Description                                          |
| -------------- | ------ | ---------------------------------------------------- |
| client\_id     | string | Deve ter a identificação da aplicação. (padrão: app) |
| client\_secret | string | Deve ter o secret da aplicação (padrão: app)         |
| username       | string | Identificação do usuário (e-mail)                    |
| password       | string | Senha do usuário                                     |
| grant\_type    | string | Sempre "password”                                    |

{% tabs %}
{% tab title="200 " %}

```javascript
{
	"access_token": "04f82054011fb69e6baeccbd4adb54103b073fb4",
	"expires_in": 3600,
	"token_type": "Bearer",
	"scope": "",
	"refresh_token": "ff0e296daaccc854ac391e3f22620e9ab7c8c178"
}
```

{% endtab %}

{% tab title="401 " %}

```javascript
{
	"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
	"title": "invalid_grant",
	"status": 401,
	"detail": "Invalid username and password combination"
}
```

{% endtab %}
{% endtabs %}

## Revogar token de acesso

<mark style="color:green;">`POST`</mark> `https://api-v1.assine.online/oauth/revoke`

Revogar o token de acesso, você estará fazendo logout na aplicação.

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| Content-Type | string | application/json |
| Accept       | string | application/json |

#### Request Body

| Name  | Type   | Description              |
| ----- | ------ | ------------------------ |
| token | string | O token de acesso gerado |

{% tabs %}
{% tab title="200 " %}

```javascript
{
    "revoked": true
}
```

{% endtab %}
{% endtabs %}

## Listar tokens de acesso

<mark style="color:blue;">`GET`</mark> `https://api-v1.assine.online/access-token`

Não será possível ver o token em si por questões de segurança, mas você pode ver quando os tokens foram gerados.

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| Content-Type | string | application/json |
| Accept       | string | application/json |

{% tabs %}
{% tab title="200 " %}

```javascript
{
    "_links": {
        "self": {
            "href": "https://api.assine.online/access-token?page=1"
        },
        "first": {
            "href": "https://api.assine.online/access-token"
        },
        "last": {
            "href": "https://api.assine.online/access-token?page=1"
        }
    },
    "_embedded": {
        "access_token": [
            {
                "accessToken": "***** HIDDEN *****",
                "expires": {
                    "date": "2020-02-28 14:41:55.000000",
                    "timezone_type": 3,
                    "timezone": "UTC"
                },
                "id": "5405",
                "scope": {},
                "_embedded": {
                    "user": {
                        "id": 474,
                        "name": "Jhon Doe",
                        "username": "siletic225@xhyemail.com",
                        "email": "siletic225@xhyemail.com",
                        "_links": {
                            "self": {
                                "href": "https://api.assine.online/user/474"
                            }
                        }
                    }
                },
                "_links": {
                    "self": {
                        "href": "https://api.assine.online/access-token/5405"
                    }
                }
            }
        ]
    },
    "page_count": 1,
    "page_size": 25,
    "total_items": 9,
    "page": 1
}
```

{% endtab %}
{% endtabs %}

## Criar token de sessão

<mark style="color:green;">`POST`</mark> `https://api-v1.assine.online/access-token`

Diferente do login, você pode criar tokens de sessão com durações maiores.

#### Headers

| Name          | Type   | Description            |
| ------------- | ------ | ---------------------- |
| Authorization | string | Bearer \<access-token> |
| Content-Type  | string | application/json       |
| Accept        | string | application/json       |

#### Request Body

| Name     | Type   | Description                                                            |
| -------- | ------ | ---------------------------------------------------------------------- |
| password | string | A senha do usuário logado para confirmação                             |
| expires  | string | Data de quando qer que este token expire. Exemplo: 2023-01-01 23:59:00 |

{% tabs %}
{% tab title="201 Este é o único momento que você conseguirá ver o accessToken, então é importante que armazene-o em local seguro." %}

```javascript
{
    "accessToken": "7ab3072b667611948efee24a8452cb1f04ea8adf",
    "expires": {
        "date": "2021-01-01 23:59:00.000000",
        "timezone_type": 3,
        "timezone": "UTC"
    },
    "id": "5406?q=verify&sessionIndex=e508b5272fb8a03b0f9d979011454f354d18d4c7",
    "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
    "title": "Token created",
    "status": 201,
    "detail": "Access Token data"
}
```

{% endtab %}
{% endtabs %}

## Remover token de sessão

<mark style="color:red;">`DELETE`</mark> `https://api-v1.assine.online/access-token/:id`

#### Path Parameters

| Name | Type   | Description                              |
| ---- | ------ | ---------------------------------------- |
| id   | number | O id do token que deseja remover/revogar |

#### Headers

| Name          | Type   | Description            |
| ------------- | ------ | ---------------------- |
| Authorization | string | Bearer \<access-token> |
| Content-Type  | string | application/json       |
| Accept        | string | application/json       |

{% tabs %}
{% tab title="204 " %}

```
```

{% endtab %}
{% endtabs %}
