All checks were successful
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 3m23s
- Introduced a dual-token system for user authentication: a short-lived access token and a long-lived rotating refresh token. - Created a new RefreshToken model to manage refresh tokens securely. - Updated auth_api.py to handle login, refresh, and logout processes with the new token system. - Enhanced security measures including token rotation and theft detection. - Updated frontend to handle token refresh on 401 errors and adjusted SSE authentication. - Removed CORS middleware as it's unnecessary behind the nginx proxy. - Added tests to ensure functionality and security of the new token system.
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from dataclasses import dataclass, field
|
|
from models.base import BaseModel
|
|
|
|
|
|
@dataclass(kw_only=True)
|
|
class RefreshToken(BaseModel):
|
|
user_id: str = ''
|
|
token_hash: str = ''
|
|
token_family: str = ''
|
|
expires_at: str = ''
|
|
is_used: bool = False
|
|
|
|
def to_dict(self):
|
|
return {
|
|
**super().to_dict(),
|
|
'user_id': self.user_id,
|
|
'token_hash': self.token_hash,
|
|
'token_family': self.token_family,
|
|
'expires_at': self.expires_at,
|
|
'is_used': self.is_used,
|
|
}
|
|
|
|
@staticmethod
|
|
def from_dict(data: dict) -> 'RefreshToken':
|
|
return RefreshToken(
|
|
id=data.get('id', ''),
|
|
created_at=data.get('created_at', 0),
|
|
updated_at=data.get('updated_at', 0),
|
|
user_id=data.get('user_id', ''),
|
|
token_hash=data.get('token_hash', ''),
|
|
token_family=data.get('token_family', ''),
|
|
expires_at=data.get('expires_at', ''),
|
|
is_used=data.get('is_used', False),
|
|
)
|