52 lines
No EOL
1.5 KiB
Python
52 lines
No EOL
1.5 KiB
Python
"""
|
|
Token models and management for external authentication services.
|
|
"""
|
|
|
|
from pydantic import BaseModel
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
|
|
class GoogleToken(BaseModel):
|
|
"""Google OAuth token model"""
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
expires_at: float
|
|
refresh_token: Optional[str] = None
|
|
|
|
class MsftToken(BaseModel):
|
|
"""Microsoft OAuth token model"""
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
expires_at: float
|
|
refresh_token: Optional[str] = None
|
|
|
|
class LocalToken(BaseModel):
|
|
"""Local authentication token model"""
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
expires_at: float
|
|
|
|
# Token management functions
|
|
def saveToken(interface, tokenType: str, tokenData: dict) -> bool:
|
|
"""Save token data for a specific service"""
|
|
try:
|
|
return interface.saveToken(f"tokens{tokenType}", tokenData)
|
|
except Exception as e:
|
|
logger.error(f"Error saving {tokenType} token: {str(e)}")
|
|
return False
|
|
|
|
def getToken(interface, tokenType: str) -> Optional[dict]:
|
|
"""Get token data for a specific service"""
|
|
try:
|
|
return interface.getToken(f"tokens{tokenType}")
|
|
except Exception as e:
|
|
logger.error(f"Error getting {tokenType} token: {str(e)}")
|
|
return None
|
|
|
|
def deleteToken(interface, tokenType: str) -> bool:
|
|
"""Delete token data for a specific service"""
|
|
try:
|
|
return interface.deleteToken(f"tokens{tokenType}")
|
|
except Exception as e:
|
|
logger.error(f"Error deleting {tokenType} token: {str(e)}")
|
|
return False |