Add trusted networks auth provider (#15812)

* Add context to login flow

* Add trusted networks auth provider

* source -> context
This commit is contained in:
Jason Hu authored and Paulus Schoutsen committed 2018-08-13 12:40:06 +02:00
1 parent 50daef9a52
commit da8f93dca2
6 files changed
+247 -12

No files matched your search

+10 -1
View File
@@ -63,6 +63,7 @@ import aiohttp.web
import voluptuous as vol
from homeassistant import data_entry_flow
from homeassistant.components.http import KEY_REAL_IP
from homeassistant.components.http.ban import process_wrong_login, \
log_invalid_auth
from homeassistant.components.http.data_validator import RequestDataValidator
@@ -151,7 +152,8 @@ class LoginFlowIndexView(HomeAssistantView):
handler = data['handler']
try:
result = await self._flow_mgr.async_init(handler, context={})
result = await self._flow_mgr.async_init(
handler, context={'ip_address': request[KEY_REAL_IP]})
except data_entry_flow.UnknownHandler:
return self.json_message('Invalid handler specified', 404)
except data_entry_flow.UnknownStep:
@@ -188,6 +190,13 @@ class LoginFlowResourceView(HomeAssistantView):
return self.json_message('Invalid client id', 400)
try:
# do not allow change ip during login flow
for flow in self._flow_mgr.async_progress():
if (flow['flow_id'] == flow_id and
flow['context']['ip_address'] !=
request.get(KEY_REAL_IP)):
return self.json_message('IP address changed', 400)
result = await self._flow_mgr.async_configure(flow_id, data)
except data_entry_flow.UnknownFlow:
return self.json_message('Invalid flow specified', 404)
@@ -220,6 +220,7 @@ class HomeAssistantHTTP:
self.ssl_key = ssl_key
self.server_host = server_host
self.server_port = server_port
self.trusted_networks = trusted_networks
self.is_ban_enabled = is_ban_enabled
self._handler = None
self.server = None
+4 -1
View File
@@ -344,7 +344,10 @@ class ActiveConnection:
if request[KEY_AUTHENTICATED]:
authenticated = True
else:
# always request auth when auth is active
# even request passed pre-authentication (trusted networks)
# or when using legacy api_password
if self.hass.auth.active or not authenticated:
self.debug("Request auth")
await self.wsock.send_json(auth_required_message())
msg = await wsock.receive_json()