devicelogin

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 11 Imported by: 1 module, 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 devicelogin signs a person in with the OAuth device authorization grant (RFC 8628) against any OIDC issuer, and keeps the token in a file that only the user reads.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath(tool string) (string, error)

DefaultPath is the file of the token of tool, under the user configuration directory.

func Save

func Save(path string, t Token) error

Save writes t to path with mode 0600, in a directory of mode 0700.

Types

type Config

type Config struct {
	Issuer   string
	ClientID string
	// Scope defaults to "openid email".
	Scope  string
	Client *http.Client
	Now    func() time.Time
	// Wait pauses for d between polls, or returns the error of ctx. It defaults to a timer.
	Wait func(ctx context.Context, d time.Duration) error
	// Prompt tells the person where to go and what to enter.
	Prompt func(verificationURI, userCode, verificationURIComplete string)
}

Config is one login.

type Token

type Token struct {
	Issuer  string    `json:"issuer"`
	Value   string    `json:"token"`
	Expires time.Time `json:"expires"`
}

Token is the credential that a login gave. It is the ID token when the issuer returns one, and the access token otherwise: the ID token is a JWT whose audience is the client.

func Load

func Load(path string, now time.Time) (Token, error)

Load reads the token at path. It refuses a token that is expired at now.

func Login

func Login(ctx context.Context, cfg Config) (Token, error)

Login runs the flow and returns the token.

Jump to

Keyboard shortcuts

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