Authdog

Go · Gin

Authentication for Go backends

First-class Gin middleware that validates Authdog sessions on every request and gives you an idiomatic authdog.Context plus a RequireAuth gate, on the same wire as the Node SDKs.

One Use() call
Mount ad.AttachSession() once and every request carries an *authdog.Context. No per-route wiring.
One enforcement point
Add ad.RequireAuth() to a route and unauthenticated requests are rejected with 401 before your handler runs.
No cookie dependency
The middleware parses the authdog-session cookie itself, so there's nothing else to wire up.
Validated at startup
authdog.New parses and checks the public key at boot, so misconfiguration fails fast.

Attach the session

// main.go
ad, _ := authdog.New(authdog.Config{
  PublicKey: os.Getenv("PK_AUTHDOG"),
})

// resolve the session on every request
r.Use(ad.AttachSession())

Gate routes with RequireAuth

// routes.go
r.GET("/me", ad.RequireAuth(),
  func(c *gin.Context) {
    c.JSON(200, authdog.FromGin(c).User)
  })

Idiomatic Gin, not a framework

Everything Go APIs need

A drop-in middleware, a RequireAuth gate, and a typed session context, all wire-compatible with the rest of your Authdog stack.

01

First-class Gin middleware

ad.AttachSession() decorates every gin.Context with an idiomatic *authdog.Context. Read it with authdog.FromGin(c) for token, user, and IsAuthenticated.

  • authdog.FromGin(c)
  • Token, user, IsAuthenticated
02

RequireAuth gate

Mount ad.RequireAuth() on protected routes and Authdog aborts unauthenticated requests with 401 before your handler runs. This is the real enforcement point.

  • 401 before your handler
  • Per-route or per-group
03

Validated at startup

authdog.New parses and validates the public key once at boot, so a malformed or untrusted key fails fast instead of at the first request.

  • Fails fast at boot
  • Trusted host enforced
05

Safe logout handler

ad.Logout clears the session cookie and redirects to a redirect_uri sanitized against open redirects, with Secure set automatically in release mode.

  • Open-redirect safe
  • Secure in release mode
06

Same wire as Node

It mirrors @authdog/express and @authdog/fastify on the wire, so one Authdog environment serves your Node and Go services interchangeably.

  • One environment
  • Node and Go together
01

Install

go get the SDK and read your public key from the env.

02

Attach sessions

r.Use(ad.AttachSession()) once, at the router root.

03

Gate routes

Mount ad.RequireAuth() on the routes you protect.

Add auth to your Go API.

go get the SDK, mount the middleware, and gate your routes with RequireAuth today. Free to start, with secure defaults built in.