Documentation
¶
Overview ¶
Package device implements an OAuth 2.0 Device Authorization Grant (RFC 8628) client for command-line tools on machines without a browser.
Start requests a device and user code and returns what the user must see; Poll waits for the user to approve the request on another device and returns the issued tokens. Endpoints come from OpenID Connect discovery or explicit configuration. The returned ID token is not verified by this package; relying servers must verify it (for example with authentication/jwt or go-oidc) before trusting it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAccessDenied reports that the user denied the authorization request. ErrAccessDenied = errors.New("device: access denied") // ErrServer reports a transport failure or an invalid authorization server // response. ErrServer = errors.New("device: authorization server request failed") )
Functions ¶
This section is empty.
Types ¶
type Authorization ¶
type Authorization struct {
DeviceCode authoidc.Secret
UserCode string
VerificationURI string
VerificationURIComplete string
ExpiresAt time.Time
Interval time.Duration
}
Authorization is a pending device authorization. Show UserCode and VerificationURI (or VerificationURIComplete) to the user, then call Poll. DeviceCode is redacted when formatted.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client runs device authorization flows for one OAuth client. It is safe for concurrent use.
func (*Client) Poll ¶
func (c *Client) Poll(ctx context.Context, authorization Authorization) (*oauth2.Token, string, error)
Poll waits until the user completes the authorization and returns the token and the raw, unverified ID token (empty when none was issued). It polls at the authorization interval, waits 5 seconds longer after each slow_down response, and keeps waiting on authorization_pending. It returns authentication.ErrExpired when the authorization expires, ErrAccessDenied when the user denies it, an *Error for other OAuth errors, and ctx.Err() when ctx ends first.
type Error ¶
Error is an OAuth error response from the authorization server. Code is the RFC 6749 error code when it is well formed and empty otherwise. Error matches authentication.ErrUnauthenticated with errors.Is.
type Options ¶
type Options struct {
Issuer string
DeviceAuthURL string
TokenURL string
ClientID string
// ClientSecret is optional; device clients are usually public. When set
// it is sent with HTTP Basic authentication.
ClientSecret string
// Scopes are requested verbatim. With Issuer, "openid" is added when
// missing so that an ID token is issued.
Scopes []string
// HTTPClient defaults to a client with a 30 second timeout.
HTTPClient *http.Client
}
Options configures a Client. Set either Issuer, for OpenID Connect discovery, or both DeviceAuthURL and TokenURL. Endpoints must use https, except http on loopback hosts.