fix oauth
All checks were successful
Docker / build (release) Successful in 8s

This commit is contained in:
krek0 2026-05-16 19:53:43 +02:00
parent 1de1cb4086
commit 4b3a0a443d
8 changed files with 34 additions and 6 deletions

View file

@ -2,6 +2,7 @@
# Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from allauth.account.models import EmailAddress
from allauth.socialaccount.signals import pre_social_login
from django.dispatch import receiver
@ -19,6 +20,7 @@ def sync_user_fields(sender, request, sociallogin, **kwargs):
if email and user.email != email:
user.email = email
changed = True
EmailAddress.objects.filter(user=user).update(email=email)
username = data.get("username")
if username and user.username != username:

View file

@ -4,6 +4,7 @@
import requests
from allauth.socialaccount import app_settings
from django.core.exceptions import ImproperlyConfigured
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
@ -31,7 +32,12 @@ class OAuthAdapter(OAuth2Adapter):
@property
def domain(self):
return self.settings.get("DOMAIN", "")
domain = self.settings.get("DOMAIN", "")
if not domain:
raise ImproperlyConfigured(
"OAUTH_SERVER_URL is not configured. Set it in your .env file."
)
return domain
@property
def access_token_url(self):
@ -46,5 +52,7 @@ class OAuthAdapter(OAuth2Adapter):
return f"https://{self.domain}/api/me/"
OAuthProvider.oauth2_adapter_class = OAuthAdapter
oauth2_login = OAuth2LoginView.adapter_view(OAuthAdapter)
oauth2_callback = OAuth2CallbackView.adapter_view(OAuthAdapter)