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

authorize: only redirect for HTML pages #2264

Merged
merged 2 commits into from
Jun 2, 2021

Conversation

calebdoxsey
Copy link
Contributor

Summary

Currently when a user is not logged in and they don't have access to a route, we redirect the user through the Login flow. Unfortunately this causes issues for single page applications, because usually the request that will result in the redirect is done via AJAX or Fetch, and Javascript can't handle the HTML redirect.

This PR changes the behavior slightly so we only do the redirect if a request for an HTML page is made. Other types of requests receive a 401 instead, which applications can detect and handle appropriately. (For example Grafana reloads the page and sends the user through the Login flow again)

Related issues

Fixes #2176

Checklist

  • reference any related issues
  • updated docs
  • updated unit tests
  • updated UPGRADING.md
  • add appropriate tag (improvement / bug / etc)
  • ready for review

@calebdoxsey calebdoxsey added the bug Something isn't working label Jun 2, 2021
@calebdoxsey calebdoxsey requested a review from a team as a code owner June 2, 2021 21:06
@calebdoxsey calebdoxsey requested a review from wasaga June 2, 2021 21:06
@codeclimate
Copy link

codeclimate bot commented Jun 2, 2021

Code Climate has analyzed commit c3e286c and detected 0 issues on this pull request.

View more on Code Climate.

@calebdoxsey calebdoxsey merged commit 9dc90d0 into master Jun 2, 2021
@calebdoxsey calebdoxsey deleted the cdoxsey/2176-javascript-errors branch June 2, 2021 22:18
@github-actions
Copy link

The backport to 0-14-0 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-0-14-0 0-14-0
# Navigate to the new working tree
cd .worktrees/backport-0-14-0
# Create a new branch
git switch --create backport-2264-to-0-14-0
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick --mainline 1 9dc90d02d0ac39eae66171c9e2189e9693b35a1f
# Push it to GitHub
git push --set-upstream origin backport-2264-to-0-14-0
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-0-14-0

Then, create a pull request where the base branch is 0-14-0 and the compare/head branch is backport-2264-to-0-14-0.

calebdoxsey added a commit that referenced this pull request Jun 16, 2021
* authorize: only redirect for HTML pages

* authorize: only redirect for HTML pages
calebdoxsey added a commit that referenced this pull request Jun 16, 2021
* authorize: only redirect for HTML pages

* authorize: only redirect for HTML pages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 0-14-0 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CORS Error when session expires
2 participants