Skip to content

Commit

Permalink
Handle URL validation requests
Browse files Browse the repository at this point in the history
  • Loading branch information
willscott committed Jan 2, 2023
1 parent c51e711 commit 65d90af
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion custom_components/zoom/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from http import HTTPStatus
from logging import getLogger
from typing import Any, Dict, List
import hmac
import hashlib

from aiohttp.web import Request, Response
from aiohttp.web import Request, Response, json_response
from homeassistant.components.http.view import HomeAssistantView
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_oauth2_flow
Expand Down Expand Up @@ -123,6 +125,23 @@ async def post(self, request: Request) -> Response:
)
return Response(status=HTTPStatus.OK)

try:
data = await request.json()
if data["event"] == "endpoint.url_validation":
plain = data["payload"]["plainToken"]
signature = hmac.new(bytes(next(iter(verification_tokens)) , 'latin-1'), msg = bytes(plain , 'latin-1'), digestmod = hashlib.sha256).hexdigest()
_LOGGER.info(
"Received validation request: %s",
data
)
return json_response({'plainToken': plain, 'encryptedToken': signature})
except Exception as err:
_LOGGER.warning(
"failed response to validation request: %s (%s)",
data,
err,
)

_LOGGER.warning(
"Received unauthorized request: %s (Headers: %s)",
await request.text(),
Expand Down

0 comments on commit 65d90af

Please sign in to comment.