Documentation
¶
Overview ¶
Package browsersignin lets a person sign in to a web site in a browser window and hands back the cookies that browser would send to one address: how a calendar feed whose address answers only a signed-in browser (a Google Workspace calendar, which redirects to Google's sign-in page) is read.
The browser is a Chromium-family one installed on this computer (Chrome, Edge, Chromium or Brave), started in a fresh profile of its own that is removed afterwards, so nothing of the person's everyday browser is read or changed. It is driven over a pipe the process inherits (Chrome's --remote-debugging-pipe, or --remote-debugging-io-pipes on Windows), never a debugging port another program could reach, and its downloads are denied, so an address that answers with a file does not leave the file on disk. While the window is open the browser's cookies for the address are read every PollEvery; each new set is handed to the caller's Ready, which says whether the address now answers as wanted. The first set Ready accepts is returned and the browser is closed.
Index ¶
Constants ¶
const EnvBrowser = "AGENTRY_BROWSER"
EnvBrowser names a Chromium-family browser's program to use instead of the ones Find looks for.
Variables ¶
var ( PollEvery = 2 * time.Second RetryEvery = 15 * time.Second )
PollEvery is how often the browser's cookies are read; RetryEvery is how often a set of cookies Ready did not accept is tried again while it stays the same, so a fetch that failed for a moment does not hold the sign-in until it ends.
var ErrClosed = errors.New("the browser window was closed before the sign-in was done")
ErrClosed says the person closed the browser window before the sign-in was done.
var ErrNoBrowser = errors.New("no Chrome, Edge, Chromium or Brave was found on this computer: install one, or set " + EnvBrowser + " to its program")
ErrNoBrowser says no Chromium-family browser was found.
Functions ¶
Types ¶
type Cookie ¶
type Cookie struct {
Name string `json:"name"`
Value string `json:"value"`
Domain string `json:"domain"`
Path string `json:"path"`
Secure bool `json:"secure"`
// PartitionKey is set on a cookie kept for one top-level site alone
// (CHIPS); such a cookie is never sent to a plain fetch of the address.
PartitionKey any `json:"partitionKey,omitempty"`
}
Cookie is one cookie as the browser keeps it.
type Options ¶
type Options struct {
// URL is the https address the window opens, and the one whose cookies
// are read.
URL string
// Ready says whether the address answers as wanted when fetched with
// the Cookie header given. An error stops the sign-in; false keeps the
// window open.
Ready func(ctx context.Context, header string) (bool, error)
// Browser is the browser's program; empty finds one (Find).
Browser string
// Progress, when set, is told what the sign-in is waiting for.
Progress func(string)
}
Options are what Run opens and how it knows the sign-in is done.