Skip to content

Commit

Permalink
feat: allow skipping of proxy warning
Browse files Browse the repository at this point in the history
Allow users to bypass test to confirm HA is reachable. Users will not
get further login support when bypassing.
  • Loading branch information
alandtse committed Jul 21, 2022
1 parent a08cc04 commit 5ed2082
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 115 deletions.
58 changes: 46 additions & 12 deletions custom_components/alexa_media/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import logging
from typing import Any, Dict, List, Optional, Text

from aiohttp import ClientConnectionError, ClientSession, web, web_response
from aiohttp import ClientConnectionError, ClientSession, InvalidURL, web, web_response
from aiohttp.web_exceptions import HTTPBadRequest
from alexapy import (
AlexaLogin,
Expand Down Expand Up @@ -50,6 +50,7 @@
CONF_INCLUDE_DEVICES,
CONF_OAUTH,
CONF_OTPSECRET,
CONF_PROXY_WARNING,
CONF_QUEUE_DELAY,
CONF_SECURITYCODE,
CONF_TOTP_REGISTER,
Expand Down Expand Up @@ -123,6 +124,9 @@ def __init__(self):
self.totp_register = OrderedDict(
[(vol.Optional(CONF_TOTP_REGISTER, default=False), bool)]
)
self.proxy_warning = OrderedDict(
[(vol.Optional(CONF_PROXY_WARNING, default=False), bool)]
)

async def async_step_import(self, import_config):
"""Import a config entry from configuration.yaml."""
Expand Down Expand Up @@ -242,27 +246,31 @@ async def async_step_user(self, user_input=None):
)
hass_url: str = user_input.get(CONF_HASS_URL)
hass_url_valid: bool = False
hass_url_error: str = ""
async with ClientSession() as session:
try:
async with session.get(hass_url) as resp:
hass_url_valid = resp.status == 200
except ClientConnectionError:
except (ClientConnectionError) as err:
hass_url_valid = False
hass_url_error = str(err)
except (InvalidURL) as err:
hass_url_valid = False
hass_url_error = str(err.__cause__)
if not hass_url_valid:
_LOGGER.debug(
"Unable to connect to provided Home Assistant url: %s", hass_url
)
return self.async_show_form(
step_id="user",
errors={"base": "hass_url_invalid"},
description_placeholders={"message": ""},
)
if not self.proxy:
self.proxy = AlexaProxy(
self.login, str(URL(hass_url).with_path(AUTH_PROXY_PATH))
)
# Swap the login object
self.proxy.change_login(self.login)
step_id="proxy_warning",
data_schema=vol.Schema(self.proxy_warning),
errors={},
description_placeholders={
"email": self.login.email,
"hass_url": hass_url,
"error": hass_url_error
},
)
if (
user_input
and user_input.get(CONF_OTPSECRET)
Expand Down Expand Up @@ -290,6 +298,19 @@ async def async_step_start_proxy(self, user_input=None):
hide_email(self.login.email),
self.login.url,
)
if not self.proxy:
try:
self.proxy = AlexaProxy(
self.login, str(URL(self.config.get(CONF_HASS_URL)).with_path(AUTH_PROXY_PATH))
)
except ValueError as ex:
return self.async_show_form(
step_id="user",
errors={"base": "invalid_url"},
description_placeholders={"message": str(ex)},
)
# Swap the login object
self.proxy.change_login(self.login)
if not self.proxy_view:
self.proxy_view = AlexaMediaAuthorizationProxyView(self.proxy.all_handler)
else:
Expand Down Expand Up @@ -436,8 +457,21 @@ async def async_step_user_legacy(self, user_input=None):
return self.async_show_form(
step_id="user_legacy",
errors={"base": "unknown_error"},
description_placeholders={"message": str(ex)},
)

async def async_step_proxy_warning(self, user_input=None):
"""Handle the proxy_warning for the config flow."""
self._save_user_input_to_config(user_input=user_input)
if user_input and user_input.get(CONF_PROXY_WARNING) is False:
_LOGGER.debug("User is not accepting warning, go back")
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(self.proxy_schema),
description_placeholders={"message": ""},
)
_LOGGER.debug("User is ignoring proxy warning; starting proxy anyway")
return await self.async_step_start_proxy(user_input)

async def async_step_totp_register(self, user_input=None):
"""Handle the input processing of the config flow."""
Expand Down
1 change: 1 addition & 0 deletions custom_components/alexa_media/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
CONF_SECURITYCODE = "securitycode"
CONF_OTPSECRET = "otp_secret"
CONF_PROXY = "proxy"
CONF_PROXY_WARNING = "proxy_warning"
CONF_TOTP_REGISTER = "registered"
CONF_OAUTH = "oauth"
DATA_LISTENER = "listener"
Expand Down
69 changes: 9 additions & 60 deletions custom_components/alexa_media/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"connection_error": "Error connecting; check network and retry",
"identifier_exists": "Email for Alexa URL already registered",
"invalid_credentials": "Invalid credentials",
"invalid_url": "URL is invalid: {message}",
"2fa_key_invalid": "Invalid Built-In 2FA key",
"hass_url_invalid": "Unable to connect to Home Assistant url. Please check the Internal Url under Configuration -> General",
"unknown_error": "Unknown error, please enable advanced debugging and report log info"
"unable_to_connect_hass_url": "Unable to connect to Home Assistant url. Please check the Internal Url under Configuration -> General",
"unknown_error": "Unknown error: {message}"
},
"step": {
"user": {
Expand All @@ -15,7 +16,7 @@
"email": "Email Address",
"url": "Amazon region domain (e.g., amazon.co.uk)",
"hass_url": "Url to access Home Assistant",
"otp_secret": "Built-in 2FA App Key (automatically generate 2FA Codes)",
"otp_secret": "Built-in 2FA App Key (automatically generate 2FA Codes). This not six digits long.",
"include_devices": "Included device (comma separated)",
"exclude_devices": "Excluded device (comma separated)",
"debug": "Advanced debugging",
Expand All @@ -26,77 +27,25 @@
"description": "Please confirm the information below. For legacy configuration, disable `Use Login Proxy method` option.",
"title": "Alexa Media Player - Configuration"
},
"user_legacy": {
"proxy_warning": {
"data": {
"proxy": "Use Login Proxy method (2FA not required)",
"password": "Password",
"email": "Email Address",
"securitycode": "2FA Code (recommended to avoid login issues)",
"otp_secret": "Built-in 2FA App Key (automatically generate 2FA Codes)",
"url": "Amazon region domain (e.g., amazon.co.uk)",
"include_devices": "Included device (comma separated)",
"exclude_devices": "Excluded device (comma separated)",
"debug": "Advanced debugging",
"scan_interval": "Seconds between scans",
"cookies_txt": "Cookies.txt data",
"oauth_login": "Enable oauth-token app method"
},
"description": "Please enter your [information](https://github.com/custom-components/alexa_media_player/wiki/Configuration#integrations-page). **[Cookie import](https://github.com/custom-components/alexa_media_player/wiki/Configuration#cookie-import) may be easiest!** \n**WARNING: Amazon incorrectly reports 'Enter a valid email or mobile number' when [2FA Code is required](https://github.com/custom-components/alexa_media_player/wiki/Configuration#enable-two-factor-authentication-for-your-amazon-account).** \n>{message}",
"title": "Alexa Media Player - Legacy Configuration"
},
"captcha": {
"data": {
"password": "Password",
"securitycode": "2FA Code (recommended to avoid login issues)",
"captcha": "Captcha",
"proxy": "Use Login Proxy method (2FA not required)"
"proxy_warning": "Ignore and Continue - I understand that no support for login issues are provided for bypassing this warning."
},
"description": "**{email} - alexa.{url}** \n{message} \n {captcha_image}",
"title": "Alexa Media Player - Captcha"
"description": "The HA server cannot connect to the URL provided: {hass_url}.\n> {error}\n\nTo fix this, please confirm your **HA server** can reach {hass_url}. This field is from the External Url under Configuration -> General but you can try your internal url.\n\nIf you are **certain** your client can reach this url, you can bypass this warning.",
"title": "Alexa Media Player - Unable to Connect to HA URL"
},
"totp_register": {
"data": {
"registered": "OTP from the Built-in 2FA App Key confirmed successfully."
},
"description": "**{email} - alexa.{url}** \nHave you successfully confirmed an OTP from the Built-in 2FA App Key with Amazon? \n >OTP Code {message}",
"title": "Alexa Media Player - OTP Confirmation"
},
"twofactor": {
"data": {
"securitycode": "2FA Code",
"proxy": "Use Login Proxy method (2FA not required)"
},
"description": "**{email} - alexa.{url}** \nEnter the One Time Password (OTP). \n{message}",
"title": "Alexa Media Player - Two Factor Authentication"
},
"authselect": {
"data": {
"authselectoption": "OTP method",
"proxy": "Use Login Proxy method (2FA not required)"
},
"description": "**{email} - alexa.{url}** \n{message}",
"title": "Alexa Media Player - One Time Password"
},
"claimspicker": {
"data": {
"authselectoption": "Verification method",
"proxy": "Use Login Proxy method (2FA not required)"
},
"description": "**{email} - alexa.{url}** \nPlease select verification method by number. (e.g., `0` or `1`) \n{message}",
"title": "Alexa Media Player - Verification Method"
},
"action_required": {
"data": {
"proxy": "Use Login Proxy method (2FA not required)"
},
"description": "**{email} - alexa.{url}** \nAmazon will send a push notification per the below message. Please completely respond before continuing. \n{message}",
"title": "Alexa Media Player - Action Required"
}
},
"abort": {
"forgot_password": "The Forgot Password page was detected. This normally is the result of too may failed logins. Amazon may require action before a relogin can be attempted.",
"login_failed": "Alexa Media Player failed to login.",
"reauth_successful": "Alexa Media Player successfully reauthenticated."
"reauth_successful": "Alexa Media Player successfully reauthenticated. Please ignore the \"Aborted\" message from HA."
}
},
"options": {
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alexa_media/translations/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"error": {
"2fa_key_invalid": "Invalid Built-In 2FA key",
"connection_error": "Error connecting; check network and retry",
"hass_url_invalid": "Unable to connect to Home Assistant url. Please check the External Url under Configuration -> General",
"unable_to_connect_hass_url": "Unable to connect to Home Assistant url. Please check the External Url under Configuration -> General",
"identifier_exists": "Email for Alexa URL already registered",
"invalid_credentials": "Invalid credentials",
"unknown_error": "Unknown error, please enable advanced debugging and report log info"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alexa_media/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"error": {
"2fa_key_invalid": "Invalid Built-In 2FA key",
"connection_error": "Verbindungsfehler; Netzwerk prüfen und erneut versuchen",
"hass_url_invalid": "Es kann keine Verbindung zur Home Assistant-URL hergestellt werden. Bitte überprüfen Sie die externe URL unter Konfiguration - > Allgemein",
"unable_to_connect_hass_url": "Es kann keine Verbindung zur Home Assistant-URL hergestellt werden. Bitte überprüfen Sie die externe URL unter Konfiguration - > Allgemein",
"identifier_exists": "Diese Email ist bereits registriert",
"invalid_credentials": "Falsche Zugangsdaten",
"unknown_error": "Unbekannter Fehler, bitte Log-Info melden"
Expand Down
62 changes: 33 additions & 29 deletions custom_components/alexa_media/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
{
"config": {
"abort": {
"forgot_password": "The Forgot Password page was detected. This normally is the result of too may failed logins. Amazon may require action before a relogin can be attempted.",
"login_failed": "Alexa Media Player failed to login.",
"reauth_successful": "Alexa Media Player successfully reauthenticated."
},
"error": {
"2fa_key_invalid": "Invalid Built-In 2FA key",
"connection_error": "Error connecting; check network and retry",
"hass_url_invalid": "Unable to connect to Home Assistant url. Please check the External Url under Configuration -> General",
"identifier_exists": "Email for Alexa URL already registered",
"invalid_credentials": "Invalid credentials",
"unknown_error": "Unknown error, please enable advanced debugging and report log info"
"invalid_url": "URL is invalid: {message}",
"2fa_key_invalid": "Invalid Built-In 2FA key",
"unable_to_connect_hass_url": "Unable to connect to Home Assistant url. Please check the Internal Url under Configuration -> General",
"unknown_error": "Unknown error: {message}"
},
"step": {
"captcha": {
"data": {
"securitycode": "2FA Code (recommended to avoid login issues)"
}
},
"totp_register": {
"data": {
"registered": "OTP from the Built-in 2FA App Key confirmed successfully."
},
"description": "**{email} - alexa.{url}** \nHave you successfully confirmed an OTP from the Built-in 2FA App Key with Amazon? \n >OTP Code {message}",
"title": "Alexa Media Player - OTP Confirmation"
},
"user": {
"data": {
"debug": "Advanced debugging",
"password": "Password",
"email": "Email Address",
"exclude_devices": "Excluded device (comma separated)",
"url": "Amazon region domain (e.g., amazon.co.uk)",
"hass_url": "Url to access Home Assistant",
"otp_secret": "Built-in 2FA App Key (automatically generate 2FA Codes). This not six digits long.",
"include_devices": "Included device (comma separated)",
"otp_secret": "Built-in 2FA App Key (automatically generate 2FA Codes)",
"password": "Password",
"exclude_devices": "Excluded device (comma separated)",
"debug": "Advanced debugging",
"scan_interval": "Seconds between scans",
"securitycode": "2FA Code (recommended to avoid login issues)",
"url": "Amazon region domain (e.g., amazon.co.uk)"
"proxy": "Use Login Proxy method (2FA not required)",
"oauth_login": "Enable oauth-token app method"
},
"description": "Please confirm the information below.",
"description": "Please confirm the information below. For legacy configuration, disable `Use Login Proxy method` option.",
"title": "Alexa Media Player - Configuration"
},
"proxy_warning": {
"data": {
"proxy_warning": "Ignore and Continue - I understand that no support for login issues are provided for bypassing this warning."
},
"description": "The HA server cannot connect to the URL provided: {hass_url}.\n> {error}\n\nTo fix this, please confirm your **HA server** can reach {hass_url}. This field is from the External Url under Configuration -> General but you can try your internal url.\n\nIf you are **certain** your client can reach this url, you can bypass this warning.",
"title": "Alexa Media Player - Unable to Connect to HA URL"
},
"totp_register": {
"data": {
"registered": "OTP from the Built-in 2FA App Key confirmed successfully."
},
"description": "**{email} - alexa.{url}** \nHave you successfully confirmed an OTP from the Built-in 2FA App Key with Amazon? \n >OTP Code {message}",
"title": "Alexa Media Player - OTP Confirmation"
}
},
"abort": {
"forgot_password": "The Forgot Password page was detected. This normally is the result of too may failed logins. Amazon may require action before a relogin can be attempted.",
"login_failed": "Alexa Media Player failed to login.",
"reauth_successful": "Alexa Media Player successfully reauthenticated. Please ignore the \"Aborted\" message from HA."
}
},
"options": {
"step": {
"init": {
"data": {
"extended_entity_discovery": "Include devices connected via Echo",
"queue_delay": "Seconds to wait to queue commands together"
"queue_delay": "Seconds to wait to queue commands together",
"extended_entity_discovery": "Include devices connected via Echo"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alexa_media/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"error": {
"2fa_key_invalid": "Invalid Built-In 2FA key",
"connection_error": "Error al conectar, verifique la red y vuelva a intentarlo",
"hass_url_invalid": "No se puede conectar a la url de Home Assistant. Compruebe la dirección URL externa en Configuración -> General",
"unable_to_connect_hass_url": "No se puede conectar a la url de Home Assistant. Compruebe la dirección URL externa en Configuración -> General",
"identifier_exists": "Correo electrónico para la URL de Alexa ya registrado",
"invalid_credentials": "Credenciales no válidas",
"unknown_error": "Error desconocido, habilite la depuración avanzada e informe la información de registro"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alexa_media/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"error": {
"2fa_key_invalid": "Clé 2FA intégrée non valide",
"connection_error": "Erreur de connexion; vérifier le réseau et réessayer",
"hass_url_invalid": "Impossible de se connecter à l'URL de Home Assistant. Veuillez vérifier l'URL externe sous Configuration - > Général",
"unable_to_connect_hass_url": "Impossible de se connecter à l'URL de Home Assistant. Veuillez vérifier l'URL externe sous Configuration - > Général",
"identifier_exists": "Email pour l'URL Alexa déjà enregistré",
"invalid_credentials": "Informations d'identification invalides",
"unknown_error": "Erreur inconnue, veuillez signaler les informations du journal"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alexa_media/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"error": {
"2fa_key_invalid": "Chiave 2FA incorporata non valida",
"connection_error": "Errore durante la connessione; controlla la rete e riprova",
"hass_url_invalid": "Impossibile collegarsi all'URL di Home Assistant. Controllare l'URL esterno nel menu Configurazione -> Generale",
"unable_to_connect_hass_url": "Impossibile collegarsi all'URL di Home Assistant. Controllare l'URL esterno nel menu Configurazione -> Generale",
"identifier_exists": "L'email per l'URL di Alexa è già stata registrata",
"invalid_credentials": "Credenziali non valide",
"unknown_error": "Errore sconosciuto, si prega di abilitare il debug avanzato e riportare i log informativi"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alexa_media/translations/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"error": {
"2fa_key_invalid": "Invalid Built-In 2FA key",
"connection_error": "Feil ved tilkobling; sjekk nettverket og prøv på nytt",
"hass_url_invalid": "Kan ikke koble til nettadressen til hjemmeassistenten. Vennligst sjekk den eksterne nettadressen under Konfigurasjon - > Generelt",
"unable_to_connect_hass_url": "Kan ikke koble til nettadressen til hjemmeassistenten. Vennligst sjekk den eksterne nettadressen under Konfigurasjon - > Generelt",
"identifier_exists": "E-post for Alexa URL allerede registrert",
"invalid_credentials": "ugyldige legitimasjon",
"unknown_error": "Ukjent feil, vennligst rapporter logginfo"
Expand Down
Loading

0 comments on commit 5ed2082

Please sign in to comment.