django-allauth icon indicating copy to clipboard operation
django-allauth copied to clipboard

Third party app button "Install now" redirects directly to callback which causes errors - is there a solution?

Open futilestudio opened this issue 3 years ago • 1 comments

Hello,

I'm using a custom provider Pipedrive. The application is publicly accessible in the Pipedrive marketplace and they automatically generate "Install now" button that redirects user to this URL:

.../accounts/pipedrive/login/callback/?code=<SOME_CODE>

By clicking on "Install now" users should register/authenticate themselves on my website but allauth shows an error:

Social Network Login Failure
An error occurred while attempting to log in via your social network account.

I realized it's because there is no socialaccount_state entry in the request.session. Is it possible to make this work somehow or do users always have to access login page before?

The error happens here (no matter if supports_state is True/False as both cases expect socialaccount_state in the request.session):

    if self.adapter.supports_state:
        login.state = SocialLogin.verify_and_unstash_state(
            request, get_request_param(request, "state")
        )
    else:
        login.state = SocialLogin.unstash_state(request)

Thanks

futilestudio avatar Apr 21 '22 13:04 futilestudio

What about setting supports_state=False and then in your providers complete_login, add to the request.session['socialaccount_state'] = ({}, False).

It pops the tuple off here

and then state (the empty dict) gets used here

iarp avatar May 05 '22 13:05 iarp

Closing, not an issue in allauth but in a custom provider.

pennersr avatar Jun 19 '23 20:06 pennersr