Help us shape the future of Go! Take the 2026 Go Developer Survey

session

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 21 Imported by: 0

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

View Source
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.

View Source
var ErrNoSession = errors.New("not logged in; run `d2l login`")

ErrNoSession means the user has never logged in (or logged out).

Functions

func Delete

func Delete() error

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

func ResolveBrowser(configured string, logf func(string, ...any)) (*Browser, error)

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

func (b *Browser) ProfileDir() string

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 Cookie struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Domain string `json:"domain"`
	Path   string `json:"path"`
}

type Family

type Family int

Family is the automation protocol a browser speaks.

const (
	FamilyUnknown  Family = iota
	FamilyChromium        // Chrome DevTools Protocol
	FamilyFirefox         // WebDriver BiDi
)

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

func FromHeader(baseURL, header string) (*Session, error)

FromHeader parses a pasted "a=b; c=d" Cookie header.

func Load

func Load() (*Session, error)

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.

func (*Session) HTTPCookies

func (s *Session) HTTPCookies() []*http.Cookie

func (*Session) Save

func (s *Session) Save() error

Jump to

Keyboard shortcuts

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