Source code for mdvtools.auth.auth_provider
from abc import ABC, abstractmethod
# from flask import Response
from flask.typing import ResponseReturnValue
from typing import Optional, Tuple
[docs]
class AuthProvider(ABC):
@abstractmethod
[docs]
def login(self) -> ResponseReturnValue:
"""Redirects to the login page of the provider."""
pass
@abstractmethod
[docs]
def logout(self) -> ResponseReturnValue:
"""Logs out the user."""
pass
@abstractmethod
[docs]
def get_user(self, token: Optional[dict] = None) -> 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 validate_user(self) -> Tuple[Optional[dict], Optional[Tuple]]:
"""Validates and returns user data."""
pass
@abstractmethod
[docs]
def sync_users_to_db(self):
""" Syncs users from the authentication provider (e.g., Auth0) to the application's database."""
pass