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

authhttp

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package authhttp holds the HTTP rules the remote server and the console share: problem responses, JSON bodies, identity error mapping, session cookies, CSRF, authentication admission and deployment probes.

Index

Constants

View Source
const (
	AttemptLimit = 20
)

Each client IP may make AttemptLimit authentication attempts per window, which starts at its first attempt.

View Source
const SessionCookie = "diffx_session"

SessionCookie names the browser session cookie on each origin.

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON(w http.ResponseWriter, r *http.Request, target any) bool

func IdentityError

func IdentityError(w http.ResponseWriter, err error)

IdentityError maps identity outcomes to problem responses.

func Probes

func Probes(database Pinger, next http.Handler) http.Handler

Probes answers unauthenticated deployment probes before identity: /healthz reports a serving process without touching the database, and /readyz also requires a database that accepts queries. Neither explains a failure.

func Problem

func Problem(w http.ResponseWriter, status int, detail string)

func SetSession

func SetSession(w http.ResponseWriter, secret string, expiry time.Time, insecure bool)

SetSession writes the session cookie, or clears it for an empty secret.

func Unauthorized

func Unauthorized(w http.ResponseWriter)

func Unsafe

func Unsafe(method string) bool

Unsafe reports a method that browser sessions must protect with CSRF.

func ValidCSRF

func ValidCSRF(r *http.Request, expected string) bool

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, value any)

Types

type Admission

type Admission struct {
	// contains filtered or unexported fields
}

Admission bounds authentication attempts: a few at once per process and, with a client IP header, a fixed number per client IP each window. The listener's peer is an ingress, not the client, so the IP comes only from the header a trusted ingress sets; without that header attempts are not limited per client.

func NewAdmission

func NewAdmission(attempts Attempts, header string) *Admission

func (*Admission) Admit

func (admission *Admission) Admit(w http.ResponseWriter, r *http.Request) (func(), bool)

Admit answers the refusal itself and returns false, or returns a release function for the admitted attempt.

type Attempts

type Attempts interface {
	CountAuthAttempt(ctx context.Context, client string, now time.Time, window time.Duration) (int, error)
}

Attempts counts a client's attempts in its current window; every replica and the console share the counts.

type Pinger

type Pinger interface {
	Ping(ctx context.Context) error
}

Jump to

Keyboard shortcuts

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