assign user to websocket connection when using legacy_api_password (#19797)
This commit is contained in:
parent
6d9fda04ac
commit
23382ab199
2 changed files with 5 additions and 2 deletions
|
@ -6,6 +6,7 @@ from homeassistant.const import __version__
|
||||||
from homeassistant.components.http.auth import validate_password
|
from homeassistant.components.http.auth import validate_password
|
||||||
from homeassistant.components.http.ban import process_wrong_login, \
|
from homeassistant.components.http.ban import process_wrong_login, \
|
||||||
process_success_login
|
process_success_login
|
||||||
|
from homeassistant.auth.providers import legacy_api_password
|
||||||
|
|
||||||
from .connection import ActiveConnection
|
from .connection import ActiveConnection
|
||||||
from .error import Disconnect
|
from .error import Disconnect
|
||||||
|
@ -81,7 +82,8 @@ class AuthPhase:
|
||||||
elif self._hass.auth.support_legacy and 'api_password' in msg:
|
elif self._hass.auth.support_legacy and 'api_password' in msg:
|
||||||
self._logger.debug("Received api_password")
|
self._logger.debug("Received api_password")
|
||||||
if validate_password(self._request, msg['api_password']):
|
if validate_password(self._request, msg['api_password']):
|
||||||
return await self._async_finish_auth(None, None)
|
user = await legacy_api_password.async_get_user(self._hass)
|
||||||
|
return await self._async_finish_auth(user, None)
|
||||||
|
|
||||||
self._send_message(auth_invalid_message(
|
self._send_message(auth_invalid_message(
|
||||||
'Invalid access token or password'))
|
'Invalid access token or password'))
|
||||||
|
|
|
@ -132,7 +132,8 @@ async def test_auth_active_with_password_not_allow(hass, aiohttp_client):
|
||||||
assert auth_msg['type'] == TYPE_AUTH_INVALID
|
assert auth_msg['type'] == TYPE_AUTH_INVALID
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_legacy_support_with_password(hass, aiohttp_client):
|
async def test_auth_legacy_support_with_password(hass, aiohttp_client,
|
||||||
|
legacy_auth):
|
||||||
"""Test authenticating with a token."""
|
"""Test authenticating with a token."""
|
||||||
assert await async_setup_component(hass, 'websocket_api', {
|
assert await async_setup_component(hass, 'websocket_api', {
|
||||||
'http': {
|
'http': {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue