payforput

package
v0.0.0-...-d0e8f4b Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultValidator

func DefaultValidator(r *http.Request, secret string) bool

DefaultValidator is the default request payment validator

func GenerateHMACToken

func GenerateHMACToken(message, secret string) string

GenerateHMACToken generates an HMAC token for a given url with the provided secret

func RandString

func RandString(n int) string

RandString is a random string implementation taken from https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go It implements an easy way to get an ephemeral HMAC secret if one is not configured.

func ValidateHMACToken

func ValidateHMACToken(message, messageMAC64, secret string) bool

ValidateHMACToken validates that an HMAC token matches for a given URL

Types

type PaymentEnforcer

type PaymentEnforcer struct {
	// Location to where we should redirect payments, and has the PaymentHandler
	// installed
	PaymentURL string
	// Validator is a func that validates that a request has a valid proof of
	// payment
	Validator ValidatorFunc
	// Secret is the HMAC secret used for generating and validating tokens
	// NOTE: This may be swapped out at a later date.
	Secret string
}

PaymentEnforcer ensures that the request has been paid for properly by checking for a payment authorization. If there is no payment authorization header, then we send a BIP70 payment request

func New

func New(PaymentURL string, secret string, Validator ValidatorFunc) *PaymentEnforcer

New returns a new payment enforcer that can be used for easy BIP70 integration for the keyserver.

func (*PaymentEnforcer) Middleware

func (e *PaymentEnforcer) Middleware(prevHandler http.Handler) http.Handler

Middleware is a middleware function that ensures a payment has been made before allowing this endpoint to be accessed.

func (*PaymentEnforcer) PaymentHandler

func (e *PaymentEnforcer) PaymentHandler(w http.ResponseWriter,
	r *http.Request)

PaymentHandler is an http handler that implements a check for payment, along with a redirect to the original location with the key

type ValidatorFunc

type ValidatorFunc func(r *http.Request, secret string) bool

ValidatorFunc is the type of unction which can indicate if a request has the appropriate headers to have been paid.

Jump to

Keyboard shortcuts

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