authx

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 13 Imported by: 1 module, 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

func SupportedAuthTypes

func SupportedAuthTypes() []string

SupportedAuthTypes returns the supported auth types

Types

type AuthFileInfo

type AuthFileInfo struct {
	Name        string `json:"name" yaml:"name"`
	Author      string `json:"author" yaml:"author"`
	Severity    string `json:"severity" yaml:"severity"`
	Description string `json:"description" yaml:"description"`
}

type AuthStrategy

type AuthStrategy interface {
	// Apply applies the strategy to the request
	Apply(*http.Request)
	// ApplyOnRR applies the strategy to the retryable request
	ApplyOnRR(*retryablehttp.Request)
}

AuthStrategy is an interface for auth strategies basic auth , bearer token, headers, cookies, query

type AuthType

type AuthType string
const (
	BasicAuth       AuthType = "BasicAuth"
	BearerTokenAuth AuthType = "BearerToken"
	HeadersAuth     AuthType = "Header"
	CookiesAuth     AuthType = "Cookie"
	QueryAuth       AuthType = "Query"
)

type Authx

type Authx struct {
	ID      string       `json:"id" yaml:"id"`
	Info    AuthFileInfo `json:"info" yaml:"info"`
	Secrets []Secret     `json:"static" yaml:"static"`
}

Authx is a struct for secrets or credentials file

func GetAuthDataFromFile

func GetAuthDataFromFile(file string) (*Authx, error)

GetAuthDataFromFile reads the auth data from file

func GetAuthDataFromJSON

func GetAuthDataFromJSON(data []byte) (*Authx, error)

GetAuthDataFromJSON reads the auth data from json

func GetAuthDataFromYAML

func GetAuthDataFromYAML(data []byte) (*Authx, error)

GetAuthDataFromYAML reads the auth data from yaml

type BasicAuthStrategy

type BasicAuthStrategy struct {
	Data *Secret
}

BasicAuthStrategy is a strategy for basic auth

func NewBasicAuthStrategy

func NewBasicAuthStrategy(data *Secret) *BasicAuthStrategy

NewBasicAuthStrategy creates a new basic auth strategy

func (*BasicAuthStrategy) Apply

func (s *BasicAuthStrategy) Apply(req *http.Request)

Apply applies the basic auth strategy to the request

func (*BasicAuthStrategy) ApplyOnRR

func (s *BasicAuthStrategy) ApplyOnRR(req *retryablehttp.Request)

ApplyOnRR applies the basic auth strategy to the retryable request

type BearerTokenAuthStrategy

type BearerTokenAuthStrategy struct {
	Data *Secret
}

BearerTokenAuthStrategy is a strategy for bearer token auth

func NewBearerTokenAuthStrategy

func NewBearerTokenAuthStrategy(data *Secret) *BearerTokenAuthStrategy

NewBearerTokenAuthStrategy creates a new bearer token auth strategy

func (*BearerTokenAuthStrategy) Apply

func (s *BearerTokenAuthStrategy) Apply(req *http.Request)

Apply applies the bearer token auth strategy to the request

func (*BearerTokenAuthStrategy) ApplyOnRR

func (s *BearerTokenAuthStrategy) ApplyOnRR(req *retryablehttp.Request)

ApplyOnRR applies the bearer token auth strategy to the retryable request

type Cookie struct {
	Key   string `json:"key" yaml:"key"`
	Value string `json:"value" yaml:"value"`
	Raw   string `json:"raw" yaml:"raw"`
}

func (*Cookie) Parse

func (c *Cookie) Parse() error

Parse parses the cookie in raw the cookie is in format of Set-Cookie: <cookie-name>=<cookie-value>; Expires=<date>; Path=<path>; Domain=<domain_name>; Secure; HttpOnly

func (*Cookie) Validate

func (c *Cookie) Validate() error

type CookiesAuthStrategy

type CookiesAuthStrategy struct {
	Data *Secret
}

CookiesAuthStrategy is a strategy for cookies auth

func NewCookiesAuthStrategy

func NewCookiesAuthStrategy(data *Secret) *CookiesAuthStrategy

NewCookiesAuthStrategy creates a new cookies auth strategy

func (*CookiesAuthStrategy) Apply

func (s *CookiesAuthStrategy) Apply(req *http.Request)

Apply applies the cookies auth strategy to the request

func (*CookiesAuthStrategy) ApplyOnRR

func (s *CookiesAuthStrategy) ApplyOnRR(req *retryablehttp.Request)

ApplyOnRR applies the cookies auth strategy to the retryable request

type HeadersAuthStrategy

type HeadersAuthStrategy struct {
	Data *Secret
}

HeadersAuthStrategy is a strategy for headers auth

func NewHeadersAuthStrategy

func NewHeadersAuthStrategy(data *Secret) *HeadersAuthStrategy

NewHeadersAuthStrategy creates a new headers auth strategy

func (*HeadersAuthStrategy) Apply

func (s *HeadersAuthStrategy) Apply(req *http.Request)

Apply applies the headers auth strategy to the request NOTE: This preserves exact header casing (e.g., barAuthToken stays as barAuthToken) This is useful for APIs that require case-sensitive header names

func (*HeadersAuthStrategy) ApplyOnRR

func (s *HeadersAuthStrategy) ApplyOnRR(req *retryablehttp.Request)

ApplyOnRR applies the headers auth strategy to the retryable request NOTE: This preserves exact header casing (e.g., barAuthToken stays as barAuthToken) This is useful for APIs that require case-sensitive header names

type KV

type KV struct {
	Key   string `json:"key" yaml:"key"` // Header key (preserves exact casing)
	Value string `json:"value" yaml:"value"`
}

func (*KV) Validate

func (k *KV) Validate() error

type QueryAuthStrategy

type QueryAuthStrategy struct {
	Data *Secret
}

QueryAuthStrategy is a strategy for query auth

func NewQueryAuthStrategy

func NewQueryAuthStrategy(data *Secret) *QueryAuthStrategy

NewQueryAuthStrategy creates a new query auth strategy

func (*QueryAuthStrategy) Apply

func (s *QueryAuthStrategy) Apply(req *http.Request)

Apply applies the query auth strategy to the request

func (*QueryAuthStrategy) ApplyOnRR

func (s *QueryAuthStrategy) ApplyOnRR(req *retryablehttp.Request)

ApplyOnRR applies the query auth strategy to the retryable request

type Secret

type Secret struct {
	Type         string   `json:"type" yaml:"type"`
	Domains      []string `json:"domains" yaml:"domains"`
	DomainsRegex []string `json:"domains-regex" yaml:"domains-regex"`
	Headers      []KV     `json:"headers" yaml:"headers"` // Headers preserve exact casing (useful for case-sensitive APIs)
	Cookies      []Cookie `json:"cookies" yaml:"cookies"`
	Params       []KV     `json:"params" yaml:"params"`
	Username     string   `json:"username" yaml:"username"` // can be either email or username
	Password     string   `json:"password" yaml:"password"`
	Token        string   `json:"token" yaml:"token"` // Bearer Auth token
}

Secret is a struct for secret or credential

func (*Secret) GetStrategy

func (s *Secret) GetStrategy() AuthStrategy

GetStrategy returns the auth strategy for the secret

func (*Secret) Validate

func (s *Secret) Validate() error

Jump to

Keyboard shortcuts

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