Documentation ¶
Overview ¶
Authentication/authorization
Package service provides functionality to support all services
Index ¶
- Constants
- Variables
- func ClearRequestContext(r *http.Request)
- func IsAuthentic(msg Signed, key []byte) (bool, error)
- func RequestContext(r *http.Request) context.Context
- func RequestContextAuth(r *http.Request) map[string]interface{}
- func SetRequestContext(r *http.Request, ctx *Context)
- func SetRequestContextVar(r *http.Request, key, value interface{})
- func Sign(msg Signable, key []byte) ([]byte, error)
- func TimeoutHandler(logFunc func(msg string, ctx ...interface{}), d time.Duration, h http.Handler) http.Handler
- type Authorization
- func (a *Authorization) Decode(key []byte) error
- func (a *Authorization) Encode(key []byte) error
- func (a *Authorization) Expires(t time.Time)
- func (a *Authorization) Expiry() time.Time
- func (a *Authorization) HashFunc() func() hash.Hash
- func (a *Authorization) Message() ([]byte, error)
- func (a *Authorization) ReadFrom(r io.Reader) (int64, error)
- func (a *Authorization) Serialized() (string, error)
- func (a *Authorization) Signature() ([]byte, error)
- func (a *Authorization) WriteTo(w io.Writer) (int64, error)
- type Context
- func (ctx *Context) APIKeychain() *Keychain
- func (ctx *Context) Config() *config.Config
- func (ctx *Context) Log() log15.Logger
- func (ctx *Context) PaymentDB(ros ...dbRequestReadOnly) *sql.DB
- func (ctx *Context) PrincipalDB(ros ...dbRequestReadOnly) *sql.DB
- func (ctx *Context) RateLimitHandler(parent http.Handler) http.Handler
- func (ctx *Context) SetPaymentDB(w, ro *sql.DB)
- func (ctx *Context) SetPrincipalDB(w, ro *sql.DB)
- func (ctx *Context) Value(key interface{}) interface{}
- func (ctx *Context) WebKeychain() *Keychain
- func (ctx *Context) WithValue(key, value interface{}) *Context
- type Keychain
- func (k *Keychain) AddBinKey(key []byte)
- func (k *Keychain) AddKey(newKey string) error
- func (k *Keychain) BinKey() ([]byte, error)
- func (k *Keychain) GenerateKey() ([]byte, error)
- func (k *Keychain) Key() (string, error)
- func (k *Keychain) KeyCount() int
- func (k *Keychain) MatchKey(s Signed) ([]byte, error)
- type Signable
- type Signed
Constants ¶
const ( // ContextVarAuthKey is the name of the key under which the auth container // will be stored in request contexts ContextVarAuthKey = "Auth" )
const ( // MaxMsgSize is the maximum size the (encoded) content of an Authorization container // can have MaxMsgSize = 4096 )
Variables ¶
var ( ErrDecrypt = errors.New("error decrypting container") ErrMsgSize = errors.New("message too big") ErrInvalidKey = errors.New("invalid key") ErrNoKeys = errors.New("no keys in keychain") ErrNoMatchingKey = errors.New("no matching key for signature") )
var (
ErrTimedOut = errors.New("http Write: already timed out")
)
var ReadOnly = dbRequestReadOnly(true)
ReadOnly is a possible parameter for the ctx.xDB() methods. If this parameter is passed to the methods, they will attempt to return the read-only database connection
Functions ¶
func ClearRequestContext ¶
ClearRequestContext removes the associated context for the given request
func IsAuthentic ¶
IsAuthentic returns true if the signed message has a correct signature for the given key
func RequestContext ¶
RequestContext returns a request associated with the given request
func RequestContextAuth ¶
RequestAuthUserKey returns a request associated with the given request
func SetRequestContext ¶
SetRequestContext sets a new context for a request
func SetRequestContextVar ¶
SetRequestContextVar associates a var with a request context
Types ¶
type Authorization ¶
type Authorization struct { Payload map[string]interface{} H func() hash.Hash // contains filtered or unexported fields }
Authorization is a container which can hold arbitrary authorization data, can be encrypted and signed and safely passed between services. As long as those share the same keychain, they are able to access the encrypted data.
func NewAuthorization ¶
func NewAuthorization(h func() hash.Hash) *Authorization
NewAuthorization creates a new authorization container with the given Hash function for signing and key derivation
func (*Authorization) Decode ¶
func (a *Authorization) Decode(key []byte) error
/ Decode decodes a container after it was read using the ReadFrom() method
func (*Authorization) Encode ¶
func (a *Authorization) Encode(key []byte) error
Encode encodes the message, encrypting its contents and signing it with the given key
Encode() must be called prior to writing it using the WriteTo() method, otherwise secret data might be written to the Writer
func (*Authorization) Expires ¶
func (a *Authorization) Expires(t time.Time)
Expires sets the expiry time
func (*Authorization) Expiry ¶
func (a *Authorization) Expiry() time.Time
Expiry returns the expiry time
func (*Authorization) HashFunc ¶
func (a *Authorization) HashFunc() func() hash.Hash
HashFunc implementing the Signable interface
func (*Authorization) Message ¶
func (a *Authorization) Message() ([]byte, error)
Message implementing the Signable interface
func (*Authorization) ReadFrom ¶
func (a *Authorization) ReadFrom(r io.Reader) (int64, error)
ReadFrom reads a serialized authorization container from the given reader
After the container is read, it should be decoded using the Decode() method
func (*Authorization) Serialized ¶
func (a *Authorization) Serialized() (string, error)
func (*Authorization) Signature ¶
func (a *Authorization) Signature() ([]byte, error)
Signature implementing the Signed interface
type Context ¶
Context is a custom context which is used by the service pkg
func NewContext ¶
NewContext creates a new service context for use in the service pkg
func (*Context) APIKeychain ¶
Keychain returns the authorization container keychain associated with the context
func (*Context) Log ¶
func (ctx *Context) Log() log15.Logger
Log returns the log15.Logger associated with the context
func (*Context) PaymentDB ¶
PaymentDB returns the *sql.DB for the payment DB If the parameter(s) contain a service.ReadOnly, the read-only connection will be returned if present
func (*Context) PrincipalDB ¶
PrincipalDB returns the *sql.DB for the principal DB If the parameter(s) contain a service.ReadOnly, the read-only connection will be returned if present
func (*Context) RateLimitHandler ¶
RateLimitHandler wraps the given handler with a context-wide rate limit
The capacity of the ctx.rateLimit buffered channel determines the maximum amount of concurrent requests on this context.
func (*Context) SetPaymentDB ¶
SetPaymentDB sets the payment DB connection(s) It will panic if the write connection is nil
func (*Context) SetPrincipalDB ¶
SetPrincipalDB sets the principal DB connection(s) It will panic if the write connection is nil
func (*Context) Value ¶
func (ctx *Context) Value(key interface{}) interface{}
Value wraps the Context.Value
func (*Context) WebKeychain ¶
type Keychain ¶
type Keychain struct {
// contains filtered or unexported fields
}
Keychain stores (and rotates) keys for authorization container encryption
func (*Keychain) BinKey ¶
BinKey returns a binary key from the keychain which can be used to encrypt authorization containers
func (*Keychain) GenerateKey ¶
GenerateKey generates a random key, adds it to the keychain and returns the generated key
func (*Keychain) Key ¶
Key returns a hex-encoded key from the keychain which can be used to encrypt authorization containers
Directories ¶
Path | Synopsis |
---|---|
Package api provides the API service It includes the HTTP Handler to serve the paymentd API
|
Package api provides the API service It includes the HTTP Handler to serve the paymentd API |
v1
Package v1 provides API functionality for the version: 1.x
|
Package v1 provides API functionality for the version: 1.x |
Package payment provides the payment service This service handles all payment related business logic
|
Package payment provides the payment service This service handles all payment related business logic |
notification
Package notification provides notification (or callback) related functionality
|
Package notification provides notification (or callback) related functionality |
notification/v2
Package notification provides the Notification type for notifications in the version: 2.x
|
Package notification provides the Notification type for notifications in the version: 2.x |
Package provider provides functionality for dealing with Payment Service Providers (PSPs)
|
Package provider provides functionality for dealing with Payment Service Providers (PSPs) |
fritzpay
Package fritzpay provides the Test-/Demo-Payment Service Provider (PSP) FritzPay This package demonstrates how to add new PSP drivers.
|
Package fritzpay provides the Test-/Demo-Payment Service Provider (PSP) FritzPay This package demonstrates how to add new PSP drivers. |
paypal_rest
Package paypal_rest provides the PayPal REST-API provider driver Paypal data types
|
Package paypal_rest provides the PayPal REST-API provider driver Paypal data types |
stripe
Package stripe provides the stripe provider driver
|
Package stripe provides the stripe provider driver |
Package web provides the web service through which the end user will interact with payments.
|
Package web provides the web service through which the end user will interact with payments. |