Make database, oauth, smtp server, mail verificaiton configurable in .env

This commit is contained in:
krek0 2026-05-02 14:18:02 +02:00
parent 9b5fe1627d
commit 712d9a843e
8 changed files with 109 additions and 31 deletions

50
allauth_oauth/views.py Normal file
View file

@ -0,0 +1,50 @@
# From https://gitlab.crans.org/bde/allauth-note-kfet
# Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
import requests
from allauth.socialaccount import app_settings
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import OAuthProvider
class OAuthAdapter(OAuth2Adapter):
provider_id = OAuthProvider.id
def complete_login(self, request, app, token, **kwargs):
headers = {
"Authorization": f"Bearer {token.token}",
"Content-Type": "application/json",
}
extra_data = requests.get(self.profile_url, headers=headers)
return self.get_provider().sociallogin_from_response(request, extra_data.json())
@property
def settings(self):
return app_settings.PROVIDERS.get(self.provider_id, {})
@property
def domain(self):
return self.settings.get("DOMAIN", "")
@property
def access_token_url(self):
return f"https://{self.domain}/o/token/"
@property
def authorize_url(self):
return f"https://{self.domain}/o/authorize/"
@property
def profile_url(self):
return f"https://{self.domain}/api/me/"
oauth2_login = OAuth2LoginView.adapter_view(OAuthAdapter)
oauth2_callback = OAuth2CallbackView.adapter_view(OAuthAdapter)