Open shennnj opened 5 months ago
Seems like django-allauth update to 0.62.0 changes how get_scope
is implemented, will downgrade django-allauth to 0.61.1 at the moment to have dj-rest-auth work together.
def get_scope(self, request):
settings = self.get_settings()
scope = list(settings.get("SCOPE", self.get_default_scope()))
dynamic_scope = request.GET.get("scope", None)
if dynamic_scope:
scope.extend(dynamic_scope.split(","))
return scope
def get_scope(self):
"""
Returns the scope to use, taking settings `SCOPE` into consideration.
"""
settings = self.get_settings()
scope = list(settings.get("SCOPE", self.get_default_scope()))
return scope
def get_scope_from_request(self, request):
"""
Returns the scope to use for the given request.
"""
scope = self.get_scope()
dynamic_scope = request.GET.get("scope", None)
if dynamic_scope:
scope.extend(dynamic_scope.split(","))
return scope
My setup with django-allauth==0.61.1 and dj-rest-auth==5.0.2 was working fine for like months. Before a few days ago I started getting errors like the above and "allauth.socialaccount.providers.oauth2.client.OAuth2Error: Invalid id_token".
Check this reply by one of the main dev of allauth: https://github.com/iMerica/dj-rest-auth/issues/503#issuecomment-1932655997
Going back to django-allauth==0.57.1 solved my issues.
I came across this issue while using Github as a provider and @shennnj's solution worked for me.
However, while using dj-rest-auth
6.0.0 and django-allauth
0.63.2, I noticed that the client class in dj-rest-auth
is being instantiated with an extra scope
argument.
in the validate
method of SocialLoginSerializer
, the client is instantiated with an extra scope
argument.
This is not needed in the instantiation of a new client class
So to address this problem, I inherited SocialLoginSerializer
and removed the scope
argument
class CstmSocialLoginSerializer(SocialLoginSerializer):
def validate(self, attrs):
...
client = self.client_class(
request,
app.client_id,
app.secret,
adapter.access_token_method,
adapter.access_token_url,
self.callback_url,
scope_delimiter=adapter.scope_delimiter,
headers=adapter.headers,
basic_auth=adapter.basic_auth,
)
...
Then added the serializer to my GithubLoginView
class GitHubLogin(SocialLoginView):
adapter_class = GitHubOAuth2Adapter
callback_url = "..."
client_class = OAuth2Client
serializer_class = CstmSocialLoginSerializer
This solved my problem and I didn't get the error.
We are encountering this issue with Apple login despite it previously functioning correctly.
We are encountering this issue with Apple login despite it previously functioning correctly.
Downgrading to django-allauth to 0.61.1 Fixes the issue.
@YDA93 - could you share your dj_rest_auth version that works with django-allauth 0.61.1 for social auth via Apple?
@trackers153 Sure dj-rest-auth==6.0.0
Thanks vm, @YDA93
Not fixed in 7.0.0
? 😩
Getting this error when sending a post request to SocialLoginView. The body of post request contains "code" only. Having this problem on google/facebook/github login.
Similar problem also asked in https://stackoverflow.com/questions/78477908/dj-rest-auth-with-google-login-typeerror-oauth2provider-get-scope-takes-1-po
Did I do any mistake in setting this up?
The error: Happens during validation in
SocialLoginSerializer
view.py
url.py
views.py
Post request Post to
/auth/google/
with body of{ "code": "<code_received_after_user_authorize>" }