auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

README

Auth Package

The auth package provides modular authentication strategies for the remote client.

Authenticator Interface

All strategies implement the Authenticator interface, allowing them to be easily injected into any remote.Client.

type Authenticator interface {
    Apply(req *http.Request) error
}

Supported Strategies

API Key Authentication

Uses a custom header (e.g., X-API-Key) with a fixed value.

auth.NewAPIKey(auth.APIKeyConfig{
    Key:   "X-Custom-Key",
    Value: "my-secret-key",
})
Bearer Token Authentication

Uses the standard Authorization: Bearer <token> header.

auth.NewBearer(auth.BearerConfig{Token: "my-jwt-token"})
OAuth2 Client Credentials Flow

Implements the OAuth2 Client Credentials flow with the following features:

  • Automatic token caching.
  • Expiry handling with a 1-minute safety buffer.
  • Synchronized token updates to prevent race conditions.
  • Scope support.
auth.NewOAuth2(auth.OAuth2Config{
    TokenURL:     "https://identity.example.com/oauth2/token",
    ClientID:     "my-client-id",
    ClientSecret: "my-client-secret",
    Scopes:       []string{"read", "write"},
})

Strategy Configuration

APIKeyConfig

Used when the authentication type is "api_key".

Field Type Description
key string The HTTP header name (e.g., "X-API-Key").
value string The static key value.
BearerConfig

Used when the authentication type is "bearer".

Field Type Description
token string The static bearer token.
OAuth2Config

Used when the authentication type is "oauth2".

Field Type Description
token_url string The OAuth2 token endpoint URL.
client_id string The client identifier.
client_secret string The client secret.
scopes []string Optional list of requested scopes.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	// contains filtered or unexported fields
}

func NewAPIKey

func NewAPIKey(cfg APIKeyConfig) *APIKey

func (*APIKey) Apply

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

type APIKeyConfig

type APIKeyConfig struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Authenticator

type Authenticator interface {
	Apply(req *http.Request) error
}

Authenticator defines an interface for applying authentication to outgoing requests.

type Bearer

type Bearer struct {
	// contains filtered or unexported fields
}

func NewBearer

func NewBearer(cfg BearerConfig) *Bearer

func (*Bearer) Apply

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

type BearerConfig

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

type OAuth2

type OAuth2 struct {
	// contains filtered or unexported fields
}

func NewOAuth2

func NewOAuth2(cfg OAuth2Config) *OAuth2

func (*OAuth2) Apply

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

type OAuth2Config

type OAuth2Config struct {
	TokenURL     string   `json:"token_url"`
	ClientID     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret"`
	Scopes       []string `json:"scopes,omitempty"`
}

Jump to

Keyboard shortcuts

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