Repository: comic/grand-challenge.org

Issue:
Google logins broken with django-allauth 0.62+
# Recipe

- Open incognito window (just in case it matters)
- Navigate to grand-challenge.org
- Click Third party auth -> Google to login
 
![image](https://github.com/comic/grand-challenge.org/assets/11632379/c699412c-c522-4c78-a86b-df9ba27b66cb)

- Acknowledge that you are sent to a "third party" by clicking continue on the next page.

![image](https://github.com/comic/grand-challenge.org/assets/11632379/b361b622-4065-4fa8-ac7e-9c3ecf72b12e)

# Result

![image](https://github.com/comic/grand-challenge.org/assets/11632379/f830f3d0-b3d9-4408-a37a-9b62f82c185e)

> Unexpected Error

No login possible.

@amickan reported that no sentry errors are being recorded. I cannot login, presumably many other people cannot login either.



Discussion:
I suspect this is related to the upgrade of allauth, so pinned it as a speculative fix.
The exception appears to be:

```
24 April 2024 at 15:56 (UTC+2:00)	File "/opt/poetry/.venv/lib/python3.11/site-packages/django/urls/resolvers.py", line 828, in _reverse_with_prefix	web
24 April 2024 at 15:56 (UTC+2:00)	raise NoReverseMatch(msg)	web
24 April 2024 at 15:56 (UTC+2:00)	django.urls.exceptions.NoReverseMatch: Reverse for 'google_callback' not found. 'google_callback' is not a valid view function or pattern name.
```
In allauth the social account dependencies were separated out in 0.62.0 (https://github.com/pennersr/django-allauth/commit/8172ea9fba7d899323ab53069afb80c31fa9f3c3) but the backwards incompatibility notice was later moved to 0.60.1 (https://github.com/pennersr/django-allauth/commit/80088ce319b03a9df79f8a9d0cf49dad7ef50dc4). So, we upgraded thinking that we didn't have to do anything. 

Resolving patch:
diff --git a/app/grandchallenge/profiles/providers/gmail/provider.py b/app/grandchallenge/profiles/providers/gmail/provider.py
--- a/app/grandchallenge/profiles/providers/gmail/provider.py
+++ b/app/grandchallenge/profiles/providers/gmail/provider.py
@@ -1,9 +1,12 @@
 from allauth.socialaccount.providers.google.provider import GoogleProvider
 
+from grandchallenge.profiles.providers.gmail.views import GmailOAuth2Adapter
+
 
 class GmailProvider(GoogleProvider):
     id = "gmail"
     name = "Google"
+    oauth2_adapter_class = GmailOAuth2Adapter
 
     def extract_uid(self, data):
         return str(data["email"])
diff --git a/app/grandchallenge/profiles/providers/gmail/views.py b/app/grandchallenge/profiles/providers/gmail/views.py
--- a/app/grandchallenge/profiles/providers/gmail/views.py
+++ b/app/grandchallenge/profiles/providers/gmail/views.py
@@ -4,11 +4,9 @@
     OAuth2LoginView,
 )
 
-from grandchallenge.profiles.providers.gmail.provider import GmailProvider
-
 
 class GmailOAuth2Adapter(GoogleOAuth2Adapter):
-    provider_id = GmailProvider.id
+    provider_id = "gmail"
 
 
 oauth2_login = OAuth2LoginView.adapter_view(GmailOAuth2Adapter)


Test patch:
diff --git a/app/tests/core_tests/test_socialaccount.py b/app/tests/core_tests/test_socialaccount.py
new file mode 100644
--- /dev/null
+++ b/app/tests/core_tests/test_socialaccount.py
@@ -0,0 +1,13 @@
+import pytest
+
+
+@pytest.mark.django_db
+def test_gmail_login(client):
+    response = client.get("/accounts/gmail/login/")
+    assert response.status_code == 200
+
+    response = client.post("/accounts/gmail/login/")
+    assert response.status_code == 302
+    assert response.url.startswith(
+        "https://accounts.google.com/o/oauth2/v2/auth"
+    )