Authentication Provider Error: Grant missing session or misconfigured provider

System Information
  • Strapi Version: 3.1.1:
  • Operating System: Windows 10 and Mac / Linux (I test locally using Windows/MAC and the application is deployed using AWS Fargate):
  • Database: Sqlite, MySQL Aurora:
  • Node Version: 10.0.0:
  • NPM Version: 6.14.4:
  • Yarn Version: 1.22.10:

I’ve tried to configure strapi for making use of Google and Facebook authentication providers. I’m making use of a React Application as my frontend and Strapi (details above) as my backend/API. I’ve had a look at the react login sample and my code appears to be working locally (I do not get the Error: Grant missing session or misconfigured provider message). After deploying the frontend application to an AWS Fargate instance I get the error.

From a configuration perspective: the things that are different locally compared to production is the usage of a named host (not localhost).

In terms of the network requests that occur when I initiate the authentication: A 302 error is returned when making the get request to https://mybackend.org/connect/google/callback?code=“my code”. This occurs after selecting the Google account that I’d like to use for authentication. There is also a 302 error that occurs before this but it also happens when I test locally. The url is: https://accounts.google.com/signin/oauth/consent?authuser=0&part=“additional parameters”.

My frontend differs from the react-login-example in only one way that could be meaningful: I make use of session storage instead of local storage.

Please assist if you have any ideas, I can also provide additional information if needed.

Im not sure if this is relevant, but I had a similar issue when I was implementing google OAuth. What solved it for me was integrating adding the cors middleware to strapi and the frontend url as an approved domain like so

I’m having the same problem here, although with Microsoft provider. Everything is working fine on local but fails once in production, with the error described by OP: error=Grant%3A%20missing%20session%20or%20misconfigured%20provider.

On local Strapi is behind Nginx as reverse proxy.
On production Strapi is behind Nginx as reverse proxy and Cloudfront on top of that. I don’t know if that can be the source of the problem, but I am struggling to find the origin of the error…

There’s another post there: AWS Cognito as Authentication Provider: Grant Missing session or misconfigured provider error with a workaround suggested that didn’t work for me.

Any help is welcome!

I have found the problem and fixed it. As I stated before, the only difference between dev and prod environments was Cloudfront. So I needed to configure Cloudfront to differentiate calls with differents cookies and URLs. Grant needs cookies to initiate the connection with Strapi, while Strapi makes calls with queries in URLs.

More docs on that here: Caching content based on cookies - Amazon CloudFront
and here: Caching content based on query string parameters - Amazon CloudFront

Once I set up the Cloudfront policy (Cache key settings) to allow cookies and query strings, everything worked finally fine! I hope this can help some people overlooking that.