auth

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseAuthType

func ParseAuthType(authType string) (string, error)

ParseAuthType converts a string to an auth type validator

func RedactString

func RedactString(s string) string

RedactString hides sensitive data for logging

Types

type APIKeyAuth

type APIKeyAuth struct {
	Key      string `json:"key"`      // The key name (e.g., "X-API-Key")
	Value    string `json:"value"`    // The key value
	Location string `json:"location"` // "header" or "query"
}

APIKeyAuth represents API Key authentication

func NewAPIKeyAuth

func NewAPIKeyAuth(key, value, location string) *APIKeyAuth

NewAPIKeyAuth creates a new API Key authentication provider

func (*APIKeyAuth) Apply

func (a *APIKeyAuth) Apply(req *http.Request) error

Apply adds the API key to the request

func (*APIKeyAuth) Redact

func (a *APIKeyAuth) Redact() AuthProvider

Redact returns a copy with the value redacted

func (*APIKeyAuth) String

func (a *APIKeyAuth) String() string

String returns a human-readable representation

func (*APIKeyAuth) Type

func (a *APIKeyAuth) Type() string

Type returns the authentication type

func (*APIKeyAuth) Validate

func (a *APIKeyAuth) Validate() error

Validate checks if the configuration is valid

type AuthProvider

type AuthProvider interface {
	// Apply adds authentication to the request
	Apply(req *http.Request) error

	// Type returns the authentication type identifier
	Type() string

	// Validate checks if the configuration is valid
	Validate() error

	// Redact returns a copy with sensitive data hidden (for logging)
	Redact() AuthProvider
}

AuthProvider applies authentication to HTTP requests

type BasicAuth

type BasicAuth struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

BasicAuth represents HTTP Basic authentication

func NewBasicAuth

func NewBasicAuth(username, password string) *BasicAuth

NewBasicAuth creates a new Basic authentication provider

func (*BasicAuth) Apply

func (b *BasicAuth) Apply(req *http.Request) error

Apply adds Basic authentication to the request

func (*BasicAuth) Redact

func (b *BasicAuth) Redact() AuthProvider

Redact returns a copy with password redacted

func (*BasicAuth) String

func (b *BasicAuth) String() string

String returns a human-readable representation

func (*BasicAuth) Type

func (b *BasicAuth) Type() string

Type returns the authentication type

func (*BasicAuth) Validate

func (b *BasicAuth) Validate() error

Validate checks if username and password are present

type BearerAuth

type BearerAuth struct {
	Token string `json:"token"`
}

BearerAuth represents Bearer token authentication

func NewBearerAuth

func NewBearerAuth(token string) *BearerAuth

NewBearerAuth creates a new Bearer authentication provider

func (*BearerAuth) Apply

func (b *BearerAuth) Apply(req *http.Request) error

Apply adds the Bearer token to the Authorization header

func (*BearerAuth) Redact

func (b *BearerAuth) Redact() AuthProvider

Redact returns a copy with the token redacted

func (*BearerAuth) String

func (b *BearerAuth) String() string

String returns a human-readable representation

func (*BearerAuth) Type

func (b *BearerAuth) Type() string

Type returns the authentication type

func (*BearerAuth) Validate

func (b *BearerAuth) Validate() error

Validate checks if the token is present

type NoAuth

type NoAuth struct{}

NoAuth represents no authentication

func (*NoAuth) Apply

func (n *NoAuth) Apply(req *http.Request) error

func (*NoAuth) Redact

func (n *NoAuth) Redact() AuthProvider

func (*NoAuth) Type

func (n *NoAuth) Type() string

func (*NoAuth) Validate

func (n *NoAuth) Validate() error

Jump to

Keyboard shortcuts

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