Skip to content

Commit

Permalink
add debug option to show sent headers during login
Browse files Browse the repository at this point in the history
  • Loading branch information
BeryJu committed Oct 29, 2020
1 parent e98566d commit 4dd0101
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ http:
auth_header:
# Optionally set this if you're not using passbook proxy or oauth2_proxy
# username_header: X-Forwarded-Preferred-Username
# Optionally enable debug mode to see the headers Home-Assistant gets
# debug: false
```

Afterwards, restart Home Assistant.
Expand Down
17 changes: 15 additions & 2 deletions custom_components/auth_header/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from ipaddress import ip_address
from typing import OrderedDict
from aiohttp.web_request import Request

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
Expand Down Expand Up @@ -28,6 +29,7 @@
vol.Optional(
"username_header", default="X-Forwarded-Preferred-Username"
): cv.string,
vol.Optional("debug", default=False): cv.boolean,
}
)
},
Expand All @@ -46,7 +48,9 @@ async def async_setup(hass: HomeAssistant, config):
hass.http.app.router._resources.remove(route)
_LOGGER.debug("Add new login_flow route")
hass.http.register_view(
RequestLoginFlowIndexView(hass.auth.login_flow, store_result)
RequestLoginFlowIndexView(
hass.auth.login_flow, store_result, config[DOMAIN]["debug"]
)
)

# Inject Auth-Header provider.
Expand All @@ -64,6 +68,13 @@ async def async_setup(hass: HomeAssistant, config):


class RequestLoginFlowIndexView(LoginFlowIndexView):

debug: bool

def __init__(self, flow_mgr, store_result, debug=False) -> None:
super().__init__(flow_mgr, store_result)
self.debug = debug

@RequestDataValidator(
vol.Schema(
{
Expand All @@ -75,7 +86,7 @@ class RequestLoginFlowIndexView(LoginFlowIndexView):
)
)
@log_invalid_auth
async def post(self, request, data):
async def post(self, request: Request, data):
"""Create a new login flow."""
if not await indieauth.verify_redirect_uri(
request.app["hass"], data["client_id"], data["redirect_uri"]
Expand All @@ -90,6 +101,8 @@ async def post(self, request, data):
handler = data["handler"]

try:
if self.debug:
_LOGGER.warning(request.headers)
result = await self._flow_mgr.async_init(
handler,
context={
Expand Down

0 comments on commit 4dd0101

Please sign in to comment.