Help us shape the future of Go! Take the 2026 Go Developer Survey

connect

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 15 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

func DefaultList

func DefaultList(
	ctx context.Context,
	authI security.Authenticator,
	moreInterceptors ...connect.ServerInterceptor,
) ([]connect.ServerInterceptor, error)

DefaultList returns the standard chain of Connect server interceptors used by frame services. Pass the result to connect.NewServer. Order matters: otel → validation → auth → tenancy claims. The tenancy interceptor binds tenancy.Claims derived from the authenticated principal so downstream pool.DB(ctx, _) queries are transparently RLS-scoped without any additional wiring.

Caller-supplied moreInterceptors are appended after this chain. Uses a legacy claims binder (HonorInternalSkip=true). For Secure Profile use DefaultListWithBinder.

func DefaultListWithBinder

func DefaultListWithBinder(
	_ context.Context,
	authI security.Authenticator,
	binder *tenancy.ClaimsBinder,
	moreInterceptors ...connect.ServerInterceptor,
) ([]connect.ServerInterceptor, error)

DefaultListWithBinder is DefaultList with an explicit tenancy.ClaimsBinder. Nil binder keeps legacy behaviour. Secure Profile passes a binder with HonorInternalSkip=false and RequireClaims=true.

func NewAuthInterceptor

func NewAuthInterceptor(authenticator security.Authenticator) connect.ServerInterceptor

NewAuthInterceptor returns a server interceptor that authenticates the bearer token in the Authorization header of every RPC, unary and streaming. The authenticated context, enriched with the X-Tenant-Id, X-Partition-Id and X-Access-Id tenancy hints, is passed to the handler.

func NewFunctionAccessInterceptor

func NewFunctionAccessInterceptor(
	checker *authorizer.FunctionChecker,
	permissions map[string][]string,
) connect.ServerInterceptor

NewFunctionAccessInterceptor creates a Connect interceptor that enforces functional permissions automatically based on a procedure-to-permissions map.

The permissions map should be keyed by Connect procedure name (e.g., "/profile.v1.ProfileService/GetById") with values being the permission strings required for that procedure. Use the permissions.BuildProcedureMap helper from the apis/go/common/permissions package to build this map from proto service descriptors.

If a procedure is not in the map, the request is allowed through without a functional permission check.

func NewTenancyAccessInterceptor

func NewTenancyAccessInterceptor(checker *authorizer.TenancyAccessChecker) connect.ServerInterceptor

NewTenancyAccessInterceptor creates a Connect server interceptor that enforces tenancy data access using the provided TenancyAccessChecker.

func NewValidationClientInterceptor

func NewValidationClientInterceptor(opts ...Option) connect.ClientInterceptor

NewValidationClientInterceptor builds a client interceptor that validates every sent request message. Client-side use is possible, but discouraged unless the client always has an up-to-date schema.

func NewValidationInterceptor

func NewValidationInterceptor(opts ...Option) connect.ServerInterceptor

NewValidationInterceptor builds a server interceptor that validates every received request message, for unary and streaming RPCs alike. The default configuration is appropriate for most use cases.

Types

type Option

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

An Option configures an [validationInterceptor].

func WithValidateResponses

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

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

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.

Jump to

Keyboard shortcuts

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