mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use new reauth helpers in yale (#128828)
This commit is contained in:
parent
d9c61a37bb
commit
5228aa5e5c
@ -6,7 +6,7 @@ from typing import Any
|
|||||||
|
|
||||||
import jwt
|
import jwt
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlowResult
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlowResult
|
||||||
from homeassistant.helpers import config_entry_oauth2_flow
|
from homeassistant.helpers import config_entry_oauth2_flow
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -19,7 +19,6 @@ class YaleConfigFlow(config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
DOMAIN = DOMAIN
|
DOMAIN = DOMAIN
|
||||||
reauth_entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def logger(self) -> logging.Logger:
|
def logger(self) -> logging.Logger:
|
||||||
@ -30,9 +29,6 @@ class YaleConfigFlow(config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle configuration by re-auth."""
|
"""Handle configuration by re-auth."""
|
||||||
self.reauth_entry = self.hass.config_entries.async_get_entry(
|
|
||||||
self.context["entry_id"]
|
|
||||||
)
|
|
||||||
return await self.async_step_user()
|
return await self.async_step_user()
|
||||||
|
|
||||||
def _async_get_user_id_from_access_token(self, encoded: str) -> str:
|
def _async_get_user_id_from_access_token(self, encoded: str) -> str:
|
||||||
@ -51,10 +47,11 @@ class YaleConfigFlow(config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=
|
|||||||
user_id = self._async_get_user_id_from_access_token(
|
user_id = self._async_get_user_id_from_access_token(
|
||||||
data["token"]["access_token"]
|
data["token"]["access_token"]
|
||||||
)
|
)
|
||||||
if entry := self.reauth_entry:
|
|
||||||
if entry.unique_id != user_id:
|
|
||||||
return self.async_abort(reason="reauth_invalid_user")
|
|
||||||
return self.async_update_reload_and_abort(entry, data=data)
|
|
||||||
await self.async_set_unique_id(user_id)
|
await self.async_set_unique_id(user_id)
|
||||||
|
if self.source == SOURCE_REAUTH:
|
||||||
|
self._abort_if_unique_id_mismatch(reason="reauth_invalid_user")
|
||||||
|
return self.async_update_reload_and_abort(
|
||||||
|
self._get_reauth_entry(), data=data
|
||||||
|
)
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
return await super().async_oauth_create_entry(data)
|
return await super().async_oauth_create_entry(data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user