Skip to content

Commit

Permalink
fix for ha 2022.9 (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
eglia authored Sep 8, 2022
1 parent 6cc36d2 commit df65f5d
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions custom_components/auth_header/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from http import HTTPStatus
from ipaddress import ip_address
from typing import OrderedDict
from aiohttp.web_request import Request
from aiohttp.web import Request, Response
from typing import Any

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
Expand Down Expand Up @@ -94,15 +95,15 @@ def __init__(self, flow_mgr, store_result, debug=False) -> None:
)
)
@log_invalid_auth
async def post(self, request: Request, data):
async def post(self, request: Request, data: dict[str, Any]) -> Response:
"""Create a new login flow."""
if not await indieauth.verify_redirect_uri(
request.app["hass"], data["client_id"], data["redirect_uri"]
):
return self.json_message(
"invalid client id or redirect uri", HTTPStatus.BAD_REQUEST
)
client_id: str = data["client_id"]
redirect_uri: str = data["redirect_uri"]

if not indieauth.verify_client_id(client_id):
return self.json_message("Invalid client id", HTTPStatus.BAD_REQUEST)

handler: tuple[str, ...] | str
if isinstance(data["handler"], list):
handler = tuple(data["handler"])
else:
Expand All @@ -113,22 +114,19 @@ async def post(self, request: Request, data):
actual_ip = get_actual_ip(request)
_LOGGER.debug("Got actual IP %s", actual_ip)
result = await self._flow_mgr.async_init(
handler,
handler, # type: ignore[arg-type]
context={
"request": request,
"ip_address": ip_address(actual_ip),
"ip_address": ip_address(actual_ip), # type: ignore[arg-type]
"credential_only": data.get("type") == "link_user",
"redirect_uri": redirect_uri,
},
)
except data_entry_flow.UnknownHandler:
return self.json_message("Invalid handler specified", HTTPStatus.NOT_FOUND)
except data_entry_flow.UnknownStep:
return self.json_message("Handler does not support init", HTTPStatus.BAD_REQUEST)

if result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY:
await process_success_login(request)
result.pop("data")
result["result"] = self._store_result(data["client_id"], result["result"])
return self.json(result)
return self.json_message(
"Handler does not support init", HTTPStatus.BAD_REQUEST
)

return self.json(_prepare_result_json(result))
return await self._async_flow_result_to_response(request, client_id, result)

0 comments on commit df65f5d

Please sign in to comment.