auth

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 23 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

Index

Constants

View Source
const (
	// DefaultLoginTimeout is how long GetTokensContext waits for the interactive
	// login flow to complete
	DefaultLoginTimeout = time.Minute * 5
)

Variables

View Source
var (
	ErrLoginFailed = errors.New("interactive login failed")

	// ErrInteractiveLoginRequired is returned by GetTokensContext when called
	// with a [NonInteractive] context and no cached or refreshed tokens are
	// available
	ErrInteractiveLoginRequired = errors.New("interactive login required")
)

Functions

func IsNonInteractive

func IsNonInteractive(ctx context.Context) bool

IsNonInteractive reports whether ctx (or a parent) was created by NonInteractive. Handler implementations must not start an interactive login when this is true.

func NonInteractive

func NonInteractive(ctx context.Context) context.Context

NonInteractive returns a copy of ctx that prevents GetTokensContext from starting an interactive login. Only cached tokens or a refresh token are used, otherwise ErrInteractiveLoginRequired is returned. This is intended for background renewals that must not open a browser.

Types

type Handler

type Handler interface {
	GetTokens() (*Tokens, error)
	GetTokensContext(ctx context.Context) (*Tokens, error)
}

Handler provides the tokens needed to request a certificate. Any interactive login, including running the local HTTP server it needs, is handled by the implementation, which must not start one when IsNonInteractive reports true for the provided context.

type OidcConfig

type OidcConfig struct {
	ClientID    string
	Issuer      string
	LoginPath   string
	RedirectURL string
	Scopes      []string
}

type OidcHandler

type OidcHandler struct {
	// contains filtered or unexported fields
}

func NewOidcHandler

func NewOidcHandler(config OidcConfig, opts ...OidcHandlerOption) (*OidcHandler, error)

NewOidcHandler creates a handler for the OIDC provider at config.Issuer.

The IdP is not contacted until tokens are first needed, so the handler can be created while the IdP is unreachable (such as before the network is up). Provider discovery is then performed by GetTokensContext, and retried by later calls until it succeeds. Each request to the IdP is limited to 30 seconds.

func (*OidcHandler) Callback

func (h *OidcHandler) Callback(w http.ResponseWriter, r *http.Request)

The Callback method is intended for use as the handler function for the callback URL of the OIDC auth flow process as part of the Serverless SSH CA

Only a callback whose state matches the session ends the login in progress: its result, whether successful or not, is passed to the waiting GetTokensContext call. Any other callback, such as one with no session, from an earlier login, or from another web page, is answered with an error page and the login keeps waiting. Callbacks received when no interactive login is in progress are rejected.

func (*OidcHandler) GetTokens

func (h *OidcHandler) GetTokens() (*Tokens, error)

func (*OidcHandler) GetTokensContext

func (h *OidcHandler) GetTokensContext(ctx context.Context) (*Tokens, error)

GetTokensContext returns access and ID tokens. Previously obtained tokens are reused until shortly before they expire, then a refresh token is used if one is available. Otherwise the interactive login flow is started: a local HTTP server is run on the redirect URL address and this blocks until the Callback completes, the login timeout is reached or ctx is done.

If ctx was created by NonInteractive no interactive login is started and ErrInteractiveLoginRequired is returned instead.

func (*OidcHandler) HttpHandler

func (h *OidcHandler) HttpHandler() http.Handler

HttpHandler returns the http.Handler for the login and callback paths. GetTokensContext serves this itself when an interactive login is needed.

func (*OidcHandler) Login

func (h *OidcHandler) Login(w http.ResponseWriter, r *http.Request)

The Login method is intended for use as the handler function for the initial login URL of the OIDC auth flow process.

This will start the OIDC auth flow process and redirect the user to the configured OIDC IdP.

type OidcHandlerOption

type OidcHandlerOption func(*OidcHandler)

func WithLogger

func WithLogger(logger *slog.Logger) OidcHandlerOption

WithLogger sets the logger used by the handler. The default discards all log messages. A nil logger is ignored.

func WithLoginTimeout

func WithLoginTimeout(d time.Duration) OidcHandlerOption

WithLoginTimeout sets how long GetTokensContext waits for the interactive login flow to complete. The default is DefaultLoginTimeout.

func WithTokenStore

func WithTokenStore(store tokenstore.Store) OidcHandlerOption

WithTokenStore sets the store used to persist the refresh token between runs. The default is a tokenstore.DiscardStore, which does not persist the refresh token.

type Tokens

type Tokens struct {
	Access   string
	Identity string
}

Directories

Path Synopsis
Package tokenstore persists the OIDC refresh token between runs so a new certificate can be requested without an interactive login.
Package tokenstore persists the OIDC refresh token between runs so a new certificate can be requested without an interactive login.

Jump to

Keyboard shortcuts

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