middleware

package
v0.0.0-...-bb96c00 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AuthenticatedUserContextKey is context key that contains the user object
	AuthenticatedUserContextKey = contextKey{/* contains filtered or unexported fields */}

	// UserTokenContextKey context key that contains jwt token
	UserTokenContextKey = contextKey{"user-token"}

	// TokenClaimsContextKey context key that contains jwt token claims
	TokenClaimsContextKey = contextKey{"token-claims"}
)
View Source
var (
	RestEndpoint = strings.TrimSpace(os.Getenv("FRONTIER_REST_ENDPOINT"))
)

Functions

func WithAuthzAllowByDefault

func WithAuthzAllowByDefault() func(*AuthHandler)

func WithHTTPClient

func WithHTTPClient(client pkg.HTTPClient) func(*AuthHandler)

func WithJWKSetCache

func WithJWKSetCache(jwkSetCache pkg.FrontierJWKCache) func(*AuthHandler)

func WithRESTEndpoint

func WithRESTEndpoint(endpoint *url.URL) func(*AuthHandler)

WithRESTEndpoint provides url for frontier server For e.g. http://localhost:7400

func WithResourceControlMapping

func WithResourceControlMapping(rcm map[ResourcePath]ResourceControlFunc) func(*AuthHandler)

Types

type AuthHandler

type AuthHandler struct {
	// contains filtered or unexported fields
}

func NewAuthHandler

func NewAuthHandler(opts ...func(auth *AuthHandler)) (*AuthHandler, error)

NewAuthHandler creates a middleware for net/http router that checks all incoming requests for valid authorization. WithAuthorization is done using either user json web token in WithAuthorization header or session cookies. Add this middleware on routes that needs to be protected via Frontier

func (*AuthHandler) MapRequestToResource

func (ea *AuthHandler) MapRequestToResource(r *http.Request) (ResourceControl, bool)

func (*AuthHandler) WithAuthentication

func (ea *AuthHandler) WithAuthentication(base http.Handler) http.HandlerFunc

func (*AuthHandler) WithAuthorization

func (ea *AuthHandler) WithAuthorization(base http.Handler) http.HandlerFunc

type ResourceControl

type ResourceControl struct {
	// Resource should be in the form of "object_namespace:object_id"
	// for e.g. "project:07d00b42-7d5a-46b4-9d57-dda3fb7721b9"
	Resource   string
	Permission string
}

type ResourceControlFunc

type ResourceControlFunc func(*http.Request) ResourceControl

type ResourcePath

type ResourcePath struct {
	Path   string
	Method string
}

Jump to

Keyboard shortcuts

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