Skip to content

Add WithToken context override for per-request authentication#53

Merged
Its-donkey merged 6 commits intotestfrom
feat/per-request-token-override
Feb 6, 2026
Merged

Add WithToken context override for per-request authentication#53
Its-donkey merged 6 commits intotestfrom
feat/per-request-token-override

Conversation

@Its-donkey
Copy link
Owner

Summary

  • Adds WithToken(ctx, *Token) to allow per-request token overrides via context, enabling concurrent requests with different user tokens through a single client instance.
  • Follows the same context-override pattern as NoCacheContext, checking context token before falling back to the client-level AuthClient or TokenProvider.
  • Includes 5 new tests covering override behaviour, nil fallback, concurrency safety, and empty context.

Motivation

Endpoints like Get Channel Followers require a user token scoped to each channel (moderator:read:followers). Without per-request token overrides, users must create N separate Client instances to make concurrent requests for N different channels. WithToken solves this cleanly:

for _, channel := range channels {
    go func(ch Channel) {
        ctx := helix.WithToken(ctx, ch.UserToken)
        followers, _ := client.GetChannelFollowers(ctx, &helix.GetChannelFollowersParams{
            BroadcasterID: ch.ID,
        })
    }(channel)
}

Changes

  • helix/client.go: Added WithToken, tokenFromContext, tokenContextKey. Modified doOnceWithResponse token resolution order (context > authClient > tokenProvider).
  • helix/client_test.go: 5 new tests.

Its-donkey and others added 6 commits January 20, 2026 00:44
Release v1.1.0: Suspicious user endpoints & changelog monitor
Remove coverage badge auto-commit
Add Jekyll documentation site with custom Twitch-inspired theme
Add GitHub Pages documentation site with custom theme
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.
@Its-donkey Its-donkey changed the base branch from main to test February 6, 2026 01:24
@Its-donkey Its-donkey merged commit b615c5e into test Feb 6, 2026
9 checks passed
@Its-donkey Its-donkey deleted the feat/per-request-token-override branch February 6, 2026 01:24
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.

1 participant