Use SignedSession in Xbox (#133938)

This commit is contained in:
Joost Lekkerkerker 2024-12-24 10:17:02 +01:00 committed by GitHub
parent a9d6a42781
commit 6fc1cfded9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 16 deletions

View File

@ -10,11 +10,7 @@ from xbox.webapi.api.provider.smartglass.models import SmartglassConsoleList
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import ( from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv
aiohttp_client,
config_entry_oauth2_flow,
config_validation as cv,
)
from . import api from . import api
from .const import DOMAIN from .const import DOMAIN
@ -40,9 +36,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
) )
) )
session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation) session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
auth = api.AsyncConfigEntryAuth( auth = api.AsyncConfigEntryAuth(session)
aiohttp_client.async_get_clientsession(hass), session
)
client = XboxLiveClient(auth) client = XboxLiveClient(auth)
consoles: SmartglassConsoleList = await client.smartglass.get_console_list() consoles: SmartglassConsoleList = await client.smartglass.get_console_list()

View File

@ -1,24 +1,20 @@
"""API for xbox bound to Home Assistant OAuth.""" """API for xbox bound to Home Assistant OAuth."""
from aiohttp import ClientSession
from xbox.webapi.authentication.manager import AuthenticationManager from xbox.webapi.authentication.manager import AuthenticationManager
from xbox.webapi.authentication.models import OAuth2TokenResponse from xbox.webapi.authentication.models import OAuth2TokenResponse
from xbox.webapi.common.signed_session import SignedSession
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers.config_entry_oauth2_flow import OAuth2Session
from homeassistant.util.dt import utc_from_timestamp from homeassistant.util.dt import utc_from_timestamp
class AsyncConfigEntryAuth(AuthenticationManager): class AsyncConfigEntryAuth(AuthenticationManager):
"""Provide xbox authentication tied to an OAuth2 based config entry.""" """Provide xbox authentication tied to an OAuth2 based config entry."""
def __init__( def __init__(self, oauth_session: OAuth2Session) -> None:
self,
websession: ClientSession,
oauth_session: config_entry_oauth2_flow.OAuth2Session,
) -> None:
"""Initialize xbox auth.""" """Initialize xbox auth."""
# Leaving out client credentials as they are handled by Home Assistant # Leaving out client credentials as they are handled by Home Assistant
super().__init__(websession, "", "", "") super().__init__(SignedSession(), "", "", "")
self._oauth_session = oauth_session self._oauth_session = oauth_session
self.oauth = self._get_oauth_token() self.oauth = self._get_oauth_token()