Documentation
¶
Overview ¶
Package middleware provides HTTP middleware for TxToken verification and propagation.
Index ¶
- func ClaimsFromContext(ctx context.Context) *token.Claims
- func ExportedTokenContextKey() contextKey
- func TokenFromContext(ctx context.Context) string
- func VerifyTxToken(verifier *verify.Verifier) func(http.Handler) http.Handler
- func WithToken(ctx context.Context, tokenString string) context.Context
- type PropagateTransport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClaimsFromContext ¶
ClaimsFromContext extracts the verified TxToken claims from the request context. Returns nil if no claims are present (request was not verified).
func ExportedTokenContextKey ¶
func ExportedTokenContextKey() contextKey
ExportedTokenContextKey returns the context key used for storing the TxToken. This is primarily useful for tests and advanced usage where direct context manipulation is needed.
func TokenFromContext ¶
TokenFromContext extracts the raw TxToken string from the request context. Returns an empty string if no token is present.
func VerifyTxToken ¶
VerifyTxToken returns HTTP middleware that verifies the Txn-Token header on incoming requests. If valid, the claims are stored in the request context and the next handler is called. If invalid or missing, a 401 response is returned.
Types ¶
type PropagateTransport ¶
type PropagateTransport struct {
// contains filtered or unexported fields
}
PropagateTransport is an http.RoundTripper that automatically propagates the Txn-Token header from the request context to outbound HTTP requests. Wrap your existing transport with NewPropagateTransport to enable propagation.
func NewPropagateTransport ¶
func NewPropagateTransport(base http.RoundTripper) *PropagateTransport
NewPropagateTransport creates a new PropagateTransport wrapping the given base transport. If base is nil, http.DefaultTransport is used.