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

It should be easier to pass along custom state with OAuth2

Open jarshwah opened this issue 5 years ago • 2 comments

I'm in need of customising the state parameter that gets passed along to the OAuth2 provider, and I'm finding it incredibly difficult to do so. It would be amazing if the Adapater had a hook for customising the state object before it was added onto the redirect url.

My use case:

We have dynamic environments (staging, local), with dynamic URLs. It's impractical to register all of these URLs as redirect targets within each of the OAuth2 providers we support. To work around this, we have a proxy service that acts as the redirect target.

Site -> OAuthProvider -> Redirect Service -> Site

The Redirect Service pops some state off the URL to determine the final redirect. Adding this state is proving very difficult.

For what it's worth, we configure the state like so:

state = {target_domain}|{state}

jarshwah avatar May 28 '20 04:05 jarshwah

Bumping this for @pennersr. Seems valid but i'm not sure if there is an opportunity to directly support his dynamic env use case... or if this has already been addressed.

derek-adair avatar Aug 31 '23 13:08 derek-adair

I also anticipate needing this. Has anyone found a workaround that's less complex than having an entire proxy service?

norchai avatar Dec 12 '23 18:12 norchai

@jarshwah @norchai A change landed on the main branch facilitating this, see: ce038b7a. The adapter now has a generate_state_param() method that you can override.

pennersr avatar Apr 20 '24 08:04 pennersr

Documentation can be found here: https://docs.allauth.org/en/dev/socialaccount/adapter.html#allauth.socialaccount.adapter.DefaultSocialAccountAdapter.generate_state_param

pennersr avatar Apr 20 '24 09:04 pennersr