auth

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0 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

Overview

Package auth provides authentication mechanisms for cc-relay. It supports multiple authentication methods including API keys and OAuth Bearer tokens used by Claude Code subscriptions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeyAuthenticator

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

APIKeyAuthenticator validates x-api-key header authentication. Uses constant-time comparison to prevent timing attacks.

func NewAPIKeyAuthenticator

func NewAPIKeyAuthenticator(expectedKey string) *APIKeyAuthenticator

NewAPIKeyAuthenticator creates a new API key authenticator. The expected key is hashed at creation time for secure comparison.

Security note: SHA-256 is appropriate for API key hashing because: - API keys are high-entropy secrets (32+ random characters), not passwords - SHA-256 provides sufficient pre-image resistance for high-entropy inputs - Passwords require slow hashes (bcrypt/argon2) due to limited entropy - Constant-time comparison prevents timing attacks (see Validate method).

func (*APIKeyAuthenticator) Type

func (a *APIKeyAuthenticator) Type() Type

Type returns the authentication type (api_key).

func (*APIKeyAuthenticator) Validate

func (a *APIKeyAuthenticator) Validate(r *http.Request) Result

Validate checks the x-api-key header against the expected value. Uses constant-time comparison to prevent timing attacks.

type Authenticator

type Authenticator interface {
	// Validate checks the request for valid credentials.
	// Returns a Result with Valid=true if authentication succeeds.
	Validate(r *http.Request) Result

	// Type returns the authentication type this authenticator handles.
	Type() Type
}

Authenticator defines the interface for authentication mechanisms.

type BearerAuthenticator

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

BearerAuthenticator validates Authorization: Bearer token authentication. This is used by Claude Code subscription users.

func NewBearerAuthenticator

func NewBearerAuthenticator(secret string) *BearerAuthenticator

NewBearerAuthenticator creates a new Bearer token authenticator. If secret is empty, any valid bearer token format is accepted. If secret is provided, tokens are validated against it using constant-time comparison.

func (*BearerAuthenticator) Type

func (a *BearerAuthenticator) Type() Type

Type returns the authentication type (bearer).

func (*BearerAuthenticator) Validate

func (a *BearerAuthenticator) Validate(r *http.Request) Result

Validate checks the Authorization header for a valid Bearer token. Returns a Result with Valid=true if authentication succeeds.

type ChainAuthenticator

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

ChainAuthenticator tries multiple authenticators in order. The first authenticator to succeed is used. If all fail, the last error is returned.

func NewChainAuthenticator

func NewChainAuthenticator(authenticators ...Authenticator) *ChainAuthenticator

NewChainAuthenticator creates a chain of authenticators. Authenticators are tried in order; first success wins.

func (*ChainAuthenticator) Type

func (c *ChainAuthenticator) Type() Type

Type returns TypeNone since this is a meta-authenticator.

func (*ChainAuthenticator) Validate

func (c *ChainAuthenticator) Validate(request *http.Request) Result

Validate tries each authenticator in order until one succeeds. Returns the first successful result, or the last failure if all fail.

type Result

type Result struct {
	// Type indicates which authentication method was used (or attempted).
	Type Type
	// Error contains the error message if authentication failed.
	Error string
	// Valid indicates whether authentication succeeded.
	Valid bool
}

Result contains the outcome of an authentication attempt.

type Type

type Type string

Type represents the authentication method used.

const (
	// TypeAPIKey represents x-api-key header authentication.
	TypeAPIKey Type = "api_key"
	// TypeBearer represents Authorization: Bearer token authentication.
	TypeBearer Type = "bearer"
	// TypeNone represents no authentication or failed auth with no valid type.
	TypeNone Type = "none"
)

Jump to

Keyboard shortcuts

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