Documentation
¶
Overview ¶
Package middleware exposes middlewares and helpers functions related to context get/set of DatabaseConfig and Auth.
Index ¶
- Constants
- func Chain(h http.Handler, middlewares ...Middleware) http.Handler
- func Extract(r *http.Request, withAuth bool) (model.DatabaseConfig, model.Auth, error)
- func ValidateAuthKey(datastore database.Persister, volatile cache.Volatilizer, ctx context.Context, ...) (model.Auth, error)
- func ValidateRootToken(datastore database.Persister, base, token string) (model.User, error)
- type BillingPortalGetter
- type ContextKey
- type Middleware
Constants ¶
const (
RootRole = 100
)
Variables ¶
This section is empty.
Functions ¶
func Chain ¶
func Chain(h http.Handler, middlewares ...Middleware) http.Handler
Chain creates a request pipeline from which the Middleware are chained together and h is the last Handler executed.
Types ¶
type BillingPortalGetter ¶ added in v1.4.0
type ContextKey ¶
type ContextKey int
const ( ContextAuth ContextKey = iota ContextBase )
Context keys that are needed for all requests pipeline.
type Middleware ¶
Middleware is a standard http.Handler
func Cors ¶
func Cors() Middleware
Cors enables calls via remote origin to handle external JavaScript calls mainly.
func RequireAuth ¶
func RequireAuth(datastore database.Persister, volatile cache.Volatilizer) Middleware
RequireAuth validates that a session token is valid. If not valid a 401 HTTP error is returned.
The request must have an HTTP Header of: Authorization: Bearer "session-token".
func RequireRoot ¶
func RequireRoot(datastore database.Persister, volatile cache.Volatilizer) Middleware
RequireRoot validates that the token provided is for a "root" user.
func WithDB ¶
func WithDB(datastore database.Persister, volatile cache.Volatilizer, g BillingPortalGetter) Middleware
WithDB validates the presence of the "SB-PUBLIC-KEY" and fetches the proper DatabaseConfig for this Tenant so the rest of the pipeline can executes actions on the right database.