I'm trying to integrate Google SSO into my Django app, but I keep running into an issue
I'm 99% sure it has to do with my custom authentication model, as shown below:
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth import get_user_model
from django.db.models import Q
UserModel = get_user_model()
class UsernameOrEmailBackend(ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
try:
user = UserModel.objects.get(Q(username__iexact=username) | Q(email__iexact=username))
except UserModel.DoesNotExist:
return None
else:
if user.check_password(password) and self.user_can_authenticate(user):
return user
return None
The goal was to allow users to sign in with a combination of email/username or password. But now, when i try to integrate Google SSO, it always redirects to the allauth signup page because Google doesn't provide a username.