Update Notion auth to store refresh tokens instead of account passwords (#109670)

This commit is contained in:
Aaron Bach 2024-02-12 20:35:06 -07:00 committed by GitHub
parent 92c3c401b9
commit e3c838d512
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 142 additions and 47 deletions

View file

@ -0,0 +1,30 @@
"""Define notion utilities."""
from aionotion import (
async_get_client_with_credentials as cwc,
async_get_client_with_refresh_token as cwrt,
)
from aionotion.client import Client
from homeassistant.core import HomeAssistant
from homeassistant.helpers import aiohttp_client
from homeassistant.helpers.instance_id import async_get
async def async_get_client_with_credentials(
hass: HomeAssistant, email: str, password: str
) -> Client:
"""Get a Notion client with credentials."""
session = aiohttp_client.async_get_clientsession(hass)
instance_id = await async_get(hass)
return await cwc(email, password, session=session, session_name=instance_id)
async def async_get_client_with_refresh_token(
hass: HomeAssistant, user_uuid: str, refresh_token: str
) -> Client:
"""Get a Notion client with credentials."""
session = aiohttp_client.async_get_clientsession(hass)
instance_id = await async_get(hass)
return await cwrt(
user_uuid, refresh_token, session=session, session_name=instance_id
)