|
| 1 | +# GitHub Issue Context |
| 2 | + |
| 3 | +## Source |
| 4 | + |
| 5 | +- Repository: marciomyst/SmartMovieCatalog |
| 6 | +- Issue: #21 |
| 7 | +- URL: https://github.com/marciomyst/SmartMovieCatalog/issues/21 |
| 8 | +- State: OPEN |
| 9 | +- Created: 05/03/2026 00:59:57 |
| 10 | +- Updated: 05/03/2026 01:00:54 |
| 11 | +- Milestone: M1 — Core Movie Catalog |
| 12 | + |
| 13 | +## Title |
| 14 | + |
| 15 | +Backend authentication with JWT and current user context |
| 16 | + |
| 17 | +## Labels |
| 18 | + |
| 19 | +- type:feature |
| 20 | +- priority:high |
| 21 | +- area:api |
| 22 | +- area:backend |
| 23 | +- area:database |
| 24 | +- area:architecture |
| 25 | +- area:security |
| 26 | +- needs:adr |
| 27 | + |
| 28 | +## Assignees |
| 29 | + |
| 30 | +- marciomyst |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +## Issue Body |
| 35 | + |
| 36 | +## Descricao |
| 37 | +Implementar autenticacao backend no SmartMovieCatalog com `POST /api/auth/authenticate` e `GET /api/auth/me`, adaptando o desenho analisado em `MercaSafra` para a arquitetura Clean Architecture deste repositorio. |
| 38 | + |
| 39 | +O escopo e somente backend API. Nao incluir frontend Angular nesta issue. |
| 40 | + |
| 41 | +## Escopo Tecnico |
| 42 | +- Aceitar a estrategia de autenticacao em `docs/adr/0002-authentication-strategy.md`: autenticacao local com email/senha e JWT bearer. |
| 43 | +- Aceitar a estrategia de persistencia em `docs/adr/0003-database-strategy.md`: EF Core com PostgreSQL usando `ConnectionStrings:DefaultConnection`. |
| 44 | +- Definir/atualizar contrato de erro em `docs/adr/0004-api-error-contract.md`. |
| 45 | +- Adicionar entidade/aggregate de usuario no dominio, abstracoes de aplicacao e implementacoes de infraestrutura. |
| 46 | +- Configurar EF Core, migrations iniciais, hashing de senha, geracao JWT e leitura do usuario autenticado. |
| 47 | +- Configurar `AddAuthentication().AddJwtBearer(...)` e `UseAuthentication()` antes de `UseAuthorization()`. |
| 48 | + |
| 49 | +## API Contracts |
| 50 | +### `POST /api/auth/authenticate` |
| 51 | +Request: |
| 52 | +```json |
| 53 | +{ "email": "user@example.com", "password": "Password123!" } |
| 54 | +``` |
| 55 | + |
| 56 | +Responses: |
| 57 | +- `200 OK`: `{ userId, email, accessToken, accessTokenExpiresAtUtc }` |
| 58 | +- `400 Bad Request`: entrada invalida |
| 59 | +- `401 Unauthorized`: credenciais invalidas, usuario inexistente ou inativo |
| 60 | + |
| 61 | +### `GET /api/auth/me` |
| 62 | +Requer bearer token. |
| 63 | + |
| 64 | +Responses: |
| 65 | +- `200 OK`: `{ userId, email, name, roles, mustChangePasswordOnFirstLogin }` |
| 66 | +- `401 Unauthorized`: token ausente/invalido ou usuario inexistente/inativo |
| 67 | + |
| 68 | +## Fora De Escopo |
| 69 | +- Frontend login/session UI. |
| 70 | +- Refresh token. |
| 71 | +- Registro de usuario. |
| 72 | +- Recuperacao de senha. |
| 73 | +- Provedor externo de identidade. |
| 74 | +- Organizacoes/tenancy. |
| 75 | +- Autorizacao granular alem de roles basicas no token. |
| 76 | + |
| 77 | +## Documentacao |
| 78 | +Atualizar: |
| 79 | +- `docs/adr/0002-authentication-strategy.md` |
| 80 | +- `docs/adr/0003-database-strategy.md` |
| 81 | +- `docs/adr/0004-api-error-contract.md` |
| 82 | +- `docs/API.md` |
| 83 | +- `docs/SECURITY.md` |
| 84 | +- `README.md` |
| 85 | +- `backend/src/SmartMovieCatalog.Api/SmartMovieCatalog.Api.http` |
| 86 | + |
| 87 | +## Testes |
| 88 | +Application tests: |
| 89 | +- autenticacao valida retorna token; |
| 90 | +- senha invalida retorna falha nao autenticada; |
| 91 | +- usuario inexistente/inativo nao autentica; |
| 92 | +- contexto atual exige usuario autenticado; |
| 93 | +- contexto atual rejeita usuario removido/inativo. |
| 94 | + |
| 95 | +API tests: |
| 96 | +- `POST /api/auth/authenticate` cobre `200`, `400`, `401`; |
| 97 | +- `GET /api/auth/me` cobre `200` com token e `401` sem token. |
| 98 | + |
| 99 | +Verificacao final: |
| 100 | +- `dotnet build SmartMovieCatalog.slnx` |
| 101 | +- executar testes backend adicionados. |
| 102 | + |
| 103 | +## Assumptions |
| 104 | +- PostgreSQL e o provider escolhido porque ja existe em `docker-compose.yml`. |
| 105 | +- Segredos JWT ficam em environment variables ou user-secrets, nunca em arquivos versionados. |
| 106 | +- O scaffold `WeatherForecast` pode ser removido quando os endpoints reais forem introduzidos. |
| 107 | + |
| 108 | +## Comments |
| 109 | + |
| 110 | +_No comments_ |
| 111 | + |
| 112 | +## Instructions for Spec Kit |
| 113 | + |
| 114 | +Use this GitHub issue as the primary source of truth. |
| 115 | + |
| 116 | +Convert the issue into a Spec Kit feature specification before creating the implementation plan. |
| 117 | + |
| 118 | +Preserve: |
| 119 | + |
| 120 | +- business goal; |
| 121 | +- user stories; |
| 122 | +- acceptance criteria; |
| 123 | +- technical constraints; |
| 124 | +- non-goals; |
| 125 | +- dependencies; |
| 126 | +- open questions. |
| 127 | + |
| 128 | +If information is missing, add it under a clearly marked **Clarifications Needed** section instead of inventing requirements. |
| 129 | + |
| 130 | +If the issue conflicts with existing project documentation, explicitly call out the conflict. |
| 131 | + |
| 132 | +Prefer a small, incremental implementation plan aligned with the repository's existing architecture, folder structure, language, framework, and conventions. |
0 commit comments