Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/authprovider/interface.go
2070 views
1
package authprovider
2
3
import (
4
"fmt"
5
"net/url"
6
7
"github.com/projectdiscovery/nuclei/v3/pkg/authprovider/authx"
8
urlutil "github.com/projectdiscovery/utils/url"
9
)
10
11
var (
12
ErrNoSecrets = fmt.Errorf("no secrets in given provider")
13
)
14
15
var (
16
_ AuthProvider = &FileAuthProvider{}
17
)
18
19
// AuthProvider is an interface for auth providers
20
// It implements a data structure suitable for quick lookup and retrieval
21
// of auth strategies
22
type AuthProvider interface {
23
// LookupAddr looks up a given domain/address and returns appropriate auth strategy
24
// for it (accepted inputs are scanme.sh or scanme.sh:443)
25
LookupAddr(string) []authx.AuthStrategy
26
// LookupURL looks up a given URL and returns appropriate auth strategy
27
// it accepts a valid url struct and returns the auth strategy
28
LookupURL(*url.URL) []authx.AuthStrategy
29
// LookupURLX looks up a given URL and returns appropriate auth strategy
30
// it accepts pd url struct (i.e urlutil.URL) and returns the auth strategy
31
LookupURLX(*urlutil.URL) []authx.AuthStrategy
32
// GetTemplatePaths returns the template path for the auth provider
33
// that will be used for dynamic secret fetching
34
GetTemplatePaths() []string
35
// PreFetchSecrets pre-fetches the secrets from the auth provider
36
// instead of lazy fetching
37
PreFetchSecrets() error
38
}
39
40
// AuthProviderOptions contains options for the auth provider
41
type AuthProviderOptions struct {
42
// File based auth provider options
43
SecretsFiles []string
44
// LazyFetchSecret is a callback for lazy fetching of dynamic secrets
45
LazyFetchSecret authx.LazyFetchSecret
46
}
47
48
// NewAuthProvider creates a new auth provider from the given options
49
func NewAuthProvider(options *AuthProviderOptions) (AuthProvider, error) {
50
var providers []AuthProvider
51
for _, file := range options.SecretsFiles {
52
provider, err := NewFileAuthProvider(file, options.LazyFetchSecret)
53
if err != nil {
54
return nil, err
55
}
56
providers = append(providers, provider)
57
}
58
return NewMultiAuthProvider(providers...), nil
59
}
60
61