---
title: Autenticação
description: Bearer token para o Painel e OAuth 2.0 PKCE para agentes de IA via MCP.
---

# Autenticação

O Argos tem dois mecanismos de autenticação dependendo do cliente:

| Canal | Método | Quando usar |
|-------|--------|-------------|
| Painel (humano) | **Bearer token opaco** via `POST /api/v1/auth/login` | Integrações diretas à API REST |
| MCP (agente de IA) | **OAuth 2.0 Authorization Code + PKCE** (RFC 7636) | Cursor, Claude Code, agentes remotos |

---

## Bearer Token (API REST)

### 1. Obter o token

O endpoint aceita `application/x-www-form-urlencoded` com os campos `username` e `password`
(padrão OAuth2 Password Form). JSON body retorna 422.

```bash
curl -X POST https://argos.automatizase.com.br/api/v1/auth/login \
  -d 'username=voce@empresa.com&password=SUA_SENHA'
```

Resposta:

```json
{
  "access_token": "tok_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "token_type": "bearer"
}
```

### 2. Usar o token

Passe o token em todas as requisições:

```bash
# Listar câmeras
curl https://argos.automatizase.com.br/api/v1/cameras \
  -H "Authorization: Bearer tok_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
```

```js
// JavaScript / TypeScript
const resp = await fetch('https://argos.automatizase.com.br/api/v1/cameras', {
  headers: { Authorization: `Bearer ${token}` },
});
const cameras = await resp.json();
```

```python
# Python
import httpx

client = httpx.Client(
    base_url='https://argos.automatizase.com.br',
    headers={'Authorization': f'Bearer {token}'},
)
cameras = client.get('/api/v1/cameras').json()
```

### 3. Capacidades por papel

O token carrega o papel do usuário. Todas as operações são escopadas automaticamente:

- **Administrador da conta**: gerencia a organização inteira — câmeras, usuários, gravadores,
  canais de notificação, calibração e configurações.
- **Usuário**: visualiza apenas câmeras e alertas da própria organização (somente leitura).

### 4. Logout

```bash
curl https://argos.automatizase.com.br/api/v1/auth/logout \
  -H "Authorization: Bearer $TOKEN"
```

---

## OAuth 2.0 + PKCE (MCP para agentes de IA)

Para agentes de IA (Claude Code, Cursor, n8n) autenticarem via MCP, use o fluxo
OAuth 2.0 Authorization Code com PKCE.

### Discovery automático

A maioria dos clientes OAuth descobre o servidor automaticamente:

```
GET https://argos.automatizase.com.br/.well-known/oauth-authorization-server
```

### Fluxo manual (step-by-step)

#### 1. Registrar cliente (DCR)

```bash
curl -X POST https://argos.automatizase.com.br/oauth/register \
  -H "Content-Type: application/json" \
  -d '{
    "client_name": "Meu Agente",
    "redirect_uris": ["http://localhost:8080/callback"]
  }'
```

Resposta: `{ "client_id": "...", "client_secret": "..." }`

#### 2. Gerar PKCE

```python
import secrets, hashlib, base64

code_verifier = secrets.token_urlsafe(64)
code_challenge = base64.urlsafe_b64encode(
    hashlib.sha256(code_verifier.encode()).digest()
).rstrip(b'=').decode()
```

#### 3. Redirecionar para autorização

```
GET https://argos.automatizase.com.br/oauth/authorize
  ?response_type=code
  &client_id=CLIENT_ID
  &redirect_uri=http://localhost:8080/callback
  &code_challenge=CODE_CHALLENGE
  &code_challenge_method=S256
  &scope=openid
```

#### 4. Trocar código por JWT

```bash
curl -X POST https://argos.automatizase.com.br/oauth/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=authorization_code&code=CODE&redirect_uri=...&code_verifier=CODE_VERIFIER&client_id=CLIENT_ID"
```

#### 5. Chamar o MCP

```bash
curl https://argos.automatizase.com.br/mcp \
  -H "Authorization: Bearer JWT_TOKEN"
```

---

## Próximos passos

- **[Quickstart](/docs/guias/quickstart)** — ver exemplos completos de chamada à API.
- **[Usando com agentes de IA](/docs/guias/agentes)** — conectar Claude Code e Cursor via MCP.
