jackc/pgx · error

authentication method requirement %q failed: %s

Error message

authentication method requirement %q failed: %s

What it means

Error "authentication method requirement %q failed: %s" thrown in jackc/pgx.

Source

Thrown at pgconn/require_auth.go:64

func (ra requireAuth) allows(m authMethod) bool {
	return ra.allowed&(1<<m) != 0
}

// check returns an error if method m is not permitted by the policy. The reason is phrased to
// follow libpq's "authentication method requirement \"%s\" failed: %s" form so users migrating
// from libpq see familiar diagnostics.
func (ra requireAuth) check(m authMethod) error {
	if ra.allows(m) {
		return nil
	}
	var reason string
	if m == authMethodNone {
		reason = "server did not complete authentication"
	} else {
		reason = fmt.Sprintf("server requested %s authentication", authMethodNames[m])
	}
	return fmt.Errorf("authentication method requirement %q failed: %s", ra.raw, reason)
}

// parseRequireAuth parses the require_auth connection parameter with libpq-compatible semantics:
// a comma-separated list of method names, optionally each prefixed with "!" to negate. Negated and
// non-negated entries cannot be mixed; duplicate entries are rejected. An empty string yields a
// permissive policy (all methods allowed, no authentication required).
func parseRequireAuth(s string) (requireAuth, error) {
	ra := requireAuth{raw: s}

	if s == "" {
		ra.allowed = 1<<authMethodCount - 1
		return ra, nil
	}

	first := true
	negated := false
	for part := range strings.SplitSeq(s, ",") {
		method := strings.TrimSpace(part)

View on GitHub (pinned to ec1a0befd2)

When it happens

Trigger: Thrown at pgconn/require_auth.go:64 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04). Data as JSON: /data/errors/6518c5f6c80848d0.json. Report an issue: GitHub.