Hello,
I’m using django-allauth and google-auth to perform authentication using Google. I’ve followed a number of tutorials and am able to create entries in my auth_user table and in the socialaccount_socialaccount table.
Even though I’m able to login and authenticate without issues, and have checked to ensure that all the URL’s match in the Django settings relative to the settings in Google’s OAuth 2 Client configuration, the token information is still not saving to the socialaccount_socialtoken table.
Does anyone have suggestions on where to look? I’ve spent quite a bit of time trying to rebuild the socialtoken by other means, but I think that getting access to that specific token is what I need to move forward with some other things I want to do with the YouTube api.
Thanks in advance!
Did you set the SOCIALACCOUNT_STORE_TOKENS
to True
in your settings ? (See Configuration — django-allauth 0.61.1 documentation)
Thanks @antoinehumbert - I did set that to true. To check, I print out settings.SOCIALACCOUNT_STORE_TOKENS and that is set to true.
Any other suggestions?
Which version of django-allauth are you using ? Please, note that before version 0.56, this setting has no effect for apps configured in the settings rather than in database (see 0.61.1 (2024-02-09) — django-allauth 0.61.1 documentation)
Right now, i’m using 0.61.1. Been trying to track this down, and got to this point:
In site-packages/allauth/socialaccount/models.py, I put in some print statements and got out the following:
store_tokens: True
self.token: A_LARGE_STRING
self.token.app_id: None
Seems like app_id is not being set properly. I’m trying to track it down now and it might be related to some custom views I created for Google login …
def save(self, request, connect=False):
“”"
Saves a new account. Note that while the account is new,
the user may be an existing one (when connecting accounts)
“”"
assert not self.is_existing
user = self.user
user.save()
self.account.user = user
self.account.save()
print(self)
print("store_tokens:", app_settings.STORE_TOKENS)
print("self.token:", self.token)
print("self.token.app_id:", self.token.app_id)
if app_settings.STORE_TOKENS and self.token and self.token.app_id:
self.token.account = self.account
self.token.save()
if connect:
# TODO: Add any new email addresses automatically?
pass
else:
setup_user_email(request, user, self.email_addresses)
That’s it: if your app configuration is defined in settings and not in database, token.app_id will always be None and this is normal.
So remove the and self.token.app_id
from the if clause