I’m trying to activate social logins in my Django web application, which comes from open source software in this GitHub repository
(so I didn’t write it); and am running into this well-known issue:
DoesNotExist: SocialApp matching query does not exist.
The base settings
file is located here
. I do not modify that file at all. Instead, I import
(inherit) it at the top of my deploy.py
settings
file, and make overrides and customization there.
Specifically related to this issue, here are the relevant overrides and additions that I made in deploy.py
to enable Google and Twitter social authentication, both of which result in the same error:
INSTALLED_APPS.remove('allauth.socialaccount.providers.persona') # Remove
INSTALLED_APPS.append('allauth.socialaccount.providers.google') # Add
INSTALLED_APPS.append('allauth.socialaccount.providers.twitter') # Add
_GOOGLE = {
'SCOPE': ['email', 'https://www.googleapis.com/auth/userinfo.profile'],
'AUTH_PARAMS': {'access_type': 'online'},
'PROVIDER_KEY': get_env("GOOGLE_PROVIDER_KEY"), # Stored in secrets.env
'PROVIDER_SECRET_KEY': get_env("GOOGLE_PROVIDER_SECRET_KEY"), # Stored in secrets.env
}
SOCIALACCOUNT_PROVIDERS['google'] = _GOOGLE # This isn't enabled in biostar.settings.base
_TWITTER = {
'SCOPE': ['email'],
'AUTH_PARAMS': {'access_type': 'online'},
'PROVIDER_KEY': get_env("TWITTER_PROVIDER_KEY"), # Stored in secrets.env
'PROVIDER_SECRET_KEY': get_env("TWITTER_PROVIDER_SECRET_KEY"), # Stored in secrets.env
}
SOCIALACCOUNT_PROVIDERS['twitter'] = _TWITTER
I show two provider examples here — Twitter and Google — to show the pattern of what I am doing, and to show that the issue isn’t provider-specific; though let’s try to focus on just Twitter to keep things simple.
Now according to this document
— which comes from a close fork of the above project — in addition to what I implemented above (programmatically), it is necessary to also set up the same Social Accounts and the Keys/Secret-keys for them in the Social Apps section of the Django Admin panel. (Note that that fork was worked on by more-or-less the same team; so this requirement likely applies to the original upstream implementation, as well). The relevant part of that document instructs the following:
After restoring, you need to re-enter social login info.
Unfortunately, even though this information is required to be in the config
environment that initializes biostar, it also requires it
(redundantly) to be in the database as well. So go to the Django Admin panel
and click on Social Apps and then go through each app and fill in the
appropriate values.
So I went ahead and did that, too.
No matter what I try (different providers, different keys, django panel additions, no django panel additions, etc), I get the aforementioned exception, as though I’m missing a step.
Incidentally, I tried both key-pairs for Twitter (because I always forget which pair to use; so tried both Consumer Key (API Key)
+ Consumer Secret (API Secret)
and Access Token
+ Access Token Secret
, though it’s really the former from what I read online). Just mentioning this for completeness.
What am I missing? Any ideas?
Thank you in advance! 🙂
EDIT-1: Here is a full paste of the exception: https://pastebin.com/0UBAfAtu
3
Answers
I was getting the same error again and again and solve with this ..
The reason we get this error SITE_ID = 1
When “SocialApp matching query does not exist” occurs,
hope for anyone else facing this issue will get help for this.
Following below steps will resolve this issue:
django_site
.SITE_ID
to id number in setting.py of the Django project.I had a similar problem and as people have said, you need to know the SITE_ID!
You have to make sure that on the Django admin dashboard, you have added your social application under SOCIAL ACCOUNTS.
When you’re creating the social application, make sure that have listed the right websites for "chosen sites". If you’re on local development, paste your computer IP in there. There will be a new SITE_ID associated with each "Chosen site" that you add to your application. Make sure you’re using the right one that’s associated to your IP. Personally, after adding my IP, I then just played and incremented my SITE_ID variable until it worked.
Posting this in case someone in a similar situation in the future lands on this page.