Onboarding to validate redirect uri (#36863)
This commit is contained in:
1 parent
43cee39528
commit
903db07feb
6 files changed
+55
-10
No files matched your search
@@ -2,7 +2,9 @@
|
||||
"domain": "frontend",
|
||||
"name": "Home Assistant Frontend",
|
||||
"documentation": "https://www.home-assistant.io/integrations/frontend",
|
||||
"requirements": ["home-assistant-frontend==20200613.0"],
|
||||
"requirements": [
|
||||
"home-assistant-frontend==20200617.0"
|
||||
],
|
||||
"dependencies": [
|
||||
"api",
|
||||
"auth",
|
||||
@@ -15,6 +17,8 @@
|
||||
"system_log",
|
||||
"websocket_api"
|
||||
],
|
||||
"codeowners": ["@home-assistant/frontend"],
|
||||
"codeowners": [
|
||||
"@home-assistant/frontend"
|
||||
],
|
||||
"quality_scale": "internal"
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,10 @@ import asyncio
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.auth.const import GROUP_ID_ADMIN
|
||||
from homeassistant.components.auth import indieauth
|
||||
from homeassistant.components.http.data_validator import RequestDataValidator
|
||||
from homeassistant.components.http.view import HomeAssistantView
|
||||
from homeassistant.const import HTTP_FORBIDDEN
|
||||
from homeassistant.const import HTTP_BAD_REQUEST, HTTP_FORBIDDEN
|
||||
from homeassistant.core import callback
|
||||
|
||||
from .const import (
|
||||
@@ -168,7 +169,9 @@ class IntegrationOnboardingView(_BaseOnboardingView):
|
||||
name = "api:onboarding:integration"
|
||||
step = STEP_INTEGRATION
|
||||
|
||||
@RequestDataValidator(vol.Schema({vol.Required("client_id"): str}))
|
||||
@RequestDataValidator(
|
||||
vol.Schema({vol.Required("client_id"): str, vol.Required("redirect_uri"): str})
|
||||
)
|
||||
async def post(self, request, data):
|
||||
"""Handle token creation."""
|
||||
hass = request.app["hass"]
|
||||
@@ -182,6 +185,14 @@ class IntegrationOnboardingView(_BaseOnboardingView):
|
||||
|
||||
await self._async_mark_done(hass)
|
||||
|
||||
# Validate client ID and redirect uri
|
||||
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", HTTP_BAD_REQUEST
|
||||
)
|
||||
|
||||
# Return authorization code so we can redirect user and log them in
|
||||
auth_code = hass.components.auth.create_auth_code(data["client_id"], user)
|
||||
return self.json({"auth_code": auth_code})
|
||||
|
||||
Reference in new issue
Block a user