auth

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package auth provides authentication mechanisms for the crawler.

Index

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

func (a *APIKeyAuth) Authenticate(ctx context.Context, pool *browser.Pool) error

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 AuthType

type AuthType string

AuthType represents the type of authentication.

const (
	AuthTypeNone      AuthType = "none"
	AuthTypeSession   AuthType = "session"
	AuthTypeJWT       AuthType = "jwt"
	AuthTypeOAuth     AuthType = "oauth"
	AuthTypeFormLogin AuthType = "form"
	AuthTypeAPIKey    AuthType = "apikey"
	AuthTypeBasic     AuthType = "basic"
)

type BasicAuth

type BasicAuth struct {
	// contains filtered or unexported fields
}

BasicAuth provides HTTP Basic authentication.

func NewBasicAuth

func NewBasicAuth(username, password string) *BasicAuth

NewBasicAuth creates a new Basic authentication provider.

func (*BasicAuth) Authenticate

func (b *BasicAuth) Authenticate(ctx context.Context, pool *browser.Pool) error

Authenticate is a no-op for Basic auth.

func (*BasicAuth) GetCookies

func (b *BasicAuth) GetCookies() []*http.Cookie

GetCookies returns no cookies for Basic auth.

func (*BasicAuth) GetHeaders

func (b *BasicAuth) GetHeaders() map[string]string

GetHeaders returns the Authorization header.

func (*BasicAuth) IsAuthenticated

func (b *BasicAuth) IsAuthenticated() bool

IsAuthenticated returns true if credentials are set.

func (*BasicAuth) RefreshIfNeeded

func (b *BasicAuth) RefreshIfNeeded(ctx context.Context) error

RefreshIfNeeded is a no-op for Basic auth.

func (*BasicAuth) Type

func (b *BasicAuth) Type() AuthType

Type returns the authentication type.

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

func (f *FormLoginAuth) Authenticate(ctx context.Context, pool *browser.Pool) error

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

func NewJWTAuth(token string) *JWTAuth

NewJWTAuth creates a new JWT authentication provider.

func NewJWTAuthWithRefresh

func NewJWTAuthWithRefresh(token, refreshToken, refreshURL string) *JWTAuth

NewJWTAuthWithRefresh creates a JWT auth with refresh capability.

func (*JWTAuth) Authenticate

func (j *JWTAuth) Authenticate(ctx context.Context, pool *browser.Pool) error

Authenticate sets up JWT authentication.

func (*JWTAuth) GetCookies

func (j *JWTAuth) GetCookies() []*http.Cookie

GetCookies returns no cookies for JWT auth.

func (*JWTAuth) GetExpiry

func (j *JWTAuth) GetExpiry() time.Time

GetExpiry returns the token expiry time.

func (*JWTAuth) GetHeaders

func (j *JWTAuth) GetHeaders() map[string]string

GetHeaders returns the Authorization header.

func (*JWTAuth) GetToken

func (j *JWTAuth) GetToken() string

GetToken returns the current token.

func (*JWTAuth) IsAuthenticated

func (j *JWTAuth) IsAuthenticated() bool

IsAuthenticated returns true if we have a valid token.

func (*JWTAuth) RefreshIfNeeded

func (j *JWTAuth) RefreshIfNeeded(ctx context.Context) error

RefreshIfNeeded refreshes the token if expired or expiring soon.

func (*JWTAuth) SetToken

func (j *JWTAuth) SetToken(token string)

SetToken updates the JWT token.

func (*JWTAuth) TimeUntilExpiry

func (j *JWTAuth) TimeUntilExpiry() time.Duration

TimeUntilExpiry returns the time until the token expires.

func (*JWTAuth) Type

func (j *JWTAuth) Type() AuthType

Type returns the authentication type.

type NoAuth

type NoAuth struct{}

NoAuth represents no authentication.

func (*NoAuth) Authenticate

func (n *NoAuth) Authenticate(ctx context.Context, pool *browser.Pool) error

func (*NoAuth) GetCookies

func (n *NoAuth) GetCookies() []*http.Cookie

func (*NoAuth) GetHeaders

func (n *NoAuth) GetHeaders() map[string]string

func (*NoAuth) IsAuthenticated

func (n *NoAuth) IsAuthenticated() bool

func (*NoAuth) RefreshIfNeeded

func (n *NoAuth) RefreshIfNeeded(ctx context.Context) error

func (*NoAuth) Type

func (n *NoAuth) Type() AuthType

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

func (o *OAuthAuth) Authenticate(ctx context.Context, pool *browser.Pool) error

Authenticate performs OAuth authentication.

func (*OAuthAuth) GetCookies

func (o *OAuthAuth) GetCookies() []*http.Cookie

GetCookies returns no cookies for OAuth.

func (*OAuthAuth) GetHeaders

func (o *OAuthAuth) GetHeaders() map[string]string

GetHeaders returns the Authorization header.

func (*OAuthAuth) IsAuthenticated

func (o *OAuthAuth) IsAuthenticated() bool

IsAuthenticated returns true if we have a valid token.

func (*OAuthAuth) RefreshIfNeeded

func (o *OAuthAuth) RefreshIfNeeded(ctx context.Context) error

RefreshIfNeeded refreshes the token if needed.

func (*OAuthAuth) Type

func (o *OAuthAuth) Type() AuthType

Type returns the authentication type.

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

func (s *SessionAuth) Authenticate(ctx context.Context, pool *browser.Pool) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL