Repository: pennersr/django-allauth
Pull request #3445 (2023-09-22 18:59:46)

docs(openid): refactor structures
per conversation in #3165 switch from `dict()` to `{}` for structures

# Submitting Pull Requests

## General

 - [x] Make sure you use [semantic commit messages](https://seesparkbox.com/foundry/semantic_commit_messages).
       Examples: `"fix(google): Fixed foobar bug"`, `"feat(accounts): Added foobar feature"`.
 - [ ] All Python code must formatted using Black, and clean from pep8 and isort issues.
 - [ ] JavaScript code should adhere to [StandardJS](https://standardjs.com).
 - [ ] If your changes are significant, please update `ChangeLog.rst`.
 - [ ] If your change is substantial, feel free to add yourself to `AUTHORS`.

 ## Provider Specifics

 In case you add a new provider:

- [ ] Make sure unit tests are available.
- [ ] Add an entry of your provider in `test_settings.py::INSTALLED_APPS` and `docs/installation.rst::INSTALLED_APPS`.
- [ ] Add documentation to `docs/providers/<provider name>.rst` and `docs/providers/index.rst` Provider Specifics toctree.
- [ ] Add an entry to the list of supported providers over at `docs/overview.rst`.



Patch:
diff --git a/allauth/socialaccount/models.py b/allauth/socialaccount/models.py
index 0775db9a..5e07f9a7 100644
--- a/allauth/socialaccount/models.py
+++ b/allauth/socialaccount/models.py
@@ -276,15 +276,18 @@ class SocialLogin(object):
         """When `False`, this social login represents a temporary account, not
         yet backed by a database record.
         """
-        return self.user.pk is not None
+        if self.user.pk is None:
+            return False
+        return get_user_model().objects.filter(pk=self.user.pk).exists()
 
     def lookup(self):
         """Look up the existing local user account to which this social login
         points, if any.
         """
         if not self._lookup_by_socialaccount():
+            provider_id = self.account.get_provider().id
             if app_settings.EMAIL_AUTHENTICATION or app_settings.PROVIDERS.get(
-                self.account.provider, {}
+                provider_id, {}
             ).get("EMAIL_AUTHENTICATION", False):
                 self._lookup_by_email()
 
diff --git a/docs/socialaccount/providers/openid.rst b/docs/socialaccount/providers/openid.rst
index df85b79f..943e8b7a 100644
--- a/docs/socialaccount/providers/openid.rst
+++ b/docs/socialaccount/providers/openid.rst
@@ -12,15 +12,21 @@ builtin templates can be configured as follows:
     SOCIALACCOUNT_PROVIDERS = {
         'openid': {
             'SERVERS': [
-                dict(id='yahoo',
-                     name='Yahoo',
-                     openid_url='http://me.yahoo.com'),
-                dict(id='hyves',
-                     name='Hyves',
-                     openid_url='http://hyves.nl'),
-                dict(id='google',
-                     name='Google',
-                     openid_url='https://www.google.com/accounts/o8/id'),
+                {
+                    'id': 'yahoo',
+                    'name': 'Yahoo',
+                    'openid_url': 'http://me.yahoo.com',
+                },
+                {
+                    'id': 'hyves',
+                    'name': 'Hyves',
+                    'openid_url': 'http://hyves.nl',
+                },
+                {
+                    'id': 'google',
+                    'name': 'Google',
+                    'openid_url': 'https://www.google.com/accounts/o8/id',
+                },
             ]
         }
     }
@@ -30,13 +36,19 @@ You can manually specify extra_data you want to request from server as follows::
     SOCIALACCOUNT_PROVIDERS = \
         { 'openid':
             { 'SERVERS':
-                 [ dict(id='mojeid',
-                      name='MojeId',
-                      openid_url='https://mojeid.cz/endpoint/',
-                      extra_attributes = [
-                          ('phone', 'http://axschema.org/contact/phone/default', False),
-                          ('birth_date', 'http://axschema.org/birthDate', False,),
-                      ])]}}
+                [
+                    {
+                        'id': 'mojeid',
+                        'name': 'MojeId',
+                        'openid_url': 'https://mojeid.cz/endpoint/',
+                        'extra_attributes': [
+                            ('phone', ''http://axschema.org/contact/phone/default', False),
+                            ('birth_date', 'http://axschema.org/birthDate', False),
+                        ]
+                    },
+                ]
+            }
+        }
 
 Attributes are in form (id, name, required) where id is key in extra_data field of socialaccount,
 name is identifier of requested attribute and required specifies whether attribute is required.
@@ -54,8 +66,13 @@ The OpenID provider can be forced to operate in stateless mode as follows::
     SOCIALACCOUNT_PROVIDERS = \
         { 'openid':
             { 'SERVERS':
-                [ dict(id='steam',
-                    name='Steam',
-                    openid_url='https://steamcommunity.com/openid',
-                    stateless=True,
-                )]}}
+                [
+                    {
+                        'id': 'steam',
+                        'name': 'Steam',
+                        'openid_url': 'https://steamcommunity.com/openid',
+                        'stateless': True,
+                    },
+                ]
+            }
+        }


Test patch:
diff --git a/allauth/socialaccount/tests/test_login.py b/allauth/socialaccount/tests/test_login.py
index 7acb173f..70bdc3ad 100644
--- a/allauth/socialaccount/tests/test_login.py
+++ b/allauth/socialaccount/tests/test_login.py
@@ -1,3 +1,4 @@
+import copy
 from unittest.mock import patch
 
 from django.contrib.auth.models import AnonymousUser
@@ -37,14 +38,19 @@ def test_email_authentication(
     if setting == "on-global":
         settings.SOCIALACCOUNT_EMAIL_AUTHENTICATION = True
     elif setting == "on-provider":
-        settings.SOCIALACCOUNT_PROVIDERS["google"] = {"EMAIL_AUTHENTICATION": True}
+        settings.SOCIALACCOUNT_PROVIDERS = copy.deepcopy(
+            settings.SOCIALACCOUNT_PROVIDERS
+        )
+        settings.SOCIALACCOUNT_PROVIDERS["openid_connect"][
+            "EMAIL_AUTHENTICATION"
+        ] = True
     else:
         settings.SOCIALACCOUNT_EMAIL_AUTHENTICATION = False
     settings.SOCIALACCOUNT_EMAIL_AUTHENTICATION_AUTO_CONNECT = auto_connect
 
     user = user_factory()
 
-    sociallogin = sociallogin_factory(email=user.email, provider="google")
+    sociallogin = sociallogin_factory(email=user.email, provider="unittest-server")
 
     request = rf.get("/")
     SessionMiddleware(lambda request: None).process_request(request)