Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/authprovider/authx/bearer_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 = &BearerTokenAuthStrategy{}
11
)
12
13
// BearerTokenAuthStrategy is a strategy for bearer token auth
14
type BearerTokenAuthStrategy struct {
15
Data *Secret
16
}
17
18
// NewBearerTokenAuthStrategy creates a new bearer token auth strategy
19
func NewBearerTokenAuthStrategy(data *Secret) *BearerTokenAuthStrategy {
20
return &BearerTokenAuthStrategy{Data: data}
21
}
22
23
// Apply applies the bearer token auth strategy to the request
24
func (s *BearerTokenAuthStrategy) Apply(req *http.Request) {
25
req.Header.Set("Authorization", "Bearer "+s.Data.Token)
26
}
27
28
// ApplyOnRR applies the bearer token auth strategy to the retryable request
29
func (s *BearerTokenAuthStrategy) ApplyOnRR(req *retryablehttp.Request) {
30
req.Header.Set("Authorization", "Bearer "+s.Data.Token)
31
}
32
33