Skip to content
Secure servicesDocs 1.3.x

Auth and Authz ​

Authentication establishes an AuthContext; authorization decides whether that identity may invoke a method. Keep those decisions separate in the interceptor chain even when they are configured together.

Authentication and authorization Client credentials are verified by a chosen authentication strategy, which establishes the shared identity used by code or proto-based authorization and by context-aware application code and tests. Choose a verifier Client credentialsBearer token or trusted gateway headers JWTSignature · claims GatewayTrust source · headers SessionVerify · map identity Auth context and testingRequest / stream identity · propagationMock context · signed test JWTs Code authorizationRules · callback · default policy Proto-based authorizationPublic / internal · roles / scopes A valid credential is not permission to invoke every method.
Choose authentication for the trust boundary and authorization for the method policy. Context, propagation and testing share the verified identity; attaching client credentials does not verify them.

Choose the trust boundary ​

Start with JWTs, a trusted gateway or an application session.

Internal identity, propagation and transport boundaries
BoundaryStart here
Clients send bearer JWTs directlyJWT authentication
A trusted gateway verifies credentials firstGateway authentication
A web application resolves a sessionSession authentication
Internal services attach outgoing identityClient interceptors
RPCs require a trusted service identity instead of an end-user tokenInternal method setup
Handlers need the authenticated identityAuth context

The auth interceptors receive request headers; they do not expose the TLS peer certificate to an authentication callback. For mTLS-bound identity, have a trusted gateway or mesh supply a verified identity header and enforce that boundary as described in the gateway guide. Direct application-level peer-certificate/SAN reading is deferred; see ADR-029.

Choose authorization ownership ​

Use proto-based authorization when access policy belongs with the RPC contract. It keeps public methods, roles, scopes, and the runtime resolver on the same generated descriptor. Use code-based authorization for dynamic rules or legacy services whose policy cannot live in proto options.

typescript
interceptors: [
  createErrorHandlerInterceptor(),
  createJwtAuthInterceptor({ jwksUri, skipMethods }),
  createProtoAuthzInterceptor({ defaultPolicy: 'deny' }),
  ...createDefaultInterceptors({ errorHandler: false }),
]

This is an interceptor-list excerpt. The JWT and proto-authz guides supply imports, credentials, public-method exclusions and the full server setup.

To turn away requests that carry no credential at all before their body is even read, add a server-wide request gate in front of this chain; it runs before every interceptor, so its errors must already be client-safe.

The security invariant is error handling → authentication → authorization → remaining behavior. Public-method discovery and exact factory fields are deliberately not duplicated here; use the focused guide and generated interfaces such as JwtAuthInterceptorOptions.

Learn, configure, inspect ​

  • Learn the model here and in ADR-024.
  • Configure a concrete trust boundary in the focused guides above.
  • Use the generated API for exact symbols.

Installation ​

Add authentication and authorization
bash
npm install @connectum/auth
bash
pnpm add @connectum/auth
bash
bun add @connectum/auth

Keep the shared protobuf and Connect peers compatible with the rest of your application; see peer requirements.