QuantumAuth middleware for Go HTTP servers.
This package allows Go backends to verify QuantumAuth requests signed by the QuantumAuth Client (TPM + Post-Quantum signatures), using either:
- the hosted QuantumAuth backend (default), or
- a custom / self-hosted verifier
Supported frameworks:
net/httpginchi
go get github.com/quantumauth-io/go-quantumauth-mw- A frontend (web app) requests a challenge from the QuantumAuth browser extension
- The local QuantumAuth Client:
- builds a canonical request
- signs it with TPM + PQ keys
- The frontend sends the signed headers to your backend
- This middleware:
- extracts the QuantumAuth headers
- validates request shape
- verifies signatures via the QuantumAuth backend
- On success, the authenticated user ID is injected into the request context
Uses the hosted QuantumAuth backend automatically.
import (
"net/http"
qaauthmw "github.com/quantumauth-io/go-quantumauth-mw"
)
mux := http.NewServeMux()
mux.Handle("/protected",
qaauthmw.QaMiddleware()(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
userID, ok := qaauthmw.UserIDFromContext(r.Context())
if !ok {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
w.Write([]byte("Hello user " + userID))
})),
)
http.ListenAndServe(":8080", mux)import (
"github.com/gin-gonic/gin"
qagin "github.com/quantumauth-io/go-quantumauth-mw/gin"
)
r := gin.Default()
r.Use(qagin.QAMiddleware())
r.GET("/protected", func(c *gin.Context) {
userID, ok := qagin.UserID(c)
if !ok {
c.AbortWithStatus(401)
return
}
c.JSON(200, gin.H{
"user_id": userID,
})
})
r.Run(":8080")import (
"github.com/go-chi/chi/v5"
qaauthmw "github.com/quantumauth-io/go-quantumauth-mw"
qachi "github.com/quantumauth-io/go-quantumauth-mw/chi"
)
r := chi.NewRouter()
r.Use(qachi.Middleware(
&qaauthmw.RemoteVerifier{},
))
r.Get("/protected", func(w http.ResponseWriter, r *http.Request) {
userID, ok := qachi.UserID(r.Context())
if !ok {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
w.Write([]byte("Hello user " + userID))
})Apache-2.0 © QuantumAuth