Trying to setup a Django 4.2 app with django-allauth for Twitter using OAuth2.
The user gets presented the Twitter Authorize page with the correct logo an account name but after the user clicks on the "Authorize App" button the following message is shown:
Details: unknown, Error: Error retrieving access token: b'{"error":"unauthorized_client","error_description":"Missing valid authorization header"}’
Any ideas on how to fix the Missing valid authorization header?
The package versions are:
django 4.2
django-allauth 0.54.0
The settings.py INSTALLED APPS
‘allauth.socialaccount.providers.twitter_oauth2’,
I think settings in the Twitter API are setup properly as this Twitter App is being used successfully for non-Django operations (collect, tweet, etc).
I’ve also double-checked the callback url which is the standard https://domain/accounts/twitter_oauth2/login/callback/
The Twitter docs
https://developer.twitter.com/en/docs/authentication/oauth-2-0/user-access-token
say for confidential clients (which this is, as it is a simple web app) the header should have Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
I think the error message from Twitter is saying the request does not have the Authorization: Basic info . And I do not know how to set this up.
Any help is appreciated.
Cheers, Kevin
2
Answers
I never solved the original problem from last year and ended up staying with Twitter OAuth1. But last week, I upgraded the system to Django 5.1 with django-allauth 64.0.0 and the twitter_oauth2 provider works with these scopes in the project settings.py
SOCIALACCOUNT_PROVIDERS = { # lots of other stuff chopped out...
}
Thanks to the people who helped with original question (it did help me get the Google OAuth2 working last year). Cheers, Kevin.
Did you see some special tokens? I didn’t work with Twitter auth—it died when I tryed to register my number—but when you add auth with Google you need to add special tokens in
settings.py
:They lie in the place with name
~crediatials
or "APIs & services" (for Google).Also, you can try to add this special token in
Authorization
.