authforwarder

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package authforwarder is a combination of http middleware and grpc injectors that passes the content of the "Authorization" header from the incoming http request to any outgoing grpc calls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractAuthorization

func ExtractAuthorization(ctx context.Context) string

ExtractAuthorization shouldn't be public, but it temporarily is to keep things working.

func HTTPMiddleware

func HTTPMiddleware(next http.Handler) http.Handler

HTTPMiddleware injects the authorization header into the context.

func StreamClientInterceptor

func StreamClientInterceptor(
	ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn,
	method string, streamer grpc.Streamer, opts ...grpc.CallOption,
) (grpc.ClientStream, error)

StreamClientInterceptor does the same for streaming requests. Note that we don't try to intercept the streaming messages.

func StreamInterceptor

func StreamInterceptor(
	srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler,
) error

StreamInterceptor will process the authorization header, convert it to a prefix, and then inject it into the context, but for streams.

func UnaryClientInterceptor

func UnaryClientInterceptor(
	ctx context.Context,
	method string, req interface{}, reply interface{},
	cc *grpc.ClientConn, invoker grpc.UnaryInvoker,
	opts ...grpc.CallOption,
) error

UnaryClientInterceptor extracts the auth header value from the context and appends it to the outgoing metadata.

func UnaryInterceptor

func UnaryInterceptor(
	ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler,
) (any, error)

Types

type AuthRoundTripper

type AuthRoundTripper struct {
	Proxied http.RoundTripper
}

AuthRoundTripper is a http client "middleware" that extracts the auth middleware out of the context and injects it into the request.

func (AuthRoundTripper) RoundTrip

func (art AuthRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

Roundtrip does the actual injection.

Jump to

Keyboard shortcuts

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