from authlib.integrations.django_client import OAuth
from django.conf import settings

# # https://docs.authlib.org/en/latest/client/frameworks.html#frameworks-clients
# def fetch_token(_name, request):
#     try:
#         token = OAuth2Token.objects.get(
#             user=request.user
#         )
#         return token.to_token()
#     except (OAuth2Token.DoesNotExist, TypeError):
#         return None


# oauth = OAuth(fetch_token=fetch_token)
oauth = OAuth()
oauth.register(
    name=settings.OAUTH["client_name"],
    client_id=settings.OAUTH["client_id"],
    client_secret=settings.OAUTH["client_secret"],
    request_token_url=None,
    request_token_params=None,
    access_token_url=settings.OAUTH["access_token_url"],
    access_token_params=None,
    authorize_url=settings.OAUTH["authorize_url"],
    authorize_params=None,
    api_base_url=settings.OAUTH["api_base_url"],
    client_kwargs=settings.OAUTH["client_kwargs"]
)
