Documentation
¶
Index ¶
- Constants
- Variables
- func Middleware(v Verifier, opts ...Option) func(next http.Handler) http.Handler
- func NormalizeHost(host string) string
- func QAMiddleware(opts ...Option) func(http.Handler) http.Handler
- func QAMiddlewareWithRemote(baseURL string, opts ...Option) func(http.Handler) http.Handler
- func UserIDFromContext(ctx context.Context) (string, bool)
- type HostPolicy
- type Option
- func WithBadRequestHandler(f func(w http.ResponseWriter, r *http.Request, err error)) Option
- func WithBodyReader(f func(r *http.Request) ([]byte, error)) Option
- func WithComputeBodySHA256(v bool) Option
- func WithHostPolicy(p HostPolicy) Option
- func WithPathFunc(f func(r *http.Request) string) Option
- func WithRequireAuth(v bool) Option
- func WithUnauthorizedHandler(f func(w http.ResponseWriter, r *http.Request)) Option
- type Options
- type QAHeaderFields
- type RemoteVerifier
- type Verifier
- type VerifyInput
- type VerifyResult
Constants ¶
View Source
const (
CtxUserIDKey ctxKey = "quantumauth_user_id"
)
View Source
const DefaultRemoteBaseURL = "https://api.quantumauth.io/quantum-auth/v1"
Variables ¶
View Source
var ( ErrUnauthorized = errors.New("quantumauth: unauthorized") // ErrBadRequest means the request could not be verified due to missing/invalid inputs. ErrBadRequest = errors.New("quantumauth: bad request") )
Functions ¶
func NormalizeHost ¶
NormalizeHost makes host deterministic but DOES NOT guess ports. Recommendation: keep port if present; strip only junk.
func QAMiddlewareWithRemote ¶
Types ¶
type HostPolicy ¶
type HostPolicy struct {
// If empty, forwarded headers are NEVER trusted.
TrustedProxyCIDRs []string
// If true, also parse RFC 7239 Forwarded header (Forwarded: host=...).
TrustForwardedHeader bool
}
HostPolicy selects which host is treated as canonical host for signing/verification.
func (HostPolicy) CanonicalHost ¶
func (p HostPolicy) CanonicalHost(r *http.Request) (string, error)
type Option ¶
type Option func(*Options)
func WithBadRequestHandler ¶
func WithBodyReader ¶ added in v0.0.4
func WithComputeBodySHA256 ¶ added in v0.0.4
func WithHostPolicy ¶
func WithHostPolicy(p HostPolicy) Option
func WithRequireAuth ¶
func WithUnauthorizedHandler ¶
func WithUnauthorizedHandler(f func(w http.ResponseWriter, r *http.Request)) Option
type QAHeaderFields ¶
type QAHeaderFields struct {
SigTPM string
SigPQ string
// Future: challenge, kid, etc.
Extra map[string]string
}
func ParseAuthorizationQuantumAuth ¶
func ParseAuthorizationQuantumAuth(auth string) (*QAHeaderFields, error)
ParseAuthorizationQuantumAuth parses:
Authorization: QuantumAuth sig_tpm="...", sig_pq="..."
type RemoteVerifier ¶
type RemoteVerifier struct {
// Example: https://api.quantumauth.io/quantum-auth/v1
// The middleware will POST {BaseURL}/auth/verify
BaseURL string
// Optional: provide a custom client; defaults to a sane one.
Client *http.Client
// Optional: allow injecting extra headers to QA backend (api key, etc.)
ExtraHeaders map[string]string
}
func NewRemoteVerifier ¶
func NewRemoteVerifier() *RemoteVerifier
func (*RemoteVerifier) Verify ¶
func (r *RemoteVerifier) Verify(ctx context.Context, in VerifyInput) (*VerifyResult, error)
type Verifier ¶
type Verifier interface {
Verify(ctx context.Context, in VerifyInput) (*VerifyResult, error)
}
type VerifyInput ¶
type VerifyResult ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.