Skip to content

Migration: pkg/authngo/authn

The request-authentication primitives have been extracted out of go-tool-base into the standalone module gitlab.com/phpboyscout/go/authn (v0.1.0). It is framework-free — its only dependencies are cockroachdb/errors and golang-jwt/jwt/v5 — so any project can adopt the verifiers without pulling in the framework.

What changed

  • The package gitlab.com/phpboyscout/go-tool-base/pkg/authn no longer exists. It now lives at gitlab.com/phpboyscout/go/authn.
  • The public API is identical. The package name is still authn; Verifier, CertVerifier, Identity, AuthorizeFunc, ErrUnauthenticated, the NewAPIKeyVerifier/NewJWTVerifier/NewMTLSVerifier constructors, the RequireScopes/RequireClaim combinators, and the context helpers are unchanged.
  • There is no GTB adapter and no compatibility shim — a clean pre-1.0 import-path change (pkg/authn had zero go-tool-base imports).
  • The unused generated mocks under mocks/pkg/authn/ are removed. If you mock Verifier/CertVerifier downstream, generate mocks in your own tree (or open an issue on the module to ship them).

How to migrate

Repoint the import path — nothing else changes:

-import "gitlab.com/phpboyscout/go-tool-base/pkg/authn"
+import "gitlab.com/phpboyscout/go/authn"

Then add the module and tidy:

go get gitlab.com/phpboyscout/go/[email protected]
go mod tidy

A repository-wide substitution is sufficient (the package name and every symbol are unchanged):

grep -rl 'go-tool-base/pkg/authn' --include='*.go' . \
  | xargs sed -i 's#gitlab.com/phpboyscout/go-tool-base/pkg/authn#gitlab.com/phpboyscout/go/authn#g'
go mod tidy

Notes

  • go-tool-base itself now consumes go/authn directly: its HTTP AuthMiddleware (pkg/http) and gRPC auth interceptor (pkg/grpc) wrap the module's verifiers. The GTB-side wiring (WithAPIKeyHeader, WithBearerVerifier, WithAuthorize, IdentityFromContext) is unchanged — see How to verify requests.
  • Full documentation and the security model live at authn.go.phpboyscout.uk; the API reference is on pkg.go.dev.