Skip to content

Add support to reauthorize expired Plex tokens#40469

Merged
balloob merged 3 commits into
home-assistant:devfrom
jjlawren:plex_reauthorize_flow
Sep 28, 2020
Merged

Add support to reauthorize expired Plex tokens#40469
balloob merged 3 commits into
home-assistant:devfrom
jjlawren:plex_reauthorize_flow

Conversation

@jjlawren
Copy link
Copy Markdown
Contributor

@jjlawren jjlawren commented Sep 22, 2020

Proposed change

The integration currently needs to be removed and recreated if an authentication token expires. This detects an expired token and begins a config flow to reauthorize while preserving entities/options/etc.

If an expired token is detected during runtime, the integration will reload itself to avoid continuous logging errors and trigger the reauth step.

Currently does not handle reauthorizing in advanced mode as the reauth flow is created by the backend while that flag is set by the frontend.

Example reconfiguration alert from Integrations page:
image

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@jjlawren jjlawren force-pushed the plex_reauthorize_flow branch from ac8971f to e01bbe3 Compare September 23, 2020 18:04
@balloob balloob merged commit 3596eb3 into home-assistant:dev Sep 28, 2020
self.context[CONF_SOURCE] # pylint: disable=no-member
== config_entries.SOURCE_REAUTH
):
entry = self.hass.config_entries.async_get_entry(self._entry_id)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the unique id for an existing entry will return that entry. Looks like we can simplify this and not store the entry id.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, cleaned up in #41000.

@jjlawren jjlawren deleted the plex_reauthorize_flow branch May 31, 2022 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants