@@ -61,6 +61,11 @@ func WithApplicationTokenExpiration(exp time.Duration) ApplicationTokenOpt {
6161// Accepts either int64 App ID or string Client ID. GitHub recommends Client IDs for new apps.
6262// Private key must be in PEM format. Generated JWTs are RS256-signed with iat, exp, and iss claims.
6363// JWTs expire in max 10 minutes and include clock drift protection (iat set 60s in past).
64+ //
65+ // The returned token source is wrapped in oauth2.ReuseTokenSource to prevent unnecessary
66+ // token regeneration. Don't worry about wrapping the result again since ReuseTokenSource
67+ // prevents re-wrapping automatically.
68+ //
6469// See https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-json-web-token-jwt-for-a-github-app
6570func NewApplicationTokenSource [T Identifier ](id T , privateKey []byte , opts ... ApplicationTokenOpt ) (oauth2.TokenSource , error ) {
6671 var issuer string
@@ -97,7 +102,7 @@ func NewApplicationTokenSource[T Identifier](id T, privateKey []byte, opts ...Ap
97102 opt (t )
98103 }
99104
100- return t , nil
105+ return oauth2 . ReuseTokenSource ( nil , t ) , nil
101106}
102107
103108// Token generates a GitHub App JWT with required claims: iat, exp, iss, and alg.
@@ -183,6 +188,11 @@ type installationTokenSource struct {
183188
184189// NewInstallationTokenSource creates a GitHub App installation token source.
185190// Requires installation ID and a GitHub App JWT token source for authentication.
191+ //
192+ // The returned token source is wrapped in oauth2.ReuseTokenSource to prevent unnecessary
193+ // token regeneration. Don't worry about wrapping the result again since ReuseTokenSource
194+ // prevents re-wrapping automatically.
195+ //
186196// See https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token
187197func NewInstallationTokenSource (id int64 , src oauth2.TokenSource , opts ... InstallationTokenSourceOpt ) oauth2.TokenSource {
188198 ctx := context .Background ()
0 commit comments