Skip to content

Newer version of dj-rest-auth causes OAuth2Client.__init__() got multiple values for argument 'scope_delimiter' error. #673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Farbod909 opened this issue Jan 5, 2025 · 5 comments

Comments

@Farbod909
Copy link

Hello,

I was setting up a new project with dj-rest-auth and for some reason I was running into JSONDecodeError at /auth/google/callback/. I set it up identically to a previous project but was still getting this error. When I changed my requirements.txt file from

dj-rest-auth==7.0.1
django-allauth==65.3.1

to

dj-rest-auth==7.0.0
django-allauth==0.61.1

everything started working again.

The JSONDecodeError is because the call to the google_login view is resulting in a Django error page in the form of HTML, not JSON. Looking into the HTML that the google_login view is responding with I was able to see that the root cause is TypeError
OAuth2Client.__init__() got multiple values for argument 'scope_delimiter', which is clearly not something that is affected by my implementation.

Please share the correct version numbers to use and also where the documentation may be adjusted to address this. Please let me know if you'd like any additional details, thanks!

@toniengelhardt
Copy link

I get the same error.

dj-rest-auth==7.0.1 doesn't seem to work with django-allauth. Tested versions v0.61, v64, and v65.

@patrickamstad
Copy link

Hi guys, I have the same issue. You can fix it by removing the scope argument (django-allauth no longer expects a scope argument for the constructor after version 0.62.0)

Screenshot 2025-01-05 at 18 19 56

I think the only way to fix this is to write your custom validate function, because down-grading to v0.61 will cause another issue.

Let me know if it is clear or you need additional info.
KR
Patrick

@pomali
Copy link
Contributor

pomali commented Jan 9, 2025

I hotfixed this by writing custom client

from allauth.socialaccount.providers.apple.client import AppleOAuth2Client


class CustomAppleOAuth2Client(AppleOAuth2Client):
    def __init__(
        self,
        request,
        consumer_key,
        consumer_secret,
        access_token_method,
        access_token_url,
        callback_url,
        _scope,  # This is fix for incompatibility between django-allauth==65.3.1 and dj-rest-auth==7.0.1
        scope_delimiter=" ",
        headers=None,
        basic_auth=False,
    ):
        super().__init__(
            request,
            consumer_key,
            consumer_secret,
            access_token_method,
            access_token_url,
            callback_url,
            scope_delimiter,
            headers,
            basic_auth,
        )

and using it in view

class AppleLogin(SocialLoginView):
     ...
    client_class = CustomAppleOAuth2Client

(not sure if this fixes everything, but it fixes got multiple values error)

@toniengelhardt
Copy link

I hotfixed this by writing custom client

from allauth.socialaccount.providers.apple.client import AppleOAuth2Client


class CustomAppleOAuth2Client(AppleOAuth2Client):
    def __init__(
        self,
        request,
        consumer_key,
        consumer_secret,
        access_token_method,
        access_token_url,
        callback_url,
        _scope,  # This is fix for incompatibility between django-allauth==65.3.1 and dj-rest-auth==7.0.1
        scope_delimiter=" ",
        headers=None,
        basic_auth=False,
    ):
        super().__init__(
            request,
            consumer_key,
            consumer_secret,
            access_token_method,
            access_token_url,
            callback_url,
            scope_delimiter,
            headers,
            basic_auth,
        )

and using it in view

class AppleLogin(SocialLoginView):
     ...
    client_class = CustomAppleOAuth2Client

(not sure if this fixes everything, but it fixes got multiple values error)

Thanks 🙏🏽

This seems to work from initial testing.

@patrickamstad
Copy link

in case someone is interested for gogole auth this would look as follows:

#inside views.py

from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter
from allauth.socialaccount.providers.oauth2.client import OAuth2Client
from dj_rest_auth.registration.views import SocialLoginView

class CustomGoogleOAuth2Client(OAuth2Client):
    def __init__(
        self,
        request,
        consumer_key,
        consumer_secret,
        access_token_method,
        access_token_url,
        callback_url,
        _scope,  # This is fix for incompatibility between django-allauth==65.3.1 and dj-rest-auth==7.0.1
        scope_delimiter=" ",
        headers=None,
        basic_auth=False,
    ):
        super().__init__(
            request,
            consumer_key,
            consumer_secret,
            access_token_method,
            access_token_url,
            callback_url,
            scope_delimiter,
            headers,
            basic_auth,
        )


class GoogleLogin(SocialLoginView): # if you want to use Authorization Code Grant, use this
    adapter_class = GoogleOAuth2Adapter
    callback_url = os.environ["GOOGLE_CALLBACK_URI"]
    client_class = CustomGoogleOAuth2Client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants