# Redirecionar após logout com login em tela cheia

**URL:** https://meta.discourse.org/t/redirect-after-logout-with-full-screen-login/109755
**Category:** Bug
**Created:** [21 Fevereiro , 2019 13:33 UTC](https://meta.discourse.org/t/redirect-after-logout-with-full-screen-login/109755 "2019-02-21T13:33:42Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)
#### Post date: [21 Fevereiro , 2019 13:33 UTC](https://meta.discourse.org/t/redirect-after-logout-with-full-screen-login/109755/1 "2019-02-21T13:33:42Z")

</div>

This is a bit of a weird one. It requires a discourse install using “full screen login” for authentication, and the [omniauth origin param](https://github.com/omniauth/omniauth#configuring-the-origin-param) set to an external url (this is done either through a referrer or the `?origin=` param).

**Steps to reproduce** :

1. Log into a Discourse site using FSL, setting the origin to an external site  
e.g. [https://discourse.mozilla.org/auth/auth0?origin=http://example.com/](https://discourse.mozilla.org/auth/auth0?origin=http://example.com/) (I’d suggest logging in via passwordless by entering your email at the top, GitHub authentication currently requires 2FA)
2. Log out of the Discourse site after a successful login

**Result** :

You’re redirected to the external site.

**Video:**

[https://global.discourse-cdn.com/meta/original/3X/2/e/2ec6d9f4efb6e9a44f056bf79ce0c8c0e279ab9a.mp4](https://global.discourse-cdn.com/meta/original/3X/2/e/2ec6d9f4efb6e9a44f056bf79ce0c8c0e279ab9a.mp4)

**What’s going on here** :

During login, in `omniauth_callbacks_controller.rb`:

```ruby
# origin is e.g. "http://example.com/"
parsed = URI.parse(origin)
@origin = "#{parsed.path}?#{parsed.query}"
cookies[:authentication_data] = {
  destination_url: origin
}
redirect_to @origin

```

`@origin` is a host-less url, but `origin` is absolute. So in this case `@origin = "/"`

Also note, the cookie is set to the absolute `origin`, but the redirect is to the host-less `@origin`.

After logout, thanks to this in `application.html.erb` (which triggers a call to `Discourse.authenticationComplete` with the data), the user is redirected to the `destination_url` set above:

```plaintext
<%- if !current_user && cookies[:authentication_data] %>
  <meta id="data-authentication" data-authentication-data="<%= cookies.delete(:authentication_data) %>">
<%- end %>

```

So, there’s a couple of problems here:

1. That `authentcation_data` cookie seems to exist for login only. It then triggering `Discourse.authenticationComplete` on logout seems wrong to me. The cookie should probably be nuked on logout. This would prevent the post-logout redirect to `origin`.

2. The code in `omniauth_callbacks_controller.rb` is written to assume that the `origin` has the same domain as the Discourse instance, but that’s not always the case. I don’t know if the cookie-`origin`/redirect-`@origin` discrepancy is deliberate, but clearing `origin` prior to generating `@origin` if it’s not a Discourse url should fix this problem.

I’m happy to work on a PR to fix these two issues.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [21 Fevereiro , 2019 17:30 UTC](https://meta.discourse.org/t/redirect-after-logout-with-full-screen-login/109755/2 "2019-02-21T17:30:30Z")

</div>

> [@LeoMcA](#):
>
> happy to work on a PR to fix these two issues.

Sounds good to me, go for it 👍

---

<div class="post-metadata">

### Author: ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)
#### Post date: [14 Março , 2019 18:23 UTC](https://meta.discourse.org/t/redirect-after-logout-with-full-screen-login/109755/3 "2019-03-14T18:23:13Z")

</div>

PR submitted:

[https://github.com/discourse/discourse/pull/7170](https://github.com/discourse/discourse/pull/7170)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [11 Maio , 2019 04:24 UTC](https://meta.discourse.org/t/redirect-after-logout-with-full-screen-login/109755/4 "2019-05-11T04:24:23Z")

</div>

Is this related to your recent work @techAPJ

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [13 Maio , 2019 05:09 UTC](https://meta.discourse.org/t/redirect-after-logout-with-full-screen-login/109755/5 "2019-05-13T05:09:47Z")

</div>

This is not related to my recent “full screen login” work but the PR to fix this was merged by David and all the specs are passing. So we’re good here. 👍

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [13 Maio , 2019 05:10 UTC](https://meta.discourse.org/t/redirect-after-logout-with-full-screen-login/109755/6 "2019-05-13T05:10:55Z")

</div>


