Documentation
¶
Overview ¶
Package httpauth provides authentication strategies for HTTP requests in go-polyscript.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator interface { // Authenticate applies authentication to the HTTP request. // It should modify the request in-place to add authentication details. Authenticate(req *http.Request) error // AuthenticateWithContext applies authentication with context. // This allows for context cancellation during authentication. AuthenticateWithContext(ctx context.Context, req *http.Request) error // Name returns a descriptive name of the authentication method. Name() string }
Authenticator defines the interface for HTTP authentication strategies.
type BasicAuth ¶
BasicAuth implements HTTP Basic Authentication according to RFC 7617. It adds an Authorization header with the format: "Basic base64(username:password)".
func NewBasicAuth ¶
NewBasicAuth creates a new BasicAuth authenticator with the given credentials. If username is empty, this authenticator will do nothing when called.
func (*BasicAuth) Authenticate ¶
Authenticate applies basic authentication to the HTTP request by setting the Authorization header using the standard Basic auth format. If the username is empty, no authentication is applied.
func (*BasicAuth) AuthenticateWithContext ¶
AuthenticateWithContext applies basic authentication with context support. This respects context cancellation while applying authentication.
type HeaderAuth ¶
HeaderAuth implements authentication via custom HTTP headers. This is a flexible authenticator that can be used for various header-based authentication schemes like Bearer tokens, API keys, and custom authentication.
func NewBearerAuth ¶
func NewBearerAuth(token string) *HeaderAuth
NewBearerAuth creates a HeaderAuth specifically configured for Bearer token authentication. This is a common authentication method for APIs that use JWT or OAuth tokens.
func NewHeaderAuth ¶
func NewHeaderAuth(headers map[string]string) *HeaderAuth
NewHeaderAuth creates a new HeaderAuth authenticator with the given headers. Each key-value pair in the map will be set as a header in the HTTP request.
func (*HeaderAuth) Authenticate ¶
func (h *HeaderAuth) Authenticate(req *http.Request) error
Authenticate applies header-based authentication to the HTTP request by setting all headers from the Headers map.
func (*HeaderAuth) AuthenticateWithContext ¶
AuthenticateWithContext applies header-based authentication with context support. This respects context cancellation while applying authentication.
func (*HeaderAuth) Name ¶
func (h *HeaderAuth) Name() string
Name returns the name of the authentication method.
type NoAuth ¶
type NoAuth struct{}
NoAuth represents a no-authentication strategy. This authenticator performs no operations and is useful as a default or for explicitly indicating that no authentication is required.
func (*NoAuth) Authenticate ¶
Authenticate does nothing as no authentication is needed. This method satisfies the Authenticator interface but performs no operations.
func (*NoAuth) AuthenticateWithContext ¶
AuthenticateWithContext does nothing as no authentication is needed, but respects context cancellation.