Fix Plex auth issues by setting header (#43081)

pull/43102/head
jjlawren 2020-11-11 02:40:25 -06:00 committed by Franck Nijhof
parent 9d617d446e
commit 176c2f3978
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
4 changed files with 9 additions and 7 deletions

View File

@ -289,6 +289,8 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
async def async_step_plex_website_auth(self): async def async_step_plex_website_auth(self):
"""Begin external auth flow on Plex website.""" """Begin external auth flow on Plex website."""
self.hass.http.register_view(PlexAuthorizationCallbackView) self.hass.http.register_view(PlexAuthorizationCallbackView)
hass_url = get_url(self.hass)
headers = {"Origin": hass_url}
payload = { payload = {
"X-Plex-Device-Name": X_PLEX_DEVICE_NAME, "X-Plex-Device-Name": X_PLEX_DEVICE_NAME,
"X-Plex-Version": X_PLEX_VERSION, "X-Plex-Version": X_PLEX_VERSION,
@ -298,9 +300,9 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"X-Plex-Model": "Plex OAuth", "X-Plex-Model": "Plex OAuth",
} }
session = async_get_clientsession(self.hass) session = async_get_clientsession(self.hass)
self.plexauth = PlexAuth(payload, session) self.plexauth = PlexAuth(payload, session, headers)
await self.plexauth.initiate_auth() await self.plexauth.initiate_auth()
forward_url = f"{get_url(self.hass)}{AUTH_CALLBACK_PATH}?flow_id={self.flow_id}" forward_url = f"{hass_url}{AUTH_CALLBACK_PATH}?flow_id={self.flow_id}"
auth_url = self.plexauth.auth_url(forward_url) auth_url = self.plexauth.auth_url(forward_url)
return self.async_external_step(step_id="obtain_token", url=auth_url) return self.async_external_step(step_id="obtain_token", url=auth_url)

View File

@ -4,9 +4,9 @@
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/plex", "documentation": "https://www.home-assistant.io/integrations/plex",
"requirements": [ "requirements": [
"plexapi==4.1.1", "plexapi==4.1.1",
"plexauth==0.0.5", "plexauth==0.0.6",
"plexwebsocket==0.0.12" "plexwebsocket==0.0.12"
], ],
"dependencies": ["http"], "dependencies": ["http"],
"after_dependencies": ["sonos"], "after_dependencies": ["sonos"],

View File

@ -1124,7 +1124,7 @@ pizzapi==0.0.3
plexapi==4.1.1 plexapi==4.1.1
# homeassistant.components.plex # homeassistant.components.plex
plexauth==0.0.5 plexauth==0.0.6
# homeassistant.components.plex # homeassistant.components.plex
plexwebsocket==0.0.12 plexwebsocket==0.0.12

View File

@ -541,7 +541,7 @@ pillow==7.2.0
plexapi==4.1.1 plexapi==4.1.1
# homeassistant.components.plex # homeassistant.components.plex
plexauth==0.0.5 plexauth==0.0.6
# homeassistant.components.plex # homeassistant.components.plex
plexwebsocket==0.0.12 plexwebsocket==0.0.12