Add improvements
This commit is contained in:
@@ -239,24 +239,26 @@ class SecurityManager:
|
||||
return hashlib.sha256(data.encode()).hexdigest()
|
||||
|
||||
@staticmethod
|
||||
def create_service_token(service_name: str) -> str:
|
||||
def create_service_token(service_name: str, tenant_id: Optional[str] = None) -> str:
|
||||
"""
|
||||
Create JWT service token for inter-service communication
|
||||
✅ FIXED: Proper service token creation with JWT
|
||||
✅ UNIFIED: Uses shared JWT handler for consistent token creation
|
||||
✅ ENHANCED: Supports tenant context for tenant-scoped operations
|
||||
|
||||
Args:
|
||||
service_name: Name of the service (e.g., 'auth-service', 'tenant-service')
|
||||
tenant_id: Optional tenant ID for tenant-scoped service operations
|
||||
|
||||
Returns:
|
||||
Encoded JWT service token
|
||||
"""
|
||||
try:
|
||||
# Create service token payload
|
||||
payload = {
|
||||
"sub": service_name,
|
||||
"service": service_name,
|
||||
"type": "service",
|
||||
"role": "admin",
|
||||
"is_service": True
|
||||
}
|
||||
|
||||
# Use JWT handler to create service token
|
||||
token = jwt_handler.create_service_token(service_name)
|
||||
logger.debug(f"Created service token for {service_name}")
|
||||
# Use unified JWT handler to create service token
|
||||
token = jwt_handler.create_service_token(
|
||||
service_name=service_name,
|
||||
tenant_id=tenant_id
|
||||
)
|
||||
logger.debug(f"Created service token for {service_name}", tenant_id=tenant_id)
|
||||
return token
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user