auth

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 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 auth provides OIDC authentication for the krci CLI.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotAuthenticated = errors.New("not authenticated: run 'krci auth login'")
	ErrTokenExpired     = errors.New("token expired")
	ErrRefreshFailed    = errors.New("token refresh failed")

	// ErrEnvTokenExpired is returned when KRCI_TOKEN is a JWT whose exp claim
	// has passed. KRCI_TOKEN is never refreshed; the caller supplies a new one.
	ErrEnvTokenExpired = errors.New("KRCI_TOKEN has expired: supply a fresh token")
)

Sentinel errors for auth failure classification. Callers use errors.Is() to branch on these.

Functions

func NewTokenProvider

func NewTokenProvider(store token.Store, cfg *config.Config, w io.Writer) *tokenProvider

NewTokenProvider creates a TokenProvider with the given store and config. Login progress, the login summary, and refresh-persistence warnings are written to w, which must be non-nil. Panics if w is nil.

func ValidateIssuerURL added in v0.3.0

func ValidateIssuerURL(rawURL string) error

ValidateIssuerURL ensures the issuer URL is well-formed and uses HTTPS.

Types

type TokenProvider

type TokenProvider interface {
	// GetToken returns a valid ID token for portal Bearer auth.
	GetToken(ctx context.Context) (string, error)
	// Login performs the interactive OIDC login flow.
	Login(ctx context.Context) error
	// Logout clears stored credentials.
	Logout() error
	// UserInfo returns the claims of the token GetToken resolves: KRCI_TOKEN
	// when set, otherwise the resolved ID token (the stored one before any
	// resolution).
	UserInfo() (*UserInfo, error)
}

TokenProvider resolves a valid ID token using the precedence chain: KRCI_TOKEN env → cached token → refresh → error.

type UserInfo

type UserInfo struct {
	Email     string    `json:"email"`
	Name      string    `json:"name"`
	Sub       string    `json:"sub"`
	Groups    []string  `json:"groups"`
	ExpiresAt time.Time `json:"-"` // the bearer's expiry; see bearerExpiry
	FromEnv   bool      `json:"-"` // true when the claims come from KRCI_TOKEN, not the stored session
}

UserInfo holds OIDC claims extracted from the ID token.

Jump to

Keyboard shortcuts

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