Repository navigation
feat(auth): implementar Device Fingerprinting e gestão de sessões ativas (#158) - #159
Merged
NdondaDaniel2020 merged 6 commits intoAug 30, 2026
Merged
Conversation
…e fingerprinting e sessoes
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 Descrição & Motivação
Esta Pull Request implementa Device Fingerprinting e Gestão Avançada de Sessões Ativas do Usuário, permitindo rastrear os dispositivos conectados (
device_name,ip_address,user_agent,last_seen_at) na emissão e renovação de refresh tokens, e disponibiliza endpoints REST para que o usuário visualize e encerre remotamente suas sessões em outros dispositivos.Closes #158
🛠️ O que foi feito?
1. Banco de Dados & Modelos (SQLAlchemy & Alembic)
ip_address,user_agent,device_name,locationelast_seen_atno modeloRefreshToken(app/models/refresh_token.py).nullable=Truepara garantir 100% de compatibilidade retroativa com tokens existentes.last_seen_atmantida sem índice para viabilizar atualizações em memória HOT (Heap-Only Tuples) no PostgreSQL sob alta concorrência.migrations/versions/12a7942e3290_add_device_fingerprinting_to_refresh_.py.2. Utilitário de Device Fingerprinting (
app/core/device.py)extract_client_ip(): Extração segura de IP priorizando headers de proxy reverso (X-Forwarded-For,X-Real-IP).parse_user_agent(): Parser determinístico e de alta performance em memória para identificar SO (macOS, iOS, Windows, Linux, Android) e Navegador (Chrome, Safari, Firefox, Edge, Opera, Postman, cURL).3. Repositório & Camada de Serviços
RefreshTokenRepository: Métodoscreate()com metadados,list_active_by_user(),revoke_by_jti_and_user()erevoke_other_sessions().app/services/session_service.py: Camada desacoplada para listagem, revogação unitária e revogação em massa das sessões do usuário.app/services/auth_service.py: Passagem de metadados emcreate_token_pair(),authenticate_mfa_challenge()e propagação de metadados norefresh_tokens().4. Endpoints REST de Usuário
GET /api/users/me/sessions: Retorna a lista de sessões ativas do usuário com metadados legíveis de dispositivo.DELETE /api/users/me/sessions/{jti}: Revoga remotamente uma sessão ativa específica.DELETE /api/users/me/sessions: Revoga todas as outras sessões ativas do usuário.📦 Commits Atômicos
🧪 Testes & Validação
tests/test_device_fingerprinting.py(4/4 passed).uv run pytest --ignore=tests/test_db_connection.py(447 passed).uv run ruff checkeuv run ruff format --check100% aprovados.