Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/authprovider/authx/strategy.go
2070 views
1
package authx
2
3
import (
4
"net/http"
5
6
"github.com/projectdiscovery/retryablehttp-go"
7
)
8
9
// AuthStrategy is an interface for auth strategies
10
// basic auth , bearer token, headers, cookies, query
11
type AuthStrategy interface {
12
// Apply applies the strategy to the request
13
Apply(*http.Request)
14
// ApplyOnRR applies the strategy to the retryable request
15
ApplyOnRR(*retryablehttp.Request)
16
}
17
18
// DynamicAuthStrategy is an auth strategy for dynamic secrets
19
// it implements the AuthStrategy interface
20
type DynamicAuthStrategy struct {
21
// Dynamic is the dynamic secret to use
22
Dynamic Dynamic
23
}
24
25
// Apply applies the strategy to the request
26
func (d *DynamicAuthStrategy) Apply(req *http.Request) {
27
strategies := d.Dynamic.GetStrategies()
28
if strategies == nil {
29
return
30
}
31
for _, s := range strategies {
32
if s == nil {
33
continue
34
}
35
s.Apply(req)
36
}
37
}
38
39
// ApplyOnRR applies the strategy to the retryable request
40
func (d *DynamicAuthStrategy) ApplyOnRR(req *retryablehttp.Request) {
41
strategy := d.Dynamic.GetStrategies()
42
for _, s := range strategy {
43
s.ApplyOnRR(req)
44
}
45
}
46
47