Skip to content

Conversation

@bartmoorman
Copy link
Contributor

Description

ManagedHTTPClient periodically checks the validity of all managed tokens and refreshes any that have expired. This change preemptively refreshes tokens that would expire before the next validation.

Resolution for: TwitchIO v3 (view)

Example output:

2025-03-02 02:06:08,948 DEBUG    twitchio.authentication.tokens Token successfully added to TokenManager: "[redacted]"
2025-03-02 02:07:08,793 DEBUG    twitchio.authentication.tokens Attempting to revalidate all tokens that have passed the timeout on ManagedHTTPClient.
...
2025-03-02 05:53:45,330 DEBUG    twitchio.authentication.tokens Attempting to revalidate all tokens that have passed the timeout on ManagedHTTPClient.
2025-03-02 05:53:45,521 DEBUG    twitchio.authentication.tokens Token for "[redacted]" expires in 20 seconds. Attempting to refresh token.
2025-03-02 05:53:45,722 DEBUG    twitchio.authentication.tokens Token for "[redacted]" was successfully refreshed.
2025-03-02 05:54:45,722 DEBUG    twitchio.authentication.tokens Attempting to revalidate all tokens that have passed the timeout on ManagedHTTPClient.
...
2025-03-02 10:01:33,820 DEBUG    twitchio.authentication.tokens Attempting to revalidate all tokens that have passed the timeout on ManagedHTTPClient.
2025-03-02 10:01:34,007 DEBUG    twitchio.authentication.tokens Token for "[redacted]" expires in 43 seconds. Attempting to refresh token.
2025-03-02 10:01:34,205 DEBUG    twitchio.authentication.tokens Token for "[redacted]" was successfully refreshed.
2025-03-02 10:02:34,250 DEBUG    twitchio.authentication.tokens Attempting to revalidate all tokens that have passed the timeout on ManagedHTTPClient.

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
    • I have updated the changelog with a quick recap of my changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)
  • I have read and agree to the Developer Certificate of Origin for this contribution

"refresh": refresh.refresh_token,
"last_validated": datetime.datetime.now().isoformat(),
}
await self._refresh_token(data["user_id"], data["refresh"])
Copy link
Member

Choose a reason for hiding this comment

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

Since you are accessing some of these values from the dict more than once now you can likely assign them to variables before the try/except.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. :)

@EvieePy EvieePy merged commit 7ad7f4d into PythonistaGuild:main Mar 3, 2025
8 checks passed
@bartmoorman bartmoorman deleted the refresh-token-before-expire branch March 4, 2025 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants