Update Notion auth to store refresh tokens instead of account passwords (#109670)
This commit is contained in:
parent
92c3c401b9
commit
e3c838d512
12 changed files with 142 additions and 47 deletions
30
homeassistant/components/notion/util.py
Normal file
30
homeassistant/components/notion/util.py
Normal 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
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue