github.com/Jeffail/benthos/v3@v3.65.0/lib/util/http/auth/basic.go (about)

     1  package auth
     2  
     3  import "net/http"
     4  
     5  //------------------------------------------------------------------------------
     6  
     7  // BasicAuthConfig contains fields for setting basic authentication in HTTP
     8  // requests.
     9  type BasicAuthConfig struct {
    10  	Enabled  bool   `json:"enabled" yaml:"enabled"`
    11  	Username string `json:"username" yaml:"username"`
    12  	Password string `json:"password" yaml:"password"`
    13  }
    14  
    15  // NewBasicAuthConfig returns a default configuration for basic authentication
    16  // in HTTP client requests.
    17  func NewBasicAuthConfig() BasicAuthConfig {
    18  	return BasicAuthConfig{
    19  		Enabled:  false,
    20  		Username: "",
    21  		Password: "",
    22  	}
    23  }
    24  
    25  //------------------------------------------------------------------------------
    26  
    27  // Sign method to sign an HTTP request for an OAuth exchange.
    28  func (basic BasicAuthConfig) Sign(req *http.Request) error {
    29  	if basic.Enabled {
    30  		req.SetBasicAuth(basic.Username, basic.Password)
    31  	}
    32  	return nil
    33  }
    34  
    35  //------------------------------------------------------------------------------