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
- Extracts the Bearer token from the
Authorizationheader - Optionally verifies the token as a JWT (set
SkipTokenVerification=truefor opaque tokens) - Calls the OIDC userinfo endpoint to retrieve user details
- Maps the response to a
*UserviaClaimsFunc(or a default mapping) - Populates
User.ID,User.Username,User.Claimsfrom 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