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).
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).
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.
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.