Skip to main content

OIDC Auth

OpenID Connect authentication built on top of OAuth2 with automatic JWKS key discovery and ID token validation.

Usage

import "github.com/Pavan-Silva/go-zen/auth"

oidcAuth := &auth.OIDCAuth{
Issuer: "https://accounts.google.com",
ClientID: "your-client-id",
}

r.Use(auth.RequireAuth(oidcAuth))

How It Works

  1. Extracts the Bearer token from the Authorization header
  2. Optionally verifies the token as a JWT (set SkipTokenVerification=true for opaque tokens)
  3. Calls the OIDC userinfo endpoint to retrieve user details
  4. Maps the response to a *User via ClaimsFunc (or a default mapping)
  5. Populates User.ID, User.Username, User.Claims from the userinfo response

Key Features

  • Bearer token validation via userinfo endpoint
  • JWT access token verification (optional, via SkipTokenVerification)
  • Standard claims extraction (sub, preferred_username, email, name)
  • Custom claims available via User.Claims