auth

package
v1.12.3 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MPL-2.0 Imports: 3 Imported by: ? 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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiKeyAuth

type ApiKeyAuth struct {
	AuthType AuthType `json:"auth_type"`
	APIKey   string   `json:"api_key"`  // If it starts with '$', treated as injected variable.
	VarName  string   `json:"var_name"` // Header/query param/cookie name (default: "X-Api-Key").
	Location string   `json:"location"` // Where to include the key: header, query, or cookie.
}

ApiKeyAuth holds config for API key–based authentication.

The key can be provided directly or sourced from an environment variable.

func NewApiKeyAuth

func NewApiKeyAuth(apiKey string) *ApiKeyAuth

NewApiKeyAuth constructs an ApiKeyAuth with defaults.

func (*ApiKeyAuth) Type

func (a *ApiKeyAuth) Type() AuthType

Type returns the auth type.

func (*ApiKeyAuth) Validate

func (a *ApiKeyAuth) Validate() error

Validate ensures required fields are present.

type Auth

type Auth interface {
	// Type returns the authentication type.
	Type() AuthType

	// Validate checks that all required fields are set.
	Validate() error
}

Auth is the interface all auth methods implement.

func UnmarshalAuth added in v1.4.6

func UnmarshalAuth(data []byte) (Auth, error)

type AuthType

type AuthType string

AuthType represents the kind of authentication.

const (
	// APIKeyType indicates API key–based authentication.
	APIKeyType AuthType = "api_key"

	// BasicType indicates basic username/password authentication.
	BasicType AuthType = "basic"

	// OAuth2Type indicates OAuth2 authentication.
	OAuth2Type AuthType = "oauth2"
)

type BasicAuth

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

BasicAuth holds config for HTTP Basic authentication.

func NewBasicAuth

func NewBasicAuth(username, password string) *BasicAuth

NewBasicAuth constructs a BasicAuth.

func (*BasicAuth) Type

func (b *BasicAuth) Type() AuthType

Type returns the auth type.

func (*BasicAuth) Validate

func (b *BasicAuth) Validate() error

Validate ensures required fields are present.

type OAuth2Auth

type OAuth2Auth struct {
	AuthType     AuthType `json:"auth_type"`
	TokenURL     string   `json:"token_url"`
	ClientID     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret"`
	Scope        *string  `json:"scope,omitempty"` // Optional OAuth2 scope.
}

OAuth2Auth holds config for OAuth2 authentication.

func NewOAuth2Auth

func NewOAuth2Auth(tokenURL, clientID, clientSecret string, scope *string) *OAuth2Auth

NewOAuth2Auth constructs an OAuth2Auth.

func (*OAuth2Auth) Type

func (o *OAuth2Auth) Type() AuthType

Type returns the auth type.

func (*OAuth2Auth) Validate

func (o *OAuth2Auth) Validate() error

Validate ensures required fields are present.

Jump to

Keyboard shortcuts

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