oauth

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package oauth runs the browser login against the Chronos API: the authorization code flow with PKCE, a loopback listener for the redirect, the token exchange and revocation. These protocol requests use form bodies and RFC 6749 errors, which the SDK does not send or parse.

Index

Constants

View Source
const ClientID = "chronos-cli"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL string
	// HTTPClient sends the token and revoke requests. Its redirect policy is
	// ignored, since a redirect could carry the form body to another host.
	HTTPClient *http.Client
	UserAgent  string
}

func (*Client) Login

func (c *Client) Login(ctx context.Context, opts LoginOptions) (Token, error)

Login opens the browser for the person to approve the login, waits for the redirect to the loopback listener and exchanges the code for a token. It returns when ctx ends or opts.Timeout passes, with the listener closed.

func (*Client) Revoke

func (c *Client) Revoke(ctx context.Context, token string) error

Revoke revokes the grant behind token (RFC 7009). The API answers 200 whether or not the token was live, so nil means it no longer works.

func (*Client) RevokeBestEffort

func (c *Client) RevokeBestEffort(ctx context.Context, token string)

RevokeBestEffort revokes token and ignores the outcome. It runs even after ctx is cancelled, so a token chronos will not keep does not stay live.

type LoginOptions

type LoginOptions struct {
	// Scope is the space-separated scopes to ask for.
	Scope string
	// DeviceName names this machine on the consent page. Empty sends none.
	DeviceName string
	Timeout    time.Duration
	// OpenBrowser is called with the authorization URL once the listener is
	// ready.
	OpenBrowser func(authorizeURL string)
	// Ignored is called when the listener ignores a callback: a wrong state,
	// or one after the first.
	Ignored func()
}

type Token

type Token struct {
	AccessToken string
	// ExpiresIn is zero when the API sent no expiry.
	ExpiresIn time.Duration
	Scopes    []string
	User      config.User
	Account   config.Account
}

Jump to

Keyboard shortcuts

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