-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
Disambiguate Supervisor HTTPUnauthorized on user/password validation #44940
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
Conversation
The HA core API usually returns 401 when the request does not have proper authentication tokens or they have expired. However the user/password validation endpoint may also return 401 when the given user/password is invalid. The supervisor is currently unable to distinguish both scenarios, and it needs to. See home-assistant/supervisor#2408
I get the upstream change, but what does this change add to the changes made? |
) | ||
except auth_ha.InvalidAuth: | ||
raise HTTPUnauthorized() from None | ||
raise HTTPUnauthorized(reason=_REASON_INVALID_USER_PASSWORD) from None |
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.
raise HTTPNotFound() / see comment on supervisor PR
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.
Done! Thanks! 👍
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.
I had to update a unit test to reflect the new behaviour
The supervisor (authenticated with a bearer token) was trying to validate some user credentials (user and password). If the token was not valid, the response was 401. If the user credentials were not valid, the response also was 401. My initial commit added an http reason (a message) to disambiguate whether the token was not valid or the user&password credentials were not valid. @pvizeli's solution is to use a 404 when the user/password is invalid. It is simpler and makes sense, since the request is authenticated (the token is valid) so a 401 would not apply. I want to give a big thank you to both of you for all your work you do in general and for reviewing my recent pull requests. Thanks. |
…44940) * Disambiguate HTTPUnauthorized on user/password validation The HA core API usually returns 401 when the request does not have proper authentication tokens or they have expired. However the user/password validation endpoint may also return 401 when the given user/password is invalid. The supervisor is currently unable to distinguish both scenarios, and it needs to. See home-assistant/supervisor#2408 * Return 404 if user& password are not found/valid * Fix test for invalid user/password
* 'dev' of https://github.com/home-assistant/core: (98 commits) Bump pymyq to 2.0.13 (home-assistant#44961) Add zwave to ozw migration (home-assistant#39081) Add pressure forecast to HA weather entity model (home-assistant#44965) Deduplicate MQTT entity discovery code (home-assistant#44970) Fix parameters when toggling light (home-assistant#44950) Move MQTT entity helpers to separate file (home-assistant#44838) Helpers type hint improvements (home-assistant#44964) Remove script/test (home-assistant#44967) Add MQTT Number (non optimistic) (home-assistant#44883) Fix Netatmo climate boost for valves (home-assistant#44957) Disambiguate Supervisor HTTPUnauthorized on user/password validation (home-assistant#44940) Add torrent id to Transmission events (home-assistant#44187) Prefix versions in system health (home-assistant#44921) Fix media renderers without volume control (home-assistant#44874) Fix wait_template incorrectly matching falsey values (home-assistant#44938) Upgrade youtube_dl to 2021.01.03 (home-assistant#44942) Upgrade discord.py to 1.6.0 (home-assistant#44941) Fix KNX cover state return open when unknown (home-assistant#44926) Use parent_id to find cause of logbook events with new contexts (home-assistant#44416) Implement support for additional ecobee hold modes (home-assistant#40520) ...
Proposed change
The HA core API usually returns 401 when the request does not
have proper authentication tokens or they have expired.
However the user/password validation endpoint may also return
401 when the given user/password is invalid.
The supervisor is currently unable to distinguish both scenarios,
and it needs to.
See home-assistant/supervisor#2408 and home-assistant/supervisor#2411
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: