http

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package http provides HTTP authentication utilities and interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandlerFunc

func HandlerFunc(cfg *ServerConfig, origHandler http.HandlerFunc) (http.HandlerFunc, error)

HandlerFunc creates an authentication-wrapped HTTP handler function from the provided configuration.

func MultiAuthnHandlerFunc

func MultiAuthnHandlerFunc(cfg *ServerConfig, origHandler http.HandlerFunc) http.HandlerFunc

MultiAuthnHandlerFunc creates a handler function that supports multiple authentication providers.

func NewRequestModifier added in v0.6.0

func NewRequestModifier(cfg ClientConfig) func(*http.Request) error

NewRequestModifier returns a request modifier function that applies auth credentials and netrc credentials to outgoing requests. It is designed for use with github.com/dioad/net/http.ClientConfig.RequestModifier.

func NullHandler

func NullHandler(next http.HandlerFunc) http.HandlerFunc

NullHandler is a handler that passes through to the next handler without authentication.

Types

type Authenticator

type Authenticator interface {
	AuthRequest(r *http.Request) (stdctx.Context, error)
}

Authenticator is an interface for authenticating an HTTP request.

type ClientAuth

type ClientAuth interface {
	AddAuth(*http.Request) error
}

ClientAuth is an interface for adding authentication to an HTTP request.

func NewClientAuth

func NewClientAuth(authConfig ClientConfig) ClientAuth

NewClientAuth returns a ClientAuth implementation based on the provided configuration.

type ClientConfig

type ClientConfig struct {
	BasicAuthConfig  basic.ClientConfig  `mapstructure:"basic"`
	GitHubAuthConfig github.ClientConfig `mapstructure:"github"`
	HMACAuthConfig   hmac.ClientConfig   `mapstructure:"hmac"`
}

ClientConfig represents the authentication configuration for an HTTP client.

type GenericAuthConfig

type GenericAuthConfig struct {
	Name   string         `mapstructure:"name"`
	Config map[string]any `mapstructure:"config"`
}

GenericAuthConfig represents a generic authentication configuration.

type Handler

type Handler struct {
	Config ServerConfig
	// contains filtered or unexported fields
}

Handler describes an HTTP authentication handler.

func NewHandler

func NewHandler(cfg *ServerConfig) (*Handler, error)

NewHandler creates a new authentication handler from the provided configuration.

func (*Handler) LoginRoutes added in v0.8.0

func (h *Handler) LoginRoutes() (LoginRoutable, bool)

LoginRoutes returns h's concrete login-routing methods, if its underlying middleware implements LoginRoutable.

func (*Handler) Wrap

func (h *Handler) Wrap(handler http.Handler) http.Handler

Wrap wraps an HTTP handler with authentication middleware.

type LoginRoutable added in v0.8.0

type LoginRoutable interface {
	AuthStart() http.HandlerFunc
	Callback() http.HandlerFunc
	Logout() http.HandlerFunc
	LoginPath() string
	CallbackPath() string
	LogoutPath() string
}

LoginRoutable is implemented by auth middlewares that need additional HTTP routes registered beyond the Wrap middleware chain (currently only OIDC's login/callback/logout flow).

type Middleware

type Middleware interface {
	//	AuthRequest(r *http.Request) (stdctx.Context, error)
	Wrap(http.Handler) http.Handler
}

Middleware is an interface for wrapping an HTTP handler with authentication.

type OIDCServerConfig added in v0.8.0

type OIDCServerConfig struct {
	oidc.ClientConfig `mapstructure:",squash"`
	oidcmw.OIDCConfig `mapstructure:",squash"`
}

OIDCServerConfig combines OIDC provider credentials with the login/session middleware settings (redirect-uri, cookies, login/logout paths) needed to complete a login when "type: oidc" is used as a server's sole auth gate.

type ServerConfig

type ServerConfig struct {
	// Type selects the auth handler explicitly: "github", "basic", "hmac", "jwt", "oidc".
	// When set it takes precedence over zero-value detection. An unrecognised Type
	// returns an error from NewHandler.
	Type string `mapstructure:"type"`

	BasicAuthConfig  basic.ServerConfig  `mapstructure:"basic"`
	GitHubAuthConfig github.ServerConfig `mapstructure:"github"`
	HMACAuthConfig   hmac.ServerConfig   `mapstructure:"hmac"`
	JWTAuthConfig    jwt.ValidatorConfig `mapstructure:"jwt"`
	OIDCAuthConfig   OIDCServerConfig    `mapstructure:"oidc"`

	Providers []string `mapstructure:"providers"`
}

ServerConfig represents the authentication configuration for an HTTP server.

Directories

Path Synopsis
Package authmw provides a shared HTTP middleware-wrapping helper for request-based authenticators (basic, github, hmac).
Package authmw provides a shared HTTP middleware-wrapping helper for request-based authenticators (basic, github, hmac).
authz
principal
Package principal provides principal-based authorization middleware.
Package principal provides principal-based authorization middleware.
Package basic provides HTTP Basic authentication middleware and utilities.
Package basic provides HTTP Basic authentication middleware and utilities.
Package github provides GitHub-based authentication middleware.
Package github provides GitHub-based authentication middleware.
Package hmac provides HMAC-based authentication middleware.
Package hmac provides HMAC-based authentication middleware.
Package middleware provides HTTP middleware for extracting an authenticated principal from the request context and attaching it for downstream handlers.
Package middleware provides HTTP middleware for extracting an authenticated principal from the request context and attaching it for downstream handlers.
jwt
Package jwt provides HTTP middleware for authenticating requests with a bearer JWT and authorizing them against a claim predicate.
Package jwt provides HTTP middleware for authenticating requests with a bearer JWT and authorizing them against a claim predicate.
oidc
Package oidc provides HTTP middleware for browser-based, cookie-backed OIDC login sessions: the login/callback/logout flow, session cookie management, and transparent token refresh.
Package oidc provides HTTP middleware for browser-based, cookie-backed OIDC login sessions: the login/callback/logout flow, session cookie management, and transparent token refresh.
Package oidc provides HTTP authentication using OpenID Connect via goth.
Package oidc provides HTTP authentication using OpenID Connect via goth.
Package server provides auth-specific ServerOption factories for github.com/dioad/net/http servers.
Package server provides auth-specific ServerOption factories for github.com/dioad/net/http servers.

Jump to

Keyboard shortcuts

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