Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: show logout template after logging out #2913

Merged
merged 3 commits into from
Jan 20, 2025
Merged

Conversation

hugobarauna
Copy link
Member

When the user is logged in using an identity provider that supports logout (like OIDC), after clicking logout

CleanShot 2025-01-17 at 16 34 38

We want them to see the logout page:

CleanShot 2025-01-17 at 16 31 53

Before this PR, they were being redirected to the "auth via Teams" page:

CleanShot 2025-01-17 at 16 33 52

@hugobarauna hugobarauna requested a review from aleDsz January 17, 2025 19:37
Copy link

github-actions bot commented Jan 17, 2025

Uffizzi Preview deployment-60021 was deleted.

AuthHelpers.redirect_to(conn)
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the benefit of moving this to another controller? We now need to create a separate module to share functionality, causing more indirection. I'd prefer to keep them together without a AuthHelpers. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that in the first place. But they have different requirements.

AuthController's actions requires require_unauthenticated:

defp require_unauthenticated(conn, _opts) do
if AuthPlug.authenticated?(conn) do
AuthHelpers.redirect_to(conn)
else
conn
end
end

UserAuthContoller.logout does not.

After trying to battle that, I ended up with that solution: two different controllers.

I actually liked it because I have different concerns. AuthContoller is about "admin authentication". UserAuthController is about "instance/user-identity" based authentication.

We have a similar approach with two related plugs. We have AuthPlug that's more related to "admin authentication" and there's UserPlug that's more related to "instance/user-identity" based authentication.

Copy link
Contributor

@josevalim josevalim Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do action based plugs in Phoenix controllers, I believe it would be:

 plug :require_unauthenticated when action_name != :logout

Or something like that. :)

But I see your points about keeping them separate because they deal with different concerns, and I agree. Here are my suggestions:

  1. Rename it to UserController and UserHTML, in order to mirror the plugs (AuthPlug vs UserPlug)

  2. Don't use the redirect_to helper in logout, leave it only on AuthController. It is used for login because you want to redirect back to the page you were trying to enter, but that doesn't make sense for logout. The page you were at cannot be accessible anymore

I think the suggestions above keep your proposals for code organization and remove my concerns, wdyt?

Copy link
Member Author

@hugobarauna hugobarauna Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Done in e3ed654. ✅

defmodule LivebookWeb.UserController do
use LivebookWeb, :controller

def logout(conn, _params) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep it in the auth controller/view, I think it fits there, and there's no need add microfiles unnecessarily :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this and the goal for now is to mirror LivebookWeb.UserPlug and LivebookWeb.AuthPlug. So I am fine with this but we can revisit later if necessary.

identity_logout? =
Code.ensure_loaded?(module) and function_exported?(module, :logout, 2)

authentication().mode != :disabled or identity_logout?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FTR authentication().mode != :disabled was intentional, the reasoning is that currently we have no way to sign out from Livebook after you authenticate with LIVEBOOK_PASSWORD. I'm fine either way though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they have to be different things because when using an identity provider, you still need to log in as admin. We may also want to add a "Logout" button to the menu of deployed apps, which will also trigger this. So having the button doing different things at different stages could be confusing, so I think tying it exclusively to identity for now is the right call.

@hugobarauna hugobarauna merged commit a8d5786 into main Jan 20, 2025
7 checks passed
@hugobarauna hugobarauna deleted the hb-logout-fixes branch January 20, 2025 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants