contexts

package
v0.12.8 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyUnknown contextKey = iota
	KeyClaims
)

Allocate context keys to simplify context key usage in Ensign

Variables

View Source
var (
	ErrNoClaimsInContext = errors.New("no claims available in context")
	ErrNotAuthorized     = errors.New("claims do not have required permission")
)

Functions

func Authorize added in v0.5.1

func Authorize(ctx context.Context, permission string) (*tokens.Claims, error)

Authorize reduces a multistep process into a single step; fetching the claims from the context and checking that the claims have the required permission. If there are no claims in the context or the permission is invalid, then an error is returned.

func ClaimsFrom

func ClaimsFrom(ctx context.Context) (*tokens.Claims, bool)

ClaimsFrom returns the claims from the context if they exist or false if not.

func Stream

Stream allows users to override the context on a grpc.ServerStream handler so that it returns a new context rather than the old context. It is advised to use the original stream's context as the new context's parent but this method does not enforce it and instead simply returns the context specified.

func WithClaims

func WithClaims(parent context.Context, claims *tokens.Claims) context.Context

WithClaims returns a copy of the parent context with the access claims stored as a value on the new context. Users can fetch the claims using the ClaimsFrom function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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