Skip to content

Commit f1d372e

Browse files
committed
Check for existing scopes in context before fetching from GitHub API in scope challenge middleware
1 parent 2022dee commit f1d372e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

pkg/http/middleware/scope_challenge.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,15 @@ func WithScopeChallenge(oauthCfg *oauth.Config, scopeFetcher scopes.FetcherInter
9494
return
9595
}
9696

97-
// Get OAuth scopes from GitHub API
98-
activeScopes, err := scopeFetcher.FetchTokenScopes(ctx, tokenInfo.Token)
99-
if err != nil {
100-
next.ServeHTTP(w, r)
101-
return
97+
// Get OAuth scopes for Token. First check if scopes are already in context, then fetch from GitHub if not present.
98+
// This allows Remote Server to pass scope info to avoid redundant GitHub API calls.
99+
activeScopes, ok := ghcontext.GetTokenScopes(ctx)
100+
if !ok {
101+
activeScopes, err = scopeFetcher.FetchTokenScopes(ctx, tokenInfo.Token)
102+
if err != nil {
103+
next.ServeHTTP(w, r)
104+
return
105+
}
102106
}
103107

104108
// Store active scopes in context for downstream use

0 commit comments

Comments
 (0)