Use header URI in Plex config flow (#49915)
This commit is contained in:
parent
a2138a7642
commit
37e8571fe8
2 changed files with 80 additions and 79 deletions
|
@ -10,6 +10,7 @@ import requests.exceptions
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import http
|
||||
from homeassistant.components.http.view import HomeAssistantView
|
||||
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
||||
from homeassistant.const import (
|
||||
|
@ -25,7 +26,6 @@ from homeassistant.const import (
|
|||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.network import get_url
|
||||
|
||||
from .const import (
|
||||
AUTH_CALLBACK_NAME,
|
||||
|
@ -52,6 +52,8 @@ from .const import (
|
|||
from .errors import NoServersFound, ServerNotSpecified
|
||||
from .server import PlexServer
|
||||
|
||||
HEADER_FRONTEND_BASE = "HA-Frontend-Base"
|
||||
|
||||
_LOGGER = logging.getLogger(__package__)
|
||||
|
||||
|
||||
|
@ -286,7 +288,11 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
async def async_step_plex_website_auth(self):
|
||||
"""Begin external auth flow on Plex website."""
|
||||
self.hass.http.register_view(PlexAuthorizationCallbackView)
|
||||
hass_url = get_url(self.hass)
|
||||
if (req := http.current_request.get()) is None:
|
||||
raise RuntimeError("No current request in context")
|
||||
if (hass_url := req.headers.get(HEADER_FRONTEND_BASE)) is None:
|
||||
raise RuntimeError("No header in request")
|
||||
|
||||
headers = {"Origin": hass_url}
|
||||
payload = {
|
||||
"X-Plex-Device-Name": X_PLEX_DEVICE_NAME,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue