""" Models for Microsoft authentication and Graph API operations. """ from pydantic import BaseModel, Field from typing import Optional, Dict, Any from datetime import datetime class MsftToken(BaseModel): """Model for Microsoft OAuth tokens""" access_token: str refresh_token: Optional[str] = None expires_in: int token_type: str = "bearer" expires_at: float user_info: Dict[str, Any] mandateId: str userId: str class MsftUserInfo(BaseModel): """Model for Microsoft user information""" id: str email: str name: str picture: Optional[str] = None # Microsoft Graph doesn't provide profile picture by default class MsftConfig(BaseModel): """Configuration for Microsoft authentication service""" client_id: str client_secret: str redirect_uri: str scopes: list[str] authority_url: str = "https://login.microsoftonline.com/common" token_url: str = "https://login.microsoftonline.com/common/oauth2/v2.0/token" user_info_url: str = "https://graph.microsoft.com/v1.0/me" # Get all attributes of the model def getModelAttributes(modelClass): return [attr for attr in dir(modelClass) if not callable(getattr(modelClass, attr)) and not attr.startswith('_') and attr not in ('metadata', 'query', 'query_class', 'label', 'field_labels')] class Label(BaseModel): """Label for an attribute or a class with support for multiple languages""" default: str translations: Dict[str, str] = {} def getLabel(self, language: str = None): """Returns the label in the specified language, or the default value if not available""" if language and language in self.translations: return self.translations[language] return self.default # Response models for Microsoft routes class MsftAuthStatus(BaseModel): """Response model for Microsoft authentication status""" authenticated: bool message: Optional[str] = None user: Optional[MsftUserInfo] = None class MsftTokenResponse(BaseModel): """Response model for Microsoft token""" token: MsftToken class MsftSaveTokenResponse(BaseModel): """Response model for saving Microsoft token""" success: bool message: str token: Optional[MsftToken] = None