SDKs
Go
Verify au1h tokens and read gateway headers with net/http middleware.
go get github.com/AD12-codes/au1h/packages/goVerifier and middleware
import au1h "github.com/AD12-codes/au1h/packages/go"
v, err := au1h.NewVerifier(ctx, au1h.Options{
URL: "https://auth.example.com",
AppSlug: "todo",
})
mux := http.NewServeMux()
mux.Handle("GET /api/me", v.RequireUser(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, _ := au1h.UserFromContext(r.Context()) // *au1h.User{ID, Email, Name, ApplicationID}
json.NewEncoder(w).Encode(user)
})))RequireUser answers 401 ({"error","code"}) for a missing or invalid bearer token and
403 for another application's token. Keys come from au1h's JWKS, cached and refreshed at
most every 15 minutes (Options.JWKSRefresh).
Verify manually:
tok, user, err := v.Verify(ctx, raw)
tok, user, err := v.VerifyAuthorization(ctx, r.Header.Get("Authorization"))Behind the gateway
mux.Handle("/", v.RequireProxy(true, handler)) // true: verify x-au1h-token
p, _ := au1h.ProxyFromContext(r.Context()) // p.User, p.AppID, p.AppSlugau1h.ReadProxyContext(r.Header) reads the headers without middleware.
Server-to-server
c := au1h.NewServerClient("https://auth.example.com", "todo", os.Getenv("AU1H_APP_SECRET"))
id, slug, err := c.Me(ctx)
res, err := c.Introspect(ctx, token) // res.Active, res.User, res.ExpiresAtFull example: examples/go in the repository.