middleware

package
v7.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BearerAuthFuncGRPC added in v7.6.0

func BearerAuthFuncGRPC(auth authentication.Authentication) grpc_auth.AuthFunc

BearerAuthFuncGRPC returns a new grpc_auth.AuthFunc to use with the gazebo-web authentication library.

The passed in context.Context will contain the gRPC metadata.MD object (for header-based authentication) and the peer.Peer information that can contain transport-based credentials (e.g. `credentials.AuthInfo`).

auth := authentication.New[...]()

srv := grpc.NewServer(
	grpc.StreamInterceptor(grpc_auth.StreamServerInterceptor(BearerAuthFuncGRPC(auth))),
	grpc.UnaryInterceptor(grpc_auth.UnaryServerInterceptor(BearerAuthFuncGRPC(auth))),
)

func ExtractGRPCAuthSubject added in v7.13.0

func ExtractGRPCAuthSubject(ctx context.Context) (string, error)

ExtractGRPCAuthSubject extracts the authentication subject (sub) claim from the context metadata. This claim is usually injected in a middleware such as BearerToken or BearerAuthFuncGRPC, if present.

From the RFC7519, section 4.1.2: https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2

The "sub" (subject) claim identifies the principal that is the subject of the JWT. The claims in a JWT are normally
statements about the subject. The subject value MUST either be scoped to be locally unique in the context of the
issuer or be globally unique. The processing of this claim is generally application specific. The "sub" value is a
case-sensitive string containing a StringOrURI value.

This function only works with gRPC requests. It returns an error if the metadata couldn't be parsed or the subject is not present.

func InjectGRPCAuthSubject added in v7.13.0

func InjectGRPCAuthSubject(ctx context.Context, sub string) context.Context

InjectGRPCAuthSubject injects the authentication subject (sub) claim into the given context metadata. See ExtractGRPCAuthSubject for information on how to extract this value.

Types

type Extractor

type Extractor = request.Extractor

Extractor extracts a string value from an HTTP request. It's usually used to extract a header from an HTTP request, but can also be used for extracting a user and password from the body.

There are a few implementations already provided by the request package, for example: Bearer tokens: request.BearerExtractor

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is used to modify or augment the behavior of an HTTP request handler.

func BearerToken

func BearerToken(authentication authentication.Authentication) Middleware

BearerToken returns a Middleware for authenticating users using Bearer Tokens in JWT format.

Jump to

Keyboard shortcuts

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