mirror of
https://github.com/fatedier/frp.git
synced 2026-05-15 16:15:49 -06:00
[GH-ISSUE #5185] [Feature Request] Cache OIDC access token and refresh before expiry #4051
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#4051
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?
Originally created by @shani1998 on GitHub (Feb 25, 2026).
Original GitHub issue: https://github.com/fatedier/frp/issues/5185
Originally assigned to: @blizard863 on GitHub.
Describe the feature request
Current Behavior:
In the current OIDC implementation for
frpc, a new access token is requested from the OIDC provider for every authentication event. This creates significant overhead during:frpcandfrpsfrequently exchange pings to keep the connection alive. Fetching a new token for every validation cycle increases latency.Proposed Feature:
Implement a caching and proactive refresh mechanism for OIDC tokens within
frpcto improve performance and reliability.Key Components of the Proposal:
tokenRefreshAdvanceDuration.300seconds (5 minutes).frpcshould proactively fetch a new token.frpcalways has a valid token ready before the next heartbeat, preventing connection drops due to expired credentials during transit.This change reduces the load on OIDC providers and ensures that
frpcremains connected even if the OIDC provider has temporary high latency.I have already drafted this implementation in PR #5175 and would love to discuss the configuration logic here.
Describe alternatives you've considered
The current "fetch-on-demand" approach is the only alternative, but it is inefficient for users with high-frequency heartbeats or strict OIDC rate limits.
Affected area
@blizard863 commented on GitHub (Feb 26, 2026):
Thanks for the contribution! The caching idea is solid and addresses a real problem. A few suggestions before merging:
Remove tokenRefreshAdvanceDuration config option
We should avoid introducing new user-facing configuration unless absolutely necessary. Every new field adds cognitive overhead for users. In practice, no mainstream OAuth2 SDK asks users to configure refresh timing — it's handled internally.
Use expires_in from the token response to drive refresh
The token endpoint response already includes expires_in, so we have everything needed to determine when to refresh. The caching and proactive refresh logic should be fully automatic — users get the optimization by default without needing to understand OAuth2 token lifecycle.
Keep backward compatibility transparent
With automatic refresh, the behavior change is purely an internal optimization. Existing users benefit automatically without any config migration, and the external API surface remains unchanged.
@shani1998 commented on GitHub (Feb 28, 2026):
Thanks for making time to review the proposal. The suggestions make sense to me. I’ve updated the code to rely on the OAuth2 SDK and to use expires_in with the default 10-second delta.https://cs.opensource.google/go/x/oauth2/+/master:token.go