Functions

Package-level functions of package sponsorkit that are not constructors of a type.

On this page

Functions that return one of the package's types are documented on that type's page (for example New on Client and VerifySession on Result); the overview lists them all.

CodeChallenge#

func CodeChallenge(verifier string) string

CodeChallenge returns the S256 PKCE challenge for verifier: base64url(sha256(ascii(verifier))) without padding.

View source

DefaultStorageDir#

func DefaultStorageDir() (string, error)

DefaultStorageDir returns the per-user configuration directory used when neither StorageDir nor Storage is set: $XDG_CONFIG_HOME/sponsorkit (or ~/.config/sponsorkit) on Linux, ~/Library/Application Support/sponsorkit on macOS and %AppData%\sponsorkit on Windows.

View source

NewCodeVerifier#

func NewCodeVerifier() string

NewCodeVerifier returns a PKCE code verifier: 32 random bytes encoded as base64url without padding (43 characters, PROTOCOL §2).

View source

OpenSystemBrowser#

func OpenSystemBrowser(ctx context.Context, url string) error

OpenSystemBrowser opens url in the user's default browser without a shell: xdg-open on Linux and BSD, open on macOS, rundll32 on Windows. It is the default Options.OpenBrowser.

Openers exit quickly, so it waits up to 1.5 s: an opener that exits non-zero in that window (for example xdg-open with no browser available) is reported as an error, which lets SignInAuto fall back to paste-back. An opener still running after that is assumed to be opening the browser.

View source

ParseISODuration#

func ParseISODuration(s string) (time.Duration, error)

ParseISODuration parses an ISO-8601 duration made of weeks, days, hours, minutes and seconds, such as "P7D", "PT12H" or "P1DT30M". Years and months are not accepted because their length varies.

View source

PromptStdin#

func PromptStdin(ctx context.Context, _ string) (string, error)

PromptStdin is the default Options.PromptForCode: it asks for the code on stderr and reads one line from stdin. The URL has already been printed.

It reads stdin byte by byte, so nothing after the code's line is consumed. A read cannot be interrupted: if ctx ends first (cancel or SignInTimeout), the read stays pending and the next line typed is taken by the next PromptStdin call, not by the host application. Supply your own PromptForCode if your program reads stdin after a cancelled sign-in.

View source

ResetProcessState#

func ResetProcessState()

ResetProcessState forgets per-process memo state: the nag runs already counted, the dev-check memo, the Retry-After memo and the in-memory state used when there is no per-user config directory. It simulates a new process and is meant for tests.

View source

TargetsHash#

func TargetsHash(t Targets) (string, error)

TargetsHash returns targets_hash: the lowercase hex SHA-256 of the canonical target param. It names the local storage file.

View source

TargetsParam#

func TargetsParam(t Targets) (string, error)

TargetsParam returns the canonical target param, e.g. "github:octocat,open-collective:webpack" (PROTOCOL §1). It returns an invalid_config *Error for malformed or missing targets.

View source