auth

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CookieStateChanged

func CookieStateChanged(before, after CookieState) bool

CookieStateChanged reports whether a cookie was added or its value changed. Deletions alone do not prove authentication.

func ExpandCredentials

func ExpandCredentials(value, username, password string) string

ExpandCredentials substitutes {{username}}/{{password}} placeholders.

func FirstNavigateURL

func FirstNavigateURL(steps []LoginStep) string

FirstNavigateURL returns the first absolute HTTP(S) navigate URL, or "". Recorder exports can contain an initial about:blank navigation, which is not a useful anonymous-session baseline.

func HasTerminalVisibleAssertion

func HasTerminalVisibleAssertion(steps []LoginStep) bool

HasTerminalVisibleAssertion reports whether the flow ends by asserting an authenticated-only element. This is an explicit success signal for applications whose server-side session does not mutate browser state.

func NeedsCredentials

func NeedsCredentials(steps []LoginStep) bool

NeedsCredentials reports whether any step value still contains an unresolved credential placeholder that must be supplied via -auto-login.

func RunLoginSteps

func RunLoginSteps(ctx context.Context, page *rod.Page, steps []LoginStep, username, password string, settle time.Duration) error

RunLoginSteps replays an explicit multi-step login flow against a rod page. Cookies / storage set during replay remain on the browser context for the subsequent crawl. settle bounds waitvisible / inter-step WaitStable; zero uses a 5s default.

func SessionStateChanged

func SessionStateChanged(before, after SessionState) bool

SessionStateChanged reports evidence that replay established browser auth.

func ValidateSteps

func ValidateSteps(steps []LoginStep) error

ValidateSteps rejects flows that cannot be replayed deterministically.

Types

type CookieState

type CookieState map[string]string

CookieState is a browser-wide snapshot used to verify that a login changed authentication state. Cookies are browser-wide because SSO flows can finish on a different origin from the application login page.

func CaptureCookieState

func CaptureCookieState(page *rod.Page) (CookieState, error)

CaptureCookieState snapshots cookie values without exposing them to logs.

type LoginStep

type LoginStep struct {
	// Action is one of: navigate, fill, click, doubleclick, waitvisible, wait,
	// press, submit.
	Action string `json:"action" yaml:"action"`
	// Selector is a CSS selector (or xpath=… expression) the action targets.
	// Unused by navigate/wait.
	Selector string `json:"selector" yaml:"selector"`
	// Value is the action argument: a URL (navigate), text to type (fill), a key
	// name such as "enter"/"tab" (press), or a duration like "2s" (wait).
	Value string `json:"value" yaml:"value"`
}

LoginStep is a single action in a multi-step headless login flow. In Value, the placeholders {{username}} and {{password}} are substituted with the configured credentials so secrets stay out of the step list / recording.

func StepsAfterFirstNavigateURL

func StepsAfterFirstNavigateURL(steps []LoginStep) ([]LoginStep, string)

StepsAfterFirstNavigateURL returns the replayable suffix after the first absolute HTTP(S) navigation. The caller can navigate once, capture the anonymous cookie baseline, and avoid loading the login page a second time.

func StepsFromData

func StepsFromData(data []byte, username, password string) ([]LoginStep, error)

StepsFromData converts a recording / explicit-step JSON payload into LoginSteps.

func StepsFromExplicit

func StepsFromExplicit(data []byte) ([]LoginStep, error)

StepsFromExplicit loads a hand-authored LoginStep list.

func StepsFromFile

func StepsFromFile(path, username, password string) ([]LoginStep, error)

StepsFromFile loads either a Chrome DevTools Recorder export or an explicit { "steps": [ { "action": ... } ] } JSON file.

func StepsFromRecording

func StepsFromRecording(data []byte, username, password string) ([]LoginStep, error)

StepsFromRecording converts a Chrome DevTools Recorder export into LoginSteps. username/password are used to parameterize captured credential literals into {{username}}/{{password}} placeholders.

type SessionState

type SessionState struct {
	Cookies        CookieState
	Origin         string
	LocalStorage   string
	SessionStorage string
	// StorageCaptured distinguishes empty storage from a failed read, so a
	// failed read is never mistaken for storage having changed.
	StorageCaptured bool
}

SessionState captures the browser state commonly used to persist web authentication. Storage is compared only while the flow remains on the same origin; cookies are browser-wide and cover cross-origin SSO redirects.

func CaptureSessionState

func CaptureSessionState(page *rod.Page) (SessionState, error)

CaptureSessionState snapshots cookies plus same-origin web storage.

Jump to

Keyboard shortcuts

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