Features
Authentication
Overview
Arches provides a comprehensive authentication system built on modern security standards with JWT tokens, session management, and role-based access control.
Core Features
JWT Authentication
- Token Generation: Secure JWT tokens with configurable expiration
- Refresh Tokens: Automatic token refresh for seamless user experience
- Token Validation: Middleware-based validation on all protected routes
- Revocation: Support for token blacklisting and immediate invalidation
Session Management
- Redis-Backed Sessions: High-performance session storage
- Session Persistence: Configurable session timeout and persistence
- Multi-Device Support: Users can maintain sessions across multiple devices
- Session Monitoring: Track active sessions and last activity
OAuth Integration
- Multiple Providers: Support for Google, GitHub, Microsoft, and custom OAuth2 providers
- Single Sign-On: Seamless SSO experience for enterprise deployments
- Account Linking: Link multiple OAuth providers to a single account
- Custom Scopes: Configure OAuth scopes per provider
Implementation
Authentication Flow
Code
Middleware Configuration
Code
Password Management
- Bcrypt Hashing: Industry-standard password hashing
- Password Policies: Configurable complexity requirements
- Reset Flow: Secure password reset via email tokens
- Password History: Prevent reuse of recent passwords
Security Features
Rate Limiting
- Login attempt throttling
- IP-based rate limiting
- Distributed rate limiting with Redis
Two-Factor Authentication
- TOTP support (Google Authenticator compatible)
- Backup codes for recovery
- SMS authentication (optional)
Security Headers
- CSRF protection
- XSS prevention
- Content Security Policy
- HSTS enforcement
Role-Based Access Control
Roles and Permissions
Code
Organization-Level Roles
- Owner: Full organization control
- Admin: Member management and settings
- Member: Standard access to resources
- Guest: Read-only access
API Endpoints
Authentication
POST /api/v1/auth/login
- User loginPOST /api/v1/auth/logout
- User logoutPOST /api/v1/auth/refresh
- Refresh access tokenPOST /api/v1/auth/register
- New user registrationPOST /api/v1/auth/verify-email
- Email verificationPOST /api/v1/auth/reset-password
- Password reset requestPOST /api/v1/auth/reset-password/confirm
- Confirm password reset
User Management
GET /api/v1/users/me
- Get current userPUT /api/v1/users/me
- Update current userDELETE /api/v1/users/me
- Delete accountGET /api/v1/users/me/sessions
- List active sessionsDELETE /api/v1/users/me/sessions/:id
- Revoke session
Configuration
Environment Variables
Code
Testing
Unit Tests
Code
Integration Tests
Code
Security Testing
- Automated penetration testing with OWASP ZAP
- JWT token validation tests
- Session hijacking prevention tests
- SQL injection prevention tests
Best Practices
Secure Defaults
- Passwords require minimum 12 characters
- Sessions expire after 24 hours of inactivity
- Failed login attempts trigger exponential backoff
- All tokens are cryptographically signed
Monitoring
- Track failed login attempts
- Monitor unusual session patterns
- Alert on privilege escalation attempts
- Log all authentication events
Compliance
- GDPR-compliant data handling
- SOC 2 audit logging
- HIPAA-ready encryption
- PCI DSS password standards
Migration Guide
From v1 to v2
- Update JWT library to latest version
- Migrate session storage from memory to Redis
- Update password hashing from SHA-256 to bcrypt
- Implement new RBAC system
Database Schema
Code
Troubleshooting
Common Issues
Invalid JWT Token
- Verify JWT_SECRET is correctly set
- Check token expiration time
- Ensure clock synchronization between servers
Session Not Persisting
- Verify Redis connection
- Check session cookie settings
- Ensure CORS configuration allows credentials
OAuth Login Failing
- Verify redirect URLs in provider configuration
- Check client ID and secret
- Ensure callback URL is whitelisted
Related Documentation
- Deployment Guide - Production deployment
Last modified on