Add WithToken context override for per-request authentication#54
Closed
Its-donkey wants to merge 1 commit intomainfrom
Closed
Add WithToken context override for per-request authentication#54Its-donkey wants to merge 1 commit intomainfrom
Its-donkey wants to merge 1 commit intomainfrom
Conversation
Allow callers to override the client-level token on a per-request basis using WithToken(ctx, token). This enables concurrent requests with different user tokens through a single client instance, following the same context-override pattern as NoCacheContext. Updated documentation across changelog, auth reference, advanced features, quickstart, examples, FAQ, troubleshooting, and cookbook.
Owner
Author
|
Closing - PRs should target test branch per promotion workflow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WithToken(ctx, *Token)for per-request token overrides via context, enabling concurrent requests with different user tokens through a single client instanceNoCacheContextMotivation
Endpoints like
Get Channel Followersrequire a user token scoped to each channel (moderator:read:followers). Without per-request token overrides, users must create N separateClientinstances to make concurrent requests for N different channels.WithTokensolves this:Changes
Code:
helix/client.go: AddedWithToken,tokenFromContext,tokenContextKey. ModifieddoOnceWithResponsetoken resolution order (context > authClient > tokenProvider)helix/client_test.go: 5 new testsDocumentation:
CHANGELOG.md: Added unreleased entrydocs/auth.md: New "WithToken (Per-Request Override)" section under Token Helpersdocs/advanced.md: New "Per-Request Token Override" section with concurrent multi-token exampledocs/quickstart.md: Added WithToken to Token Management snippetdocs/examples/authentication.md: New "Per-Request Token Override" section with full working exampledocs/examples/batch-caching.md: New "Concurrent Requests with Different Tokens" sectiondocs/faq.md: New FAQ entry "Can I use different tokens for different requests?"docs/troubleshooting.md: Added WithToken + Client ID mismatch pitfall notedocs/cookbook.md: Added index entries for per-request token override