Documentation
¶
Overview ¶
Package auth provides authentication mechanisms for the crawler.
Index ¶
- type APIKeyAuth
- func (a *APIKeyAuth) Authenticate(ctx context.Context, pool *browser.Pool) error
- func (a *APIKeyAuth) GetCookies() []*http.Cookie
- func (a *APIKeyAuth) GetHeaders() map[string]string
- func (a *APIKeyAuth) IsAuthenticated() bool
- func (a *APIKeyAuth) RefreshIfNeeded(ctx context.Context) error
- func (a *APIKeyAuth) Type() AuthType
- type AuthType
- type BasicAuth
- func (b *BasicAuth) Authenticate(ctx context.Context, pool *browser.Pool) error
- func (b *BasicAuth) GetCookies() []*http.Cookie
- func (b *BasicAuth) GetHeaders() map[string]string
- func (b *BasicAuth) IsAuthenticated() bool
- func (b *BasicAuth) RefreshIfNeeded(ctx context.Context) error
- func (b *BasicAuth) Type() AuthType
- type Credentials
- type FormLoginAuth
- func (f *FormLoginAuth) Authenticate(ctx context.Context, pool *browser.Pool) error
- func (f *FormLoginAuth) GetCookies() []*http.Cookie
- func (f *FormLoginAuth) GetHeaders() map[string]string
- func (f *FormLoginAuth) IsAuthenticated() bool
- func (f *FormLoginAuth) RefreshIfNeeded(ctx context.Context) error
- func (f *FormLoginAuth) SetSessionLifetime(duration time.Duration)
- func (f *FormLoginAuth) Type() AuthType
- type JWTAuth
- func (j *JWTAuth) Authenticate(ctx context.Context, pool *browser.Pool) error
- func (j *JWTAuth) GetCookies() []*http.Cookie
- func (j *JWTAuth) GetExpiry() time.Time
- func (j *JWTAuth) GetHeaders() map[string]string
- func (j *JWTAuth) GetToken() string
- func (j *JWTAuth) IsAuthenticated() bool
- func (j *JWTAuth) RefreshIfNeeded(ctx context.Context) error
- func (j *JWTAuth) SetToken(token string)
- func (j *JWTAuth) TimeUntilExpiry() time.Duration
- func (j *JWTAuth) Type() AuthType
- type NoAuth
- func (n *NoAuth) Authenticate(ctx context.Context, pool *browser.Pool) error
- func (n *NoAuth) GetCookies() []*http.Cookie
- func (n *NoAuth) GetHeaders() map[string]string
- func (n *NoAuth) IsAuthenticated() bool
- func (n *NoAuth) RefreshIfNeeded(ctx context.Context) error
- func (n *NoAuth) Type() AuthType
- type OAuthAuth
- func (o *OAuthAuth) Authenticate(ctx context.Context, pool *browser.Pool) error
- func (o *OAuthAuth) GetCookies() []*http.Cookie
- func (o *OAuthAuth) GetHeaders() map[string]string
- func (o *OAuthAuth) IsAuthenticated() bool
- func (o *OAuthAuth) RefreshIfNeeded(ctx context.Context) error
- func (o *OAuthAuth) Type() AuthType
- type OAuthConfig
- type Provider
- type SessionAuth
- func (s *SessionAuth) AddCookie(cookie *http.Cookie)
- func (s *SessionAuth) Authenticate(ctx context.Context, pool *browser.Pool) error
- func (s *SessionAuth) ClearCookies()
- func (s *SessionAuth) GetCookie(name string) *http.Cookie
- func (s *SessionAuth) GetCookies() []*http.Cookie
- func (s *SessionAuth) GetHeaders() map[string]string
- func (s *SessionAuth) IsAuthenticated() bool
- func (s *SessionAuth) RefreshIfNeeded(ctx context.Context) error
- func (s *SessionAuth) SetCookies(cookies []*http.Cookie)
- func (s *SessionAuth) Type() AuthType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIKeyAuth ¶
type APIKeyAuth struct {
// contains filtered or unexported fields
}
APIKeyAuth provides API key authentication.
func NewAPIKeyAuth ¶
func NewAPIKeyAuth(headers map[string]string) *APIKeyAuth
NewAPIKeyAuth creates a new API key authentication provider.
func (*APIKeyAuth) Authenticate ¶
Authenticate is a no-op for API key auth.
func (*APIKeyAuth) GetCookies ¶
func (a *APIKeyAuth) GetCookies() []*http.Cookie
GetCookies returns no cookies for API key auth.
func (*APIKeyAuth) GetHeaders ¶
func (a *APIKeyAuth) GetHeaders() map[string]string
GetHeaders returns the API key headers.
func (*APIKeyAuth) IsAuthenticated ¶
func (a *APIKeyAuth) IsAuthenticated() bool
IsAuthenticated returns true if headers are set.
func (*APIKeyAuth) RefreshIfNeeded ¶
func (a *APIKeyAuth) RefreshIfNeeded(ctx context.Context) error
RefreshIfNeeded is a no-op for API key auth.
func (*APIKeyAuth) Type ¶
func (a *APIKeyAuth) Type() AuthType
Type returns the authentication type.
type BasicAuth ¶
type BasicAuth struct {
// contains filtered or unexported fields
}
BasicAuth provides HTTP Basic authentication.
func NewBasicAuth ¶
NewBasicAuth creates a new Basic authentication provider.
func (*BasicAuth) Authenticate ¶
Authenticate is a no-op for Basic auth.
func (*BasicAuth) GetCookies ¶
GetCookies returns no cookies for Basic auth.
func (*BasicAuth) GetHeaders ¶
GetHeaders returns the Authorization header.
func (*BasicAuth) IsAuthenticated ¶
IsAuthenticated returns true if credentials are set.
func (*BasicAuth) RefreshIfNeeded ¶
RefreshIfNeeded is a no-op for Basic auth.
type Credentials ¶
type Credentials struct {
Type AuthType
Username string
Password string
Token string
Headers map[string]string
Cookies []*http.Cookie
LoginURL string
FormFields map[string]string
OAuthConfig *OAuthConfig
}
Credentials holds authentication credentials.
type FormLoginAuth ¶
type FormLoginAuth struct {
// contains filtered or unexported fields
}
FormLoginAuth provides form-based login authentication.
func NewFormLoginAuth ¶
func NewFormLoginAuth(creds Credentials) *FormLoginAuth
NewFormLoginAuth creates a new form login authentication provider.
func (*FormLoginAuth) Authenticate ¶
Authenticate performs form-based login.
func (*FormLoginAuth) GetCookies ¶
func (f *FormLoginAuth) GetCookies() []*http.Cookie
GetCookies returns the session cookies.
func (*FormLoginAuth) GetHeaders ¶
func (f *FormLoginAuth) GetHeaders() map[string]string
GetHeaders returns no headers for form login.
func (*FormLoginAuth) IsAuthenticated ¶
func (f *FormLoginAuth) IsAuthenticated() bool
IsAuthenticated returns true if we have session cookies.
func (*FormLoginAuth) RefreshIfNeeded ¶
func (f *FormLoginAuth) RefreshIfNeeded(ctx context.Context) error
RefreshIfNeeded re-authenticates if the session may have expired.
func (*FormLoginAuth) SetSessionLifetime ¶
func (f *FormLoginAuth) SetSessionLifetime(duration time.Duration)
SetSessionLifetime sets how long a session is considered valid.
func (*FormLoginAuth) Type ¶
func (f *FormLoginAuth) Type() AuthType
Type returns the authentication type.
type JWTAuth ¶
type JWTAuth struct {
// contains filtered or unexported fields
}
JWTAuth provides JWT-based authentication.
func NewJWTAuth ¶
NewJWTAuth creates a new JWT authentication provider.
func NewJWTAuthWithRefresh ¶
NewJWTAuthWithRefresh creates a JWT auth with refresh capability.
func (*JWTAuth) Authenticate ¶
Authenticate sets up JWT authentication.
func (*JWTAuth) GetCookies ¶
GetCookies returns no cookies for JWT auth.
func (*JWTAuth) GetHeaders ¶
GetHeaders returns the Authorization header.
func (*JWTAuth) IsAuthenticated ¶
IsAuthenticated returns true if we have a valid token.
func (*JWTAuth) RefreshIfNeeded ¶
RefreshIfNeeded refreshes the token if expired or expiring soon.
func (*JWTAuth) TimeUntilExpiry ¶
TimeUntilExpiry returns the time until the token expires.
type NoAuth ¶
type NoAuth struct{}
NoAuth represents no authentication.
func (*NoAuth) Authenticate ¶
func (*NoAuth) GetCookies ¶
func (*NoAuth) GetHeaders ¶
func (*NoAuth) IsAuthenticated ¶
type OAuthAuth ¶
type OAuthAuth struct {
// contains filtered or unexported fields
}
OAuthAuth provides OAuth 2.0 authentication.
func NewOAuthAuth ¶
func NewOAuthAuth(config *OAuthConfig) *OAuthAuth
NewOAuthAuth creates a new OAuth authentication provider.
func (*OAuthAuth) Authenticate ¶
Authenticate performs OAuth authentication.
func (*OAuthAuth) GetCookies ¶
GetCookies returns no cookies for OAuth.
func (*OAuthAuth) GetHeaders ¶
GetHeaders returns the Authorization header.
func (*OAuthAuth) IsAuthenticated ¶
IsAuthenticated returns true if we have a valid token.
func (*OAuthAuth) RefreshIfNeeded ¶
RefreshIfNeeded refreshes the token if needed.
type OAuthConfig ¶
type OAuthConfig struct {
ClientID string
ClientSecret string
AuthURL string
TokenURL string
RedirectURL string
Scopes []string
}
OAuthConfig holds OAuth 2.0 configuration.
type Provider ¶
type Provider interface {
// Authenticate performs authentication
Authenticate(ctx context.Context, browserPool *browser.Pool) error
// GetHeaders returns headers to include in requests
GetHeaders() map[string]string
// GetCookies returns cookies to include in requests
GetCookies() []*http.Cookie
// RefreshIfNeeded refreshes the authentication if needed
RefreshIfNeeded(ctx context.Context) error
// IsAuthenticated returns true if currently authenticated
IsAuthenticated() bool
// Type returns the authentication type
Type() AuthType
}
Provider defines the interface for authentication providers.
func NewProvider ¶
func NewProvider(creds Credentials) (Provider, error)
NewProvider creates an authentication provider based on credentials.
type SessionAuth ¶
type SessionAuth struct {
// contains filtered or unexported fields
}
SessionAuth provides session/cookie-based authentication.
func NewSessionAuth ¶
func NewSessionAuth(cookies []*http.Cookie) *SessionAuth
NewSessionAuth creates a new session authentication provider.
func (*SessionAuth) AddCookie ¶
func (s *SessionAuth) AddCookie(cookie *http.Cookie)
AddCookie adds a cookie to the session.
func (*SessionAuth) Authenticate ¶
Authenticate sets up session authentication.
func (*SessionAuth) ClearCookies ¶
func (s *SessionAuth) ClearCookies()
ClearCookies removes all cookies.
func (*SessionAuth) GetCookie ¶
func (s *SessionAuth) GetCookie(name string) *http.Cookie
GetCookie returns a specific cookie by name.
func (*SessionAuth) GetCookies ¶
func (s *SessionAuth) GetCookies() []*http.Cookie
GetCookies returns the session cookies.
func (*SessionAuth) GetHeaders ¶
func (s *SessionAuth) GetHeaders() map[string]string
GetHeaders returns empty headers for session auth.
func (*SessionAuth) IsAuthenticated ¶
func (s *SessionAuth) IsAuthenticated() bool
IsAuthenticated returns true if cookies are set.
func (*SessionAuth) RefreshIfNeeded ¶
func (s *SessionAuth) RefreshIfNeeded(ctx context.Context) error
RefreshIfNeeded checks if cookies need refresh.
func (*SessionAuth) SetCookies ¶
func (s *SessionAuth) SetCookies(cookies []*http.Cookie)
SetCookies updates the session cookies.
func (*SessionAuth) Type ¶
func (s *SessionAuth) Type() AuthType
Type returns the authentication type.