from abc import ABC, abstractmethod
from typing import Optional
[docs]
class AuthProvider(ABC):
@abstractmethod
[docs]
def login(self) -> str:
"""Redirects to the login page of the provider."""
pass
@abstractmethod
[docs]
def logout(self) -> None:
"""Logs out the user."""
pass
@abstractmethod
[docs]
def get_user(self, token: dict) -> Optional[dict]:
"""Fetches the user profile using the provided token."""
pass
@abstractmethod
[docs]
def get_token(self) -> Optional[str]:
"""Gets the current user's access token."""
pass
@abstractmethod
[docs]
def handle_callback(self) -> Optional[str]:
"""
Handles the callback and exchanges the code for a token (implemented by the provider).
:return: Access token if successfully retrieved, else None
"""
pass
@abstractmethod
[docs]
def is_authenticated(self, token: str) -> bool:
"""Verifies if the user is authenticated using the token."""
pass