mirror of
https://github.com/fatedier/frp.git
synced 2026-05-15 08:05:49 -06:00
[PR #5175] [MERGED] auth/oidc: cache OIDC access token and refresh before expiry #5157
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#5157
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/5175
Author: @shani1998
Created: 2/12/2026
Status: ✅ Merged
Merged: 3/11/2026
Merged by: @fatedier
Base:
dev← Head:oidc-token-caching-on-heatbeat-enable-1📝 Commits (6)
8d1c350auth/oidc: cache OIDC access token and refresh before expirya759168address review comments71cdcc5Merge branch 'dev' of github.com:fatedier/frp into oidc-token-caching-on-heatbeat-enable-1fb75efbauth/oidc: fallback to per-request token fetch when expires_in is missinga1106f2auth/oidc: fix gosec lint and add test for zero-expiry fallback9ecf5acfix lint📊 Changes
2 files changed (+131 additions, -14 deletions)
View changed files
📝
pkg/auth/oidc.go(+40 -14)📝
pkg/auth/oidc_test.go(+91 -0)📄 Description
WHY --> Feature Request
When
auth.additionalScopesincludesHeartBeats, every heartbeat callsclientcredentials.Config.Token(ctx)which creates a newoauth2.ReuseTokenSourceon each invocation — the token is never actually reused between calls. This causes
a redundant HTTP request to the OIDC token endpoint on every heartbeat interval.
Changes
Config.TokenSource(ctx)once at init to create a persistentoauth2.TokenSourcethat caches the token and only refreshes when it approaches expiry
oauth2.ReuseTokenSourceWithExpiryfor a configurable early-refresh buffertokenRefreshAdvanceDurationconfig option (default: 300s) to control howearly before expiry the token is refreshed
multiple login and ping calls
Client Config
Test plan
TestOidcAuthProviderCachesTokenwith mock HTTP server proving only 1 token request is made across login + 5 pingsgo test ./pkg/auth/...)go vet ./pkg/auth/...cleango buildcompiles cleanlyauth.additionalScopes = ["HeartBeats"]— verified token is reused across heartbeats and refreshed only near expiry🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.