Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/authprovider/authx/basic_auth.go
2070 views
1
package authx
2
3
import (
4
"net/http"
5
6
"github.com/projectdiscovery/retryablehttp-go"
7
)
8
9
var (
10
_ AuthStrategy = &BasicAuthStrategy{}
11
)
12
13
// BasicAuthStrategy is a strategy for basic auth
14
type BasicAuthStrategy struct {
15
Data *Secret
16
}
17
18
// NewBasicAuthStrategy creates a new basic auth strategy
19
func NewBasicAuthStrategy(data *Secret) *BasicAuthStrategy {
20
return &BasicAuthStrategy{Data: data}
21
}
22
23
// Apply applies the basic auth strategy to the request
24
func (s *BasicAuthStrategy) Apply(req *http.Request) {
25
req.SetBasicAuth(s.Data.Username, s.Data.Password)
26
}
27
28
// ApplyOnRR applies the basic auth strategy to the retryable request
29
func (s *BasicAuthStrategy) ApplyOnRR(req *retryablehttp.Request) {
30
req.SetBasicAuth(s.Data.Username, s.Data.Password)
31
}
32
33