Authentication
Overview
The Rhesis backend implements a comprehensive authentication system using Auth0 as the identity provider. The system supports both session-based authentication for web UI users and token-based authentication for API access.
Authentication Methods
Session-Based Authentication
Session-based authentication is used for web UI users:
- User is redirected to Auth0 login page
- After successful authentication, Auth0 redirects back to the application
- A session is created and maintained using cookies
- Session middleware manages the user’s session state
Token-Based Authentication
Token-based authentication is used for API access:
- Client obtains a JWT token (either from Auth0 or through the
/tokens/endpoint) - Client includes the token in the
Authorizationheader with each request - The backend validates the token and extracts user information
Auth0 Integration
The application integrates with Auth0 for identity management:
Login Flow
- User accesses
/auth/login - Backend redirects to Auth0 authorization URL
- User authenticates with Auth0
- Auth0 redirects back to
/auth/callbackwith an authorization code - Backend exchanges the code for tokens
- User information is stored in the session
Authentication Middleware
The application uses a custom route class to enforce authentication requirements:
Authentication Dependencies
The application defines several authentication dependencies:
require_current_user
Requires a valid user session:
require_current_user_or_token
Accepts either a valid user session or a valid token:
JWT Tokens
The application uses JWT tokens for API authentication:
Token Generation
Token Validation
Logout
The logout process invalidates the user’s session:
Security Considerations
- HTTPS is enforced for all communications
- Tokens have a configurable expiration time
- Session data is encrypted using a secret key
- Auth0’s security features protect against common attacks
- CORS is configured to allow only specific origins