Skip to content

Commit bc9c6af

Browse files
authored
baton-github: override static token with reuseToken in appClient (#123)
1 parent dca61b6 commit bc9c6af

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

pkg/connector/connector.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,16 @@ func newWithGithubApp(ctx context.Context, ghc *cfg.Github) (*GitHub, error) {
322322
return nil, err
323323
}
324324

325+
jwtts := oauth2.ReuseTokenSource(
326+
&oauth2.Token{
327+
AccessToken: jwttoken,
328+
Expiry: time.Now().Add(jwtExpiryTime),
329+
},
330+
&appJWTTokenRefresher{
331+
appID: ghc.AppId,
332+
privateKey: string(ghc.AppPrivatekeyPath),
333+
},
334+
)
325335
ts := oauth2.ReuseTokenSource(
326336
&oauth2.Token{
327337
AccessToken: token.GetToken(),
@@ -331,18 +341,17 @@ func newWithGithubApp(ctx context.Context, ghc *cfg.Github) (*GitHub, error) {
331341
ctx: ctx,
332342
instanceURL: ghc.InstanceUrl,
333343
installationID: installation.GetID(),
334-
jwtTokenSource: oauth2.ReuseTokenSource(
335-
&oauth2.Token{
336-
AccessToken: jwttoken,
337-
Expiry: time.Now().Add(jwtExpiryTime),
338-
},
339-
&appJWTTokenRefresher{
340-
appID: ghc.AppId,
341-
privateKey: string(ghc.AppPrivatekeyPath),
342-
},
343-
),
344+
jwtTokenSource: jwtts,
344345
},
345346
)
347+
// override the appClient with the reuseTokenSource.
348+
appClient, err = newGitHubClient(ctx,
349+
ghc.InstanceUrl,
350+
jwtts,
351+
)
352+
if err != nil {
353+
return nil, err
354+
}
346355

347356
ghClient, err := newGitHubClient(ctx, ghc.InstanceUrl, ts)
348357
if err != nil {

0 commit comments

Comments
 (0)