Skip to content

Commit 87aa7c0

Browse files
committed
Clarify token source reuse in documentation
Added comments to NewApplicationTokenSource and NewInstallationTokenSource explaining that the returned token sources are wrapped in oauth2.ReuseTokenSource to prevent unnecessary token regeneration. This helps users understand the internal behavior and avoid redundant wrapping.
1 parent 0a395b9 commit 87aa7c0

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

auth.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
6570
func NewApplicationTokenSource[T Identifier](id T, privateKey []byte, opts ...ApplicationTokenOpt) (oauth2.TokenSource, error) {
6671
var issuer string
@@ -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
187197
func NewInstallationTokenSource(id int64, src oauth2.TokenSource, opts ...InstallationTokenSourceOpt) oauth2.TokenSource {
188198
ctx := context.Background()

0 commit comments

Comments
 (0)