# Facebook Login Error: CSRF detected

**URL:** https://meta.discourse.org/t/facebook-login-error-csrf-detected/112599
**Category:** Support
**Created:** [26.Март.2019 12:43:14 UTC](https://meta.discourse.org/t/facebook-login-error-csrf-detected/112599 "2019-03-26T12:43:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![joshm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshm/32/135134_2.png) [@joshm](https://meta.discourse.org/u/joshm)
#### Post date: [26.Март.2019 12:43:14 UTC](https://meta.discourse.org/t/facebook-login-error-csrf-detected/112599/1 "2019-03-26T12:43:14Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![Ivan\_Rapekas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ivan_rapekas/32/248924_2.png) [@Ivan\_Rapekas](https://meta.discourse.org/u/Ivan_Rapekas)
#### Post date: [23.Июль.2019 21:10:47 UTC](https://meta.discourse.org/t/facebook-login-error-csrf-detected/112599/2 "2019-07-23T21:10:47Z")

</div>

Эта ошибка похожа и для Google, и для Facebook. В моей конфигурации в nginx была строка:

```
# proxy_set_header X-Forwarded-Proto $https;

```

После того как я изменил её на

```
proxy_set_header X-Forwarded-Proto $scheme;

```

ошибка исчезла.

Решение было найдено после прочтения этой темы: [Redirect URI mismatch in Google Auth](https://meta.discourse.org/t/redirect-uri-mismatch-in-google-auth/123152)

---

<div class="post-metadata">

### Author: ![Ivan\_Rapekas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ivan_rapekas/32/248924_2.png) [@Ivan\_Rapekas](https://meta.discourse.org/u/Ivan_Rapekas)
#### Post date: [13.Январь.2022 10:31:46 UTC](https://meta.discourse.org/t/facebook-login-error-csrf-detected/112599/3 "2022-01-13T10:31:46Z")

</div>

Мне нужно улучшить свой ответ.

После экспериментов с авторизацией через Facebook и Google я остановился на входе через Office365 из-за корпоративной политики.

Когда я переместил сервер Discourse за прокси (см. изображение ниже), авторизация O365 перестала работать. Требуется включение опции `force https`, но за прокси эта опция не работает. К счастью, проблему решил Daniel: [Moved site behind proxy, favicon and header not using https anymore - #11 by rossierd](https://meta.discourse.org/t/moved-site-behind-proxy-favicon-and-header-not-using-https-anymore/131486/11).

> Строка в конфигурации Internal Nginx
> 
> ```plaintext
> proxy_set_header X-Forwarded-Proto $scheme;
> 
> ```
> 
> doлжна быть заменена на
> 
> ```plaintext
> proxy_set_header X-Forwarded-Proto "https";
> 
> ```

 ![020_discourse.drawio](https://global.discourse-cdn.com/meta/original/3X/8/f/8fd448ca4ab76d6490949fe585b95e4a33d58190.jpeg)

> External Nginx не требует подобных изменений. В нём установлено:
> 
> ```plaintext
> proxy_set_header X-Forwarded-Proto $scheme;
> 
> ```

Вероятно, то же самое справедливо для Facebook, Google и других типов авторизации.

P.S.

> [@Ivan\_Rapekas](#):
>
> Ранее я писал  
> `proxy_set_header X-Forwarded-Proto $https;`

Очевидно, что в этой строке была опечатка с символом `$`, из-за чего она не работала.
