mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-18 23:06:31 +00:00
Update OAuth reauth with simpler example (#1483)
This commit is contained in:
parent
90bcb7f3f4
commit
23fa78ae52
@ -267,8 +267,13 @@ class OAuth2FlowHandler(
|
|||||||
):
|
):
|
||||||
"""Config flow to handle OAuth2 authentication."""
|
"""Config flow to handle OAuth2 authentication."""
|
||||||
|
|
||||||
|
reauth_entry: ConfigEntry | None = None
|
||||||
|
|
||||||
async def async_step_reauth(self, user_input=None):
|
async def async_step_reauth(self, user_input=None):
|
||||||
"""Perform reauth upon an API authentication error."""
|
"""Perform reauth upon an API authentication error."""
|
||||||
|
self.reauth_entry = self.hass.config_entries.async_get_entry(
|
||||||
|
self.context["entry_id"]
|
||||||
|
)
|
||||||
return await self.async_step_reauth_confirm()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(self, user_input=None):
|
async def async_step_reauth_confirm(self, user_input=None):
|
||||||
@ -282,12 +287,9 @@ class OAuth2FlowHandler(
|
|||||||
|
|
||||||
async def async_oauth_create_entry(self, data: dict) -> dict:
|
async def async_oauth_create_entry(self, data: dict) -> dict:
|
||||||
"""Create an oauth config entry or update existing entry for reauth."""
|
"""Create an oauth config entry or update existing entry for reauth."""
|
||||||
# TODO: This example supports only a single config entry. Consider
|
if self._reauth_entry:
|
||||||
# any special handling needed for multiple config entries.
|
self.hass.config_entries.async_update_entry(self.reauth_entry, data=data)
|
||||||
existing_entry = await self.async_set_unique_id(DOMAIN)
|
await self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
|
||||||
if existing_entry:
|
|
||||||
self.hass.config_entries.async_update_entry(existing_entry, data=data)
|
|
||||||
await self.hass.config_entries.async_reload(existing_entry.entry_id)
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
return self.async_abort(reason="reauth_successful")
|
||||||
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