Facebook Login Error: CSRF detected

Hi!

My users cannot log in with Facebook anymore. This is the error log:

(facebook) Authentication failure! csrf_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected | CSRF detected

I’m using Cloudflare in front of nginx. I’m using Cloudflare automatic SSL (flexible). I didn’t install any certificate on my server (i.e. I’m not using Letsencrypt).

Is this related to Cloudflare? Can this be solved without installing Letsencrypt?

Thanks!

This error is similar both for Google and Facebook. In my configuration there was a line in nginx:

# proxy_set_header X-Forwarded-Proto $https;

After I changed it to

proxy_set_header X-Forwarded-Proto $scheme;

the error has gone.

Solution was found after reading this topic: Redirect URI mismatch in Google Auth

2 « J'aime »

Je dois améliorer ma réponse.

Après avoir expérimenté l’authentification FB et Google, je suis resté sur la connexion Office365 en raison de la politique de l’entreprise.

Lorsque j’ai déplacé mon serveur Discourse derrière un proxy (voir l’image ci-dessous), l’authentification O365 est devenue indisponible. Elle nécessite que force https soit activé et cette option est défectueuse derrière le proxy. Heureusement résolu par Daniel : Moved site behind proxy, favicon and header not using https anymore - #11 by rossierd.

La ligne dans la configuration Nginx interne

proxy_set_header X-Forwarded-Proto $scheme;

doit être remplacée par

proxy_set_header X-Forwarded-Proto "https";

Nginx externe n’a pas besoin de telles modifications. Il a :

proxy_set_header X-Forwarded-Proto $scheme;

Probablement la même chose est valable pour FB, Google et d’autres types d’authentification.

P.S.

Évidemment, cette chaîne contenait une faute de frappe $ et était inutile.

1 « J'aime »