middleware

package
v0.0.0-...-30a92e5 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContextKeyAuthN is the key to access the authentication information in the context.
	ContextKeyAuthN = util.ContextKey("authn")
	// AuthNAnonymousUserID is the value of the user ID if no credentials were provided.
	AuthNAnonymousUserID = "anonymous"
	// AuthNAnonymousOrganisationID is the value of organisation ID if no credentials were provided.
	AuthNAnonymousOrganisationID = "global"
)
View Source
const (
	// ContextKeyAuthZ is the key to access the authorization information in the context, which indicates field-level access.
	ContextKeyAuthZ = util.ContextKey("authz")
)
View Source
const (
	// ContextKeyDB is the key to access the database in the context.
	ContextKeyDB = util.ContextKey("db")
)

Variables

This section is empty.

Functions

func AuthN

func AuthN() func(next http.Handler) http.Handler

AuthN is a middleware that extracts the user information from the JWT.

func AuthZ

func AuthZ(model interface{}) func(next http.Handler) http.Handler

AuthZ is a middleware that verifies a user and its roles against access control policies.

func CORS

func CORS() func(next http.Handler) http.Handler

CORS configures the cross-origin resource sharing policies. Required for most REST APIs to be accessed from within the browser via for example the native Fetch API.

func DB

func DB(db *gorm.DB) func(next http.Handler) http.Handler

DB is a middleware that exposes the database as part of the request context.

func Logger

func Logger(httpLoglevel int) func(next http.Handler) http.Handler

Logger is a middleware that logs response codes, paths and times.

Types

type AuthNInfo

type AuthNInfo struct {
	UserID         string
	OrganisationID string
}

AuthNInfo stores information about the authenticated entity, which can be either a user or a service.

type AuthZRequest

type AuthZRequest struct {
	// The type of access as a CRUD verb.
	Verb string
	// The requested HTTP resource as a generic endpoint.
	Resource string
}

AuthZRequest defines an authorization request.

func NewAuthZRequest

func NewAuthZRequest(httpMethod string, httpPath string) AuthZRequest

NewAuthZRequest creates a new authorization request by parsing the URL path and URL method.

Jump to

Keyboard shortcuts

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