Skip to content

Commit

Permalink
Use SignedSession in Xbox (#133938)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored and bramkragten committed Dec 24, 2024
1 parent 7b2fc28 commit ef05133
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
10 changes: 2 additions & 8 deletions homeassistant/components/xbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import (
aiohttp_client,
config_entry_oauth2_flow,
config_validation as cv,
)
from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv

from . import api
from .const import DOMAIN
Expand All @@ -40,9 +36,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)
)
session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
auth = api.AsyncConfigEntryAuth(
aiohttp_client.async_get_clientsession(hass), session
)
auth = api.AsyncConfigEntryAuth(session)

client = XboxLiveClient(auth)
consoles: SmartglassConsoleList = await client.smartglass.get_console_list()
Expand Down
12 changes: 4 additions & 8 deletions homeassistant/components/xbox/api.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
"""API for xbox bound to Home Assistant OAuth."""

from aiohttp import ClientSession
from xbox.webapi.authentication.manager import AuthenticationManager
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


class AsyncConfigEntryAuth(AuthenticationManager):
"""Provide xbox authentication tied to an OAuth2 based config entry."""

def __init__(
self,
websession: ClientSession,
oauth_session: config_entry_oauth2_flow.OAuth2Session,
) -> None:
def __init__(self, oauth_session: OAuth2Session) -> None:
"""Initialize xbox auth."""
# Leaving out client credentials as they are handled by Home Assistant
super().__init__(websession, "", "", "")
super().__init__(SignedSession(), "", "", "")
self._oauth_session = oauth_session
self.oauth = self._get_oauth_token()

Expand Down

0 comments on commit ef05133

Please sign in to comment.