Skip to content

plugins.twitch: refactor Twitch._access_token() #6403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

bastimeyer
Copy link
Member

A couple of code refactor commits.

The initial motivation for these changes was adding authentication debug log messages. But then I decided against adding this, as it's unnecessary. If the Authorization Twitch API HTTP header has an invalid value, acquiring an access token will fail with an error message that perfectly describes the error. No auth and valid auth data pass silently. We don't need to log this and the user's name. Doing this only bloats up the GQL access token request by also querying VerifyEmail_CurrentUser (the most sensible query I could find on their website) and doing additional error handling.


  1. Refactor tests for easier test-setup of plugin options
  2. Refactor logic for acquiring an access token and fix duplicate GQL requests for VOD when client-integrity token is forced
  3. Refactor TwitchAPI class and fix validation schemas

I'm going to leave this open for a bit and have another look later some time, to ensure there's no mistake which I didn't spot yet...

Avoid acquiring a VOD access token twice on error.

In other words, only use the client-integrity token fallback mechanism
for live streams if the first access token API request failed.

Add more tests for full branch coverage.
@bastimeyer bastimeyer added plugin issue A Plugin does not work correctly cleanup labels Jan 16, 2025
Avoid calling HTTPSession.json() and update/fix validation schemas
of various Twitch GQL API calls.
@bastimeyer bastimeyer force-pushed the plugins/twitch/refactor-access-token branch from 69bde39 to 3477a2b Compare January 17, 2025 17:15
@bastimeyer bastimeyer merged commit 0c2349d into streamlink:master Jan 17, 2025
23 checks passed
@bastimeyer bastimeyer deleted the plugins/twitch/refactor-access-token branch January 17, 2025 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup plugin issue A Plugin does not work correctly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant