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

답변을 개선해야 합니다.

FB와 Google 인증을 테스트해 본 결과, 회사 정책상 Office365 로그인을 유지하기로 했습니다.

Discourse 서버를 프록시 뒤에 배치했을 때(아래 그림 참조), O365 인증이 사용할 수 없게 되었습니다. force https가 활성화되어 있어야 하는데, 프록시 뒤에서는 이 옵션이 작동하지 않는 문제였습니다. 다행히 Daniel 덕분에 해결되었습니다: Moved site behind proxy, favicon and header not using https anymore - #11 by rossierd.

내부 Nginx 설정의 다음 줄

proxy_set_header X-Forwarded-Proto $scheme;

은 다음과 같이 교체해야 합니다.

proxy_set_header X-Forwarded-Proto "https";

외부 Nginx에는 이러한 수정이 필요하지 않습니다. 현재 설정은 다음과 같습니다.

proxy_set_header X-Forwarded-Proto $scheme;

아마도 FB, Google 및 기타 인증 방식에도 동일한 원리가 적용될 것입니다.

P.S.

명백히 그 문자열에는 오타인 $가 포함되어 있어 아무런 효과가 없었습니다.