/ chat_workflow / auth.py
auth.py
1 from typing import Awaitable, Callable, Dict, Optional 2 3 from chainlit.config import config 4 from chainlit.oauth_providers import get_configured_oauth_providers 5 from chainlit.user import User 6 from chainlit.utils import wrap_user_function 7 8 9 def maybe_oauth_callback( 10 func: Callable[ 11 [str, str, Dict[str, str], User, Optional[str]], Awaitable[Optional[User]] 12 ], 13 ) -> Optional[Callable]: 14 """ 15 Framework agnostic decorator to authenticate the user via oauth 16 17 Args: 18 func (Callable[[str, str, Dict[str, str], User, Optional[str]], Awaitable[Optional[User]]]): The authentication callback to execute. 19 20 Example: 21 @cl.oauth_callback 22 async def oauth_callback(provider_id: str, token: str, raw_user_data: Dict[str, str], default_app_user: User, id_token: Optional[str]) -> Optional[User]: 23 24 Returns: 25 Optional[Callable[[str, str, Dict[str, str], User, Optional[str]], Awaitable[Optional[User]]]]: The decorated authentication callback. 26 """ 27 28 if len(get_configured_oauth_providers()) == 0: 29 return None 30 31 config.code.oauth_callback = wrap_user_function(func) 32 return func