@@ -3,16 +3,11 @@ package oidc
33import (
44 "context"
55 "fmt"
6- "net/http"
76 "net/url"
87 "sync"
98 "time"
109
11- "github.com/elazarl/goproxy"
12-
1310 "github.com/dependabot/proxy/internal/config"
14- "github.com/dependabot/proxy/internal/helpers"
15- "github.com/dependabot/proxy/internal/logging"
1611)
1712
1813type OIDCParameters interface {
@@ -203,40 +198,3 @@ func GetOrRefreshOIDCToken(cred *OIDCCredential, ctx context.Context) (string, e
203198
204199 return oidcAccessToken .Token , nil
205200}
206-
207- // TryAuthOIDCRequestWithPrefix tries to authenticate the request using OIDC credentials if available
208- func TryAuthOIDCRequestWithPrefix (mutex * sync.RWMutex , oidcCredentials map [string ]* OIDCCredential , req * http.Request , ctx * goproxy.ProxyCtx ) bool {
209- // Find matching credential while holding the lock, then release before token refresh
210- var matchedCred * OIDCCredential
211- if len (oidcCredentials ) > 0 {
212- mutex .RLock ()
213- for key , oidcCred := range oidcCredentials {
214- // Match by URL or host
215- if helpers .UrlMatchesRequest (req , key , true ) || helpers .CheckHost (req , key ) {
216- matchedCred = oidcCred
217- break
218- }
219- }
220- mutex .RUnlock ()
221- }
222-
223- if matchedCred != nil {
224- token , err := GetOrRefreshOIDCToken (matchedCred , req .Context ())
225- if err != nil {
226- logging .RequestLogf (ctx , "* failed to get %s token via OIDC for %s: %v" , matchedCred .Provider (), req .URL .Hostname (), err )
227- } else {
228- switch matchedCred .parameters .(type ) {
229- case * CloudsmithOIDCParameters :
230- logging .RequestLogf (ctx , "* authenticating request with OIDC API key (host: %s)" , req .URL .Hostname ())
231- req .Header .Set ("X-Api-Key" , token )
232- default :
233- logging .RequestLogf (ctx , "* authenticating request with OIDC token (host: %s)" , req .URL .Hostname ())
234- req .Header .Set ("Authorization" , fmt .Sprintf ("Bearer %s" , token ))
235- }
236-
237- return true
238- }
239- }
240-
241- return false
242- }
0 commit comments