bearertoken

package
v1.64.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const Key = "bearer.token"
View Source
const StoragePropagationKey = "storage.propagate.token"

StoragePropagationKey is a key for viper configuration to pass this option to storage plugins.

Variables

This section is empty.

Functions

func ContextWithBearerToken

func ContextWithBearerToken(ctx context.Context, token string) context.Context

ContextWithBearerToken set bearer token in context.

func GetBearerToken

func GetBearerToken(ctx context.Context) (string, bool)

GetBearerToken from context, or empty string if there is no token.

func NewStreamClientInterceptor added in v1.63.0

func NewStreamClientInterceptor() grpc.StreamClientInterceptor

NewStreamClientInterceptor injects the bearer token header into gRPC request metadata.

func NewStreamServerInterceptor added in v1.63.0

func NewStreamServerInterceptor() grpc.StreamServerInterceptor

NewStreamServerInterceptor creates a new stream interceptor that injects the bearer token into the context if available.

func NewUnaryClientInterceptor added in v1.63.0

func NewUnaryClientInterceptor() grpc.UnaryClientInterceptor

NewUnaryClientInterceptor injects the bearer token header into gRPC request metadata.

func NewUnaryServerInterceptor added in v1.63.0

func NewUnaryServerInterceptor() grpc.UnaryServerInterceptor

NewUnaryServerInterceptor creates a new unary interceptor that injects the bearer token into the context if available.

func PropagationHandler

func PropagationHandler(logger *zap.Logger, h http.Handler) http.Handler

PropagationHandler returns a http.Handler containing the logic to extract the Bearer token from the Authorization header of the http.Request and insert it into request.Context for propagation. The token can be accessed via GetBearerToken.

func ValidTokenFromGRPCMetadata added in v1.63.0

func ValidTokenFromGRPCMetadata(ctx context.Context, bearerHeader string) (string, error)

extract bearer token from the metadata

Types

type RoundTripper

type RoundTripper struct {
	// Transport is the underlying http.RoundTripper being wrapped. Required.
	Transport http.RoundTripper

	// StaticToken is the pre-configured bearer token. Optional.
	StaticToken string

	// OverrideFromCtx enables reading bearer token from Context.
	OverrideFromCtx bool
}

RoundTripper wraps another http.RoundTripper and injects an authentication header with bearer token into requests.

func (RoundTripper) RoundTrip

func (tr RoundTripper) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip injects the outbound Authorization header with the token provided in the inbound request.

Jump to

Keyboard shortcuts

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