github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/apiserver/authentication/http.go (about) 1 // Copyright 2023 Canonical Ltd. All rights reserved. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package authentication 5 6 import ( 7 "fmt" 8 "net/http" 9 10 "github.com/juju/errors" 11 ) 12 13 // HTTPStrategicAuthenticator is responsible for trying multiple Authenticators 14 // until one succeeds or an error is returned that is not equal to NotFound or 15 // NotImplemented. 16 type HTTPStrategicAuthenticator []HTTPAuthenticator 17 18 // Authenticate implements HTTPAuthenticator and calls each authenticator in 19 // order. 20 func (s HTTPStrategicAuthenticator) Authenticate(req *http.Request) (AuthInfo, error) { 21 for _, authenticator := range s { 22 authInfo, err := authenticator.Authenticate(req) 23 if errors.Is(err, errors.NotImplemented) { 24 continue 25 } else if errors.Is(err, errors.NotFound) { 26 continue 27 } else if err != nil { 28 return AuthInfo{}, err 29 } 30 return authInfo, nil 31 } 32 33 return AuthInfo{}, fmt.Errorf("authenticatio %w", errors.NotFound) 34 }