'Django Allauth and Salesforce: No_Oauth_State: State was not valid

I am having trouble setting up Salesforce as an auth provider for my Django application using Django Allauth, getting "No_Oauth_State: State was not valid" whenever I try to log in.

What I've done:

  1. I made a connected app in Salesforce as documented here: https://trailhead.salesforce.com/en/content/learn/projects/build-a-connected-app-for-api-integration/create-a-connected-app

  2. I followed the steps outlined in the Salesforce documentation (https://help.salesforce.com/articleView?id=sf.sso_provider_sfdc.htm&type=5) to setup Salesforce as an auth provider. I pasted the consumer key and secret from my connected app into the auth provider settings and copied the callback uri (https://{my_sf_domain}/services/authcallback/salesforce) from my auth provider into the callback uri field of the connected app, as stated in the docs.

  3. I configured Salesforce as a provider in my django application as stated in the Allauth docs (https://django-allauth.readthedocs.io/en/latest/providers.html#salesforce)

What happens when I try to log in:

  1. My application returns a 302 with the Location header set to: https://my.sf.domain/services/authcallback/salesforce/services/oauth2/authorize?client_id={super_secret}&redirect_uri=http://my.django.app.domain/accounts/salesforce/login/callback/&scope=id+openid&response_type=code&state={a_random_string_of_length_12}
  2. Salesforce returns a 302 at the uri the above Location header refers to, now with the Location header set to: https://my.sf.domain/_nc_external/identity/sso/ui/AuthorizationError?ErrorCode=No_Oauth_State&ErrorDescription=State+was+not+valid&ProviderId={auth_provider_id}

I am unsure how to debug this. Why is the state not valid? Does Salesforce expect the state parameter to be of a certain format?

Edit 1: I should probably mention that I am configuring this in a Salesforce Sandbox, although I'm unsure if this is relevant.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source