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

Fix logout view #1236

Merged
merged 2 commits into from
Jul 10, 2024
Merged

Fix logout view #1236

merged 2 commits into from
Jul 10, 2024

Conversation

rhysyngsun
Copy link
Contributor

@rhysyngsun rhysyngsun commented Jul 9, 2024

What are the relevant tickets?

Fixes https://github.com/mitodl/hq/issues/4831

Description (What does it do?)

  • Updates the code to ensure the redirect url is absolute again.
  • Removes the 404 error in favor of a redirect so this url behaves in an idempotent manner.

NOTE: I tried to add some tests for this, but they fail because we're using logout via a GET request, which is deprecated and removed in django 5+. I tried to fix that so we could just be done with logout for a good while but that spiraled into CSRF errors and it's not worth that level of effort at this time.

@rhysyngsun rhysyngsun marked this pull request as ready for review July 9, 2024 19:06
@rhysyngsun rhysyngsun added the Needs Review An open Pull Request that is ready for review label Jul 9, 2024
@shanbady shanbady self-requested a review July 9, 2024 20:19
@shanbady shanbady self-assigned this Jul 9, 2024
Copy link
Contributor

@shanbady shanbady left a comment

Choose a reason for hiding this comment

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

There are a few issues i've noted which i think we should address before merging. I'm working with chris to get the infra side of things sorted out

authentication/views.py Show resolved Hide resolved
@@ -37,25 +36,30 @@ def _keycloak_logout_url(self, user):
qs = urlencode(
{
"id_token_hint": id_token,
"post_logout_redirect_uri": settings.LOGOUT_REDIRECT_URL,
"post_logout_redirect_uri": self.request.build_absolute_uri(
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see this causing issues on a live server since self.request.build_absolute_uri will end up generating a different url depending on if its hit from api.* (which it might if done via js) or the main hostname. I think we need to explicitly generate this from the APP_BASE_URL since redirecting back to api.mitopen.odl.mit.edu leaves the user in a broken state - some functionality does not work as intended from api.*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The API should only ever be served from api.* domains. I updated the docstring to reflect the redirect path that the browser will take as the user is logged out.

@shanbady shanbady added Waiting on author and removed Needs Review An open Pull Request that is ready for review labels Jul 10, 2024
Copy link
Contributor

@shanbady shanbady left a comment

Choose a reason for hiding this comment

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

this should work using the /app route so not making this a blocker but i'll note my main concerns with using self.request.build_absolute_uri:

  1. it wont work when directly accessing from /logout (has to be done via js) - seems like we are unnecessarily restricting ourselves and sometimes i do go directly to /logout instead of clicking the button.
  2. Its not clear to me what the /app endpoints supports and seems like we are necessarily making extra roundtrips: mitopen -> api.mitopen/logout ->
  3. if we need to all of a sudden support redirects elsewhere or back to where the user previously this has the potential to get messy (we'd have to keep track of and pass some "next_url" through 3 request hops)

@rhysyngsun rhysyngsun merged commit 20e99eb into main Jul 10, 2024
11 checks passed
@rhysyngsun rhysyngsun deleted the nl/fix-logout branch July 10, 2024 15:35
@odlbot odlbot mentioned this pull request Jul 10, 2024
27 tasks
mbertrand pushed a commit that referenced this pull request Jul 15, 2024
* Fix logout redirect url

* Fix typos and update docstring to be more descriptive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants