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
Go · Gin
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.
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
A drop-in middleware, a RequireAuth gate, and a typed session context, all wire-compatible with the rest of your Authdog stack.
ad.AttachSession() decorates every gin.Context with an idiomatic *authdog.Context. Read it with authdog.FromGin(c) for token, user, and IsAuthenticated.
Mount ad.RequireAuth() on protected routes and Authdog aborts unauthenticated requests with 401 before your handler runs. This is the real enforcement point.
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.
AttachSession reads the authdog-session cookie or an Authorization: Bearer header on its own. No extra cookie library required.
ad.Logout clears the session cookie and redirects to a redirect_uri sanitized against open redirects, with Secure set automatically in release mode.
It mirrors @authdog/express and @authdog/fastify on the wire, so one Authdog environment serves your Node and Go services interchangeably.
go get the SDK and read your public key from the env.
r.Use(ad.AttachSession()) once, at the router root.
Mount ad.RequireAuth() on the routes you protect.
go get the SDK, mount the middleware, and gate your routes with RequireAuth today. Free to start, with secure defaults built in.