docs: atualiza README com novos endpoints auth e exemplos
This commit is contained in:
51
README.md
51
README.md
@@ -4,7 +4,7 @@ MVP de autenticação central para serviços distribuídos.
|
|||||||
|
|
||||||
## O que este projeto entrega
|
## O que este projeto entrega
|
||||||
|
|
||||||
- Auth Service com `login` e `refresh`
|
- Auth Service com `register`, `login`, `refresh` e recuperação de senha
|
||||||
- JWT assinado em `RS256` com contrato fixo
|
- JWT assinado em `RS256` com contrato fixo
|
||||||
- Middleware de validação JWT local
|
- Middleware de validação JWT local
|
||||||
- Serviço consumidor de referência (`/profile/me`)
|
- Serviço consumidor de referência (`/profile/me`)
|
||||||
@@ -73,6 +73,9 @@ A tabela `User` possui apenas:
|
|||||||
|
|
||||||
- `POST /auth/login`
|
- `POST /auth/login`
|
||||||
- `POST /auth/refresh`
|
- `POST /auth/refresh`
|
||||||
|
- `POST /auth/register`
|
||||||
|
- `POST /auth/forgot-password`
|
||||||
|
- `POST /auth/reset-password`
|
||||||
- `GET /profile/me` (protegida)
|
- `GET /profile/me` (protegida)
|
||||||
- `GET /dashboard` (protegida, chama `/profile/me`)
|
- `GET /dashboard` (protegida, chama `/profile/me`)
|
||||||
|
|
||||||
@@ -94,29 +97,65 @@ A identidade confiável do usuário é sempre o `sub`.
|
|||||||
|
|
||||||
## Teste rápido (curl)
|
## Teste rápido (curl)
|
||||||
|
|
||||||
### 1) Login
|
### 1) Cadastro
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:3000/auth/register \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{"email":"novo.usuario@example.com","password":"senha123"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
Fluxo recomendado no cliente: `register -> login`.
|
||||||
|
|
||||||
|
### 2) Login
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -X POST http://localhost:3000/auth/login \
|
curl -X POST http://localhost:3000/auth/login \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
-d '{"email":"student@example.com","password":"student123"}'
|
-d '{"email":"novo.usuario@example.com","password":"senha123"}'
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2) Rota protegida
|
### 3) Forgot password (sem SMTP, modo didático)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:3000/auth/forgot-password \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{"email":"novo.usuario@example.com"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
Observação: neste MVP didático a resposta já traz `recovery.reset_token` e `recovery.reset_url`.
|
||||||
|
|
||||||
|
### 4) Reset password
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:3000/auth/reset-password \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{"token":"<reset_token>","new_password":"novaSenha123"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5) Login com nova senha
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:3000/auth/login \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{"email":"novo.usuario@example.com","password":"novaSenha123"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6) Rota protegida
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl http://localhost:3000/profile/me \
|
curl http://localhost:3000/profile/me \
|
||||||
-H "Authorization: Bearer <access_token>"
|
-H "Authorization: Bearer <access_token>"
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3) Chamada entre serviços (A -> B)
|
### 7) Chamada entre serviços (A -> B)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl http://localhost:3000/dashboard \
|
curl http://localhost:3000/dashboard \
|
||||||
-H "Authorization: Bearer <access_token>"
|
-H "Authorization: Bearer <access_token>"
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4) Refresh
|
### 8) Refresh
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -X POST http://localhost:3000/auth/refresh \
|
curl -X POST http://localhost:3000/auth/refresh \
|
||||||
|
|||||||
Reference in New Issue
Block a user