Overview
Integra uses JSON Web Tokens (JWT) with RSA public/private key encryption for secure, stateless authentication. This approach ensures that:- No server-side session storage is required
- Tokens are cryptographically signed and cannot be forged
- Authentication scales horizontally across multiple server instances
- Tokens carry user identity and permissions for efficient authorization
Integra implements JWT authentication using the JJWT library (version 0.13.0) with RSA-256 signature algorithm.
Authentication Flow
Obtaining a Token
Login Endpoint
To authenticate and receive a JWT token, send a POST request to the login endpoint:Request Schema
Based onAccesoRequest.java:
| Field | Type | Required | Constraints | Description |
|---|---|---|---|---|
username | string | Yes | 3-50 characters | User’s login username |
password | string | Yes | 1-100 characters | User’s password |
Response Schema
Based onJWTResponse.java:
| Field | Type | Description |
|---|---|---|
token | string | JWT access token for authentication |
employeeName | object | Employee details associated with the authenticated user |
uiPermissions | string[] | List of permission identifiers for UI access control |
Store the
token securely on the client side. The token contains encoded user information and is cryptographically signed to prevent tampering.Using the Token
Authorization Header
Include the JWT token in theAuthorization header of all authenticated requests using the Bearer scheme:
Implementation Examples
Token Structure
JWT Claims
Integra’s JWT tokens contain the following claims (fromJwtUtil.java):
| Claim | Type | Description |
|---|---|---|
sub | string | Username (subject) |
id | integer | User account ID |
empleadoId | integer | Associated employee ID (if applicable) |
sup | boolean | Whether user is a supervisor |
authorities | string[] | List of role IDs (e.g., ["ROLE_1", "ROLE_2"]) |
ver | integer | Token version for invalidation support |
iat | timestamp | Issued at time |
exp | timestamp | Expiration time |
jti | string | Unique token ID (UUID) |
iss | string | Issuer (always "integra-auth-server") |
Token Validation
The server validates tokens using theJwtRequestFilter (from JwtRequestFilter.java):
- Extract Token: Reads the
Authorizationheader and extracts the Bearer token - Verify Signature: Validates the RSA signature using the public key
- Check Expiration: Ensures the token hasn’t expired
- Validate Version: Confirms the token version matches the current user version
- Load Permissions: Expands role IDs to their associated permissions
- Set Context: Establishes Spring Security authentication context
Token Expiration
Default Configuration
Fromapplication.yml:
- Access Token Expiration: 30 days (2,592,000 seconds)
- Refresh Token Expiration: 30 days (2,592,000 seconds)
Handling Expired Tokens
When a token expires, the API returns:401 Unauthorized
When you receive a 401 error due to token expiration, prompt the user to log in again. Integra currently uses long-lived tokens (30 days) to reduce re-authentication frequency.
Token Versioning & Invalidation
How It Works
Integra implements a token versioning system (fromJwtUtil.java lines 81-94) that allows for dynamic token invalidation:
- Each user has a version number stored in the database
- When a token is generated, it includes the current version in the
verclaim - On validation, the token’s version is compared to the current user version
- If the token version is less than the current version, it’s rejected
Use Cases for Version Invalidation
- Password Changed: Invalidate all existing tokens when a user changes their password
- Security Breach: Immediately revoke access by incrementing the user’s version
- Permission Changes: Force token refresh after role/permission updates
- Account Disabled: Prevent access even with a valid, non-expired token
Public Endpoints
The following endpoints do NOT require authentication (fromSecurityConfig.java):
Authentication Endpoints
Other Public Endpoints
Documentation & Monitoring
All other endpoints require a valid JWT token in the Authorization header.
Security Best Practices
Token Storage
HTTPS/TLS
Password Security
Integra uses BCrypt for password hashing (fromSecurityConfig.java):
- Passwords are never stored in plain text
- BCrypt automatically salts passwords
- Computational cost makes brute-force attacks impractical
Token Transmission
Key Management
Rate Limiting
Consider implementing rate limiting on authentication endpoints to prevent brute-force attacks:Error Responses
Invalid Credentials
401 Unauthorized
Missing Token
401 Unauthorized
Invalid Token Signature
401 Unauthorized
Deprecated Token Version
401 Unauthorized
Password Recovery Flow
Integra provides a self-service password recovery system:Next Steps
API Reference
Explore all available API endpoints
Employee Management
Learn how to manage employee records
Attendance Tracking
Understand attendance registration workflows
Role-Based Access
Configure roles and permissions