auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 17 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 auth implements the Auth0 device code login and token refresh for one context. Commands in internal/cmd/auth are thin wrappers.

Index

Constants

View Source
const UsernameClaim = "http://lfx.dev/claims/username"

UsernameClaim is the LFID username claim in education API access tokens. The delivery service returns 401 without it.

Variables

View Source
var Auth0BaseURL = func(c contexts.Context) string {
	return "https://" + c.Auth0Domain
}

Auth0BaseURL returns the tenant base URL for c without a trailing slash. Tests replace it with an httptest server URL.

View Source
var ErrNoRefreshToken = errors.New(`no refresh token stored; run "lfed auth login"`)

ErrNoRefreshToken is returned when the cached token is stale and no refresh token exists to renew it.

View Source
var ErrNotLoggedIn = errors.New(`not logged in; run "lfed auth login"`)

ErrNotLoggedIn is returned when no credentials exist for the context.

View Source
var ErrSessionExpired = errors.New(`session expired or revoked; run "lfed auth login"`)

ErrSessionExpired is returned when Auth0 rejects the refresh token.

View Source
var Scopes = []string{"openid", "email", "profile", "offline_access"}

Scopes requested at login. offline_access yields the refresh token; the others identify the user.

Functions

func CheckBackend

func CheckBackend(store credstore.Store, insecure bool) error

CheckBackend compares the stored login state with the --insecure-storage flag. The state file is shared by both backends, so a mismatch means the credentials live in the other backend. A missing state is ErrNotLoggedIn: the state file is written at login and removed at logout, so callers MUST NOT touch the system store before this check. A locked Secret Service collection prompts on first access; a logged-out user must not see that prompt.

func DeviceLogin

func DeviceLogin(ctx context.Context, c contexts.Context, store credstore.Store, opts LoginOptions) (string, error)

DeviceLogin runs the device code flow for c and persists the result in store. It returns the identity from the id_token, or "" when absent.

func IdentityFromIDToken

func IdentityFromIDToken(idToken string) string

IdentityFromIDToken returns a display name from an id_token for the "Logged in as" message. It returns "" when nothing usable is present.

func Logout

func Logout(store credstore.Store, insecure bool) error

Logout removes credentials and login state for the store's context. Without a login state there is nothing to remove, and the system store is not touched.

func OpenStore

OpenStore resolves the active context and opens its credential store with the backend selected by --insecure-storage.

func Token

func Token(ctx context.Context, c contexts.Context, store credstore.Store, insecure bool) (string, error)

Token returns a valid access token for c. It returns the cached token when it expires more than 60 seconds from now. Otherwise it refreshes and persists the new credentials.

func TokenLogin

func TokenLogin(store credstore.Store, refreshToken string, insecure bool) error

TokenLogin stores a refresh token supplied by the user. No access token is cached; the next Token call exchanges the refresh token for one.

func TokenResolver

func TokenResolver(f *cmdutil.Factory) func(context.Context) (string, error)

TokenResolver returns the Factory.Token implementation. main installs it so every command and the plugin manager share one refresh path.

Types

type Claims

type Claims struct {
	Username string
	Subject  string
	Issuer   string
	Expiry   time.Time
}

Claims are the access token fields that `lfed auth status` shows. They come from an unverified decode; the API verifies the token on each call.

func DecodeClaims

func DecodeClaims(token string) (Claims, error)

DecodeClaims decodes the payload of a JWT without signature checks.

type LoginOptions

type LoginOptions struct {
	// Out receives the user code and verification URL. Use stderr so
	// `lfed auth login` never pollutes a piped stdout.
	Out io.Writer
	// OpenBrowser launches the verification URL in the default browser.
	OpenBrowser bool
	// Insecure is recorded in the login state; see CheckBackend.
	Insecure bool
}

LoginOptions controls the interactive device code flow.

Jump to

Keyboard shortcuts

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