connectauth

package
v0.3.29 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package connectauth writes apiauth.APIMiddleware refusals in the protocol of the request: a Connect error for Connect, a grpc-status trailer for gRPC and gRPC-Web, and the middleware's default JSON for anything else.

A gRPC or Connect client can't read an HTTP 401 page. It sees a transport failure, or a code like "unavailable", and can't tell a bad token from a network fault. Wire OnAuthError in front of a Connect handler instead:

mw := &apiauth.APIMiddleware{ /* ... */ }
mw.OnAuthError = connectauth.OnAuthError(mw)
mux.Handle(path, mw.ValidateToken(handler))

See: https://connectrpc.com/docs/protocol/#error-codes See: https://github.com/grpc/grpc/blob/master/doc/statuscodes.md See: https://github.com/panyam/oneauth/issues/463

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Code

func Code(err error) connect.Code

Code is the Connect code for an APIMiddleware refusal: permission_denied for an *apiauth.AuthError with Code "insufficient_scope", unauthenticated otherwise. A refusal that isn't an *AuthError (a missing authorization_details type from RequireAuthorizationDetails) is unauthenticated, matching the middleware's own 401 for it.

func OnAuthError

func OnAuthError(mw *apiauth.APIMiddleware, opts ...connect.HandlerOption) func(http.ResponseWriter, *http.Request, error)

OnAuthError returns an APIMiddleware.OnAuthError for mw.

For a Connect, gRPC or gRPC-Web request it sets the same WWW-Authenticate challenge (and DPoP-Nonce) the middleware would, then writes a Connect error. insufficient_scope becomes permission_denied, and every other refusal becomes unauthenticated. The error message is err.Error(), the same text the default JSON body carries in error_description. For any other request it writes the middleware's default response with mw.WriteAuthError, so REST clients on the same mux see no change.

Types

This section is empty.

Jump to

Keyboard shortcuts

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