mirror of
https://github.com/fatedier/frp.git
synced 2026-05-15 08:05:49 -06:00
[PR #5174] [CLOSED] auth/oidc: cache access token to avoid redundant requests on each hea… #5156
Labels
No labels
In Progress
WIP
WaitingForInfo
bug
doc
duplicate
easy
enhancement
future
help wanted
invalid
lifecycle/stale
need-issue-template
need-usage-help
no plan
proposal
pull-request
question
todo
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/frp#5156
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/fatedier/frp/pull/5174
Author: @shani1998
Created: 2/12/2026
Status: ❌ Closed
Base:
dev← Head:oidc-token-caching-on-heatbeat-enable📝 Commits (1)
aac0cbbauth/oidc: cache access token to avoid redundant requests on each heartbeat📊 Changes
2 files changed (+60 additions, -14 deletions)
View changed files
📝
pkg/auth/oidc.go(+14 -14)📝
pkg/auth/oidc_test.go(+46 -0)📄 Description
Summary
Issue: When
AuthScopeHeartBeatsis enabled, every heartbeat ping (every ~30s) callsgenerateAccessToken()which callsclientcredentials.Config.Token(ctx). This method creates a new ReuseTokenSource(nil, ...) on every call — since it starts with nil, it always makes a fresh HTTP request to the OIDC token endpoint. Tokens are never reused despite typically being valid for minutes to hours.Fix: Call
Config.TokenSource(ctx)once during initialization and store the returnedoauth2.TokenSource. This ReuseTokenSource caches the token internally and only fetches a new one when the current token expires (with a 10s early-refresh buffer).Client Config
Test plan
TestOidcAuthProviderCachesTokenwith mock HTTP server proving only 1 token request is made across login + 5 pingsgo vet ./pkg/auth/...clean🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.