Documentation
¶
Overview ¶
Package session stores the Brightspace session cookies and obtains them by driving a real Chromium window through SSO.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoBrowser = errors.New("no supported browser found (Chromium- or Firefox-based). Set browser in the config (d2l config --edit) or use d2l login --cookie -")
ErrNoBrowser means no browser d2l can drive was found.
var ErrNoSession = errors.New("not logged in; run `d2l login`")
ErrNoSession means the user has never logged in (or logged out).
Functions ¶
func DeleteProfiles ¶
func DeleteProfiles() error
DeleteProfiles removes every login profile d2l created.
Types ¶
type Browser ¶
type Browser struct {
Name string // for messages and the profile dir, e.g. "zen" or "chromium-browser"
Argv []string // command prefix; d2l appends its flags and the URL
Family Family
// Flatpak and Snap browsers can only write inside their sandbox, so the
// login profile has to live there.
Flatpak string // app ID
Snap string // snap name
}
Browser is a launchable browser.
func ResolveBrowser ¶
ResolveBrowser picks the browser to log in with: the configured one, else the system default, else any installed browser d2l can drive.
func (*Browser) ProfileDir ¶
ProfileDir is the browser profile d2l logs in with. It is separate from the user's own profile and persists so SSO can remember them.
type LoginOptions ¶
type LoginOptions struct {
BaseURL string
Browser string // command from the config; empty means the default browser
// Interactive skips the silent headless attempt and opens a window right away.
Interactive bool
// Silent only tries the hidden browser and never opens a window.
Silent bool
// Validate checks captured cookies against the server. Login keeps
// waiting until it accepts a session. Nil accepts the first one.
Validate func(context.Context, *Session) error
// Logf receives progress lines.
Logf func(format string, args ...any)
}
LoginOptions controls how Login drives the browser.
type Session ¶
type Session struct {
BaseURL string `json:"base_url"`
Cookies []Cookie `json:"cookies"`
SavedAt time.Time `json:"saved_at"`
}
func FromHeader ¶
FromHeader parses a pasted "a=b; c=d" Cookie header.
func Login ¶
func Login(ctx context.Context, o LoginOptions) (*Session, error)
Login launches a browser on Learn with a profile of its own and waits for a session the server accepts, reading cookies over the browser's automation protocol (CDP for Chromium-based browsers, WebDriver BiDi for Firefox-based ones). The user's own browser profile is never touched.
The profile persists, so if the identity provider remembers the user ("stay signed in"), a hidden run can renew the session without a window.