-
Notifications
You must be signed in to change notification settings - Fork 141
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
Don't request HTTP Basic authenticaion when using a token #488
Conversation
Testing the UI issue: open the UI on the login screen, localStorage.miq_token = '123';
API.logout(); before: a browser login dialog will appear |
401 responses: when not providing token and cancelling the dialog (same before and after):
when providing a token that is not valid (new now):
|
@miq-bot remove_label wip Specs are already passing, just added one that fails without this :). |
@miq-bot add_label bug |
@@ -7,11 +7,13 @@ module Authentication | |||
# REST APIs Authenticator and Redirector | |||
# | |||
def require_api_user_or_token | |||
using_http_basic = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a method?
def using_http_basic_auth?
!(request.headers[HttpHeaders::MIQ_TOKEN] || request.headers[HttpHeaders::AUTH_TOKEN])
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or def auth_mechanism
or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, makes sense :)
Will do, looks like there is a similar bit of logic in container deployments, I'll try to merge that into a helper.
app/controllers/api/container_deployments_controller.rb
20: [HttpHeaders::MIQ_TOKEN, HttpHeaders::AUTH_TOKEN, "HTTP_AUTHORIZATION"].any? do |header|
only request fallback to HTTP Basic if no other authentication method is used specifically don't fall back to HTTP Basic when using the token, because otherwise there is no way to prevent the browser dialog when attempting to log out with a stale token, or even trying to use one during a normal request such attempts will now return a proper HTTP 401 JSON response, but will not trigger the popup
auth_mechanism returns :system for system tokens, :token for user tokens, :basic for HTTP Basic and nil if no such headers exist nil usually means the same as basic, but not for OPTION requests which support unauthenticated access
@bdunne can you take another look please? I added I also extracted 4 lines from all 3 authentication methods and moved them to a shared |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks great! Thanks @himdel
Don't request HTTP Basic authenticaion when using a token (cherry picked from commit c50b0ab)
Hammer backport details:
|
Only request fallback to HTTP Basic if no other authentication method is used.
Specifically don't fall back to HTTP Basic when using the token, because otherwise there is no way for the UI to prevent the browser log in dialog when attempting to log out with a stale token (or even trying to use one during a normal request, after suspend for example).
Such attempts will now return a proper HTTP 401 JSON response, but will not trigger the popup.
--
Closes ManageIQ/manageiq-ui-classic#4717
Introduced in #359