auth

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package auth provides authentication handling for accessibility audits.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthType

type AuthType string

AuthType represents the authentication method.

const (
	AuthTypeForm   AuthType = "form"
	AuthTypeOAuth  AuthType = "oauth"
	AuthTypeBasic  AuthType = "basic"
	AuthTypeBearer AuthType = "bearer"
	AuthTypeCookie AuthType = "cookie"
)

type Config

type Config struct {
	// Type of authentication
	Type AuthType `yaml:"type" json:"type"`

	// Login URL (for form auth)
	LoginURL string `yaml:"loginUrl,omitempty" json:"loginUrl,omitempty"`

	// Credentials
	Credentials map[string]string `yaml:"credentials,omitempty" json:"credentials,omitempty"`

	// Form selectors (for form auth)
	Selectors *FormSelectors `yaml:"selectors,omitempty" json:"selectors,omitempty"`

	// Headers (for bearer/basic auth)
	Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"`

	// Cookies (for cookie auth)
	Cookies map[string]string `yaml:"cookies,omitempty" json:"cookies,omitempty"`

	// Success indicator (selector that indicates successful login)
	SuccessIndicator string `yaml:"successIndicator,omitempty" json:"successIndicator,omitempty"`

	// Timeout for login
	Timeout time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"`
}

Config contains authentication configuration.

type Cookie struct {
	Name     string `json:"name"`
	Value    string `json:"value"`
	Domain   string `json:"domain,omitempty"`
	Path     string `json:"path,omitempty"`
	Secure   bool   `json:"secure,omitempty"`
	HttpOnly bool   `json:"httpOnly,omitempty"`
}

Cookie represents a browser cookie.

type FormSelectors

type FormSelectors struct {
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
	Submit   string `yaml:"submit" json:"submit"`
	MFA      string `yaml:"mfa,omitempty" json:"mfa,omitempty"`
}

FormSelectors contains CSS selectors for form-based authentication.

type Handler

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

Handler handles authentication for audits.

func NewHandler

func NewHandler(vibe *vibium.Vibe, logger *slog.Logger, config *Config) *Handler

NewHandler creates a new authentication handler.

func (*Handler) Authenticate

func (h *Handler) Authenticate(ctx context.Context) error

Authenticate performs authentication based on the configured method.

func (*Handler) GetSessionCookies

func (h *Handler) GetSessionCookies(ctx context.Context) ([]Cookie, error)

GetSessionCookies returns current session cookies.

func (*Handler) HandleMFA

func (h *Handler) HandleMFA(ctx context.Context, mfaCode string) error

HandleMFA handles multi-factor authentication.

func (*Handler) IsAuthenticated

func (h *Handler) IsAuthenticated(ctx context.Context) bool

IsAuthenticated checks if the session is authenticated.

func (*Handler) RestoreSession

func (h *Handler) RestoreSession(ctx context.Context, session *Session) error

RestoreSession restores a saved session.

func (*Handler) SaveSession

func (h *Handler) SaveSession(ctx context.Context) (*Session, error)

SaveSession saves the current session for reuse.

type Session

type Session struct {
	Cookies        []Cookie          `json:"cookies"`
	LocalStorage   map[string]string `json:"localStorage"`
	SessionStorage map[string]string `json:"sessionStorage"`
}

Session contains saved session data.

Jump to

Keyboard shortcuts

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