connect

package
v1.68.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingToken is returned when no authorization header is present.
	ErrMissingToken = errors.New("authorization header is required")
	// ErrMalformedToken is returned when the authorization header is malformed.
	ErrMalformedToken = errors.New("malformed authorization header")
	// ErrInvalidToken is returned when token authentication fails.
	ErrInvalidToken = errors.New("invalid authorization token")
)

Functions

This section is empty.

Types

type AuthInterceptor

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

AuthInterceptor implements connect.ValidationInterceptor for JWT authentication.

func NewAuthInterceptor

func NewAuthInterceptor(authenticator security.Authenticator) *AuthInterceptor

NewAuthInterceptor creates a new authentication interceptor.

func (*AuthInterceptor) WrapStreamingClient

WrapStreamingClient implements the streaming client interceptor (pass-through for server-side).

func (*AuthInterceptor) WrapStreamingHandler

WrapStreamingHandler implements the streaming handler interceptor for authentication.

func (*AuthInterceptor) WrapUnary

func (a *AuthInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc

WrapUnary implements the unary interceptor for authentication.

type Option added in v1.67.1

type Option interface {
	// contains filtered or unexported methods
}

An Option configures an ValidationInterceptor.

func WithValidateResponses added in v1.67.1

func WithValidateResponses() Option

WithValidateResponses configures the ValidationInterceptor to also validate reponses in addition to validating requests.

By default:

- Unary: Response messages from the server are not validated. - Client streams: Received messages are not validated. - Server streams: Sent messages are not validated.

However, these messages are all validated if this option is set.

func WithValidator added in v1.67.1

func WithValidator(validator protovalidate.Validator) Option

WithValidator configures the ValidationInterceptor to use a customized protovalidate.Validator. By default, protovalidate.GlobalInterceptor is used See protovalidate.ValidatorOption for the range of available customizations.

func WithoutErrorDetails added in v1.67.1

func WithoutErrorDetails() Option

WithoutErrorDetails configures the ValidationInterceptor to elide error details from validation errors. By default, a protovalidate.ValidationError is added as a detail when validation errors are returned.

type ValidationInterceptor

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

ValidationInterceptor is a connect.Interceptor that ensures that RPC request messages match the constraints expressed in their Protobuf schemas. It does not validate response messages unless the WithValidateResponses option is specified.

By default, Interceptors use a validator that lazily compiles constraints and works with any Protobuf message. This is a simple, widely-applicable configuration: after compiling and caching the constraints for a Protobuf message type once, validation is very efficient. To customize the validator, use WithValidator and protovalidate.ValidatorOption.

RPCs with invalid request messages short-circuit with an error. The error always uses connect.CodeInvalidArgument and has a detailed representation of the error attached as a connect.ErrorDetail.

This interceptor is primarily intended for use on handlers. Client-side use is possible, but discouraged unless the client always has an up-to-date schema.

func NewValidationInterceptor

func NewValidationInterceptor(opts ...Option) *ValidationInterceptor

NewValidationInterceptor builds an ValidationInterceptor. The default configuration is appropriate for most use cases.

func (*ValidationInterceptor) WrapStreamingClient

WrapStreamingClient implements connect.ValidationInterceptor.

func (*ValidationInterceptor) WrapStreamingHandler

WrapStreamingHandler implements connect.ValidationInterceptor.

func (*ValidationInterceptor) WrapUnary

WrapUnary implements connect.ValidationInterceptor.

Jump to

Keyboard shortcuts

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