oidc

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package oidc is an optional auth.IdentityProvider for any OpenID Connect provider (Google, Microsoft Entra ID, Okta, Auth0, Keycloak, ...): the authorization code flow with PKCE, the provider's endpoints and keys from its discovery document, and the ID token verified (signature, issuer, audience, expiry, nonce) before its claims become the auth.ExternalIdentity.

Core auth ships no provider: an app imports this package, or writes its own adapter against auth.IdentityProvider, and registers it with framework.WithAuthIdentityProviders (or auth.WithIdentityProviders).

google, err := oidc.New(ctx, oidc.Config{
	Name:         "google",
	Issuer:       "https://accounts.google.com",
	ClientID:     os.Getenv("GOOGLE_CLIENT_ID"),
	ClientSecret: os.Getenv("GOOGLE_CLIENT_SECRET"),
	RedirectURL:  "https://app.example.com/api/v1/auth/external/google/callback",
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Name is the provider's name in the routes' paths and the stored
	// links (auth.IdentityProvider.Name).
	Name string
	// Issuer is the provider's issuer URL; New reads its discovery document
	// (Issuer + "/.well-known/openid-configuration").
	Issuer string
	// ClientID and ClientSecret are the app's client at the provider. A
	// public client (PKCE only) has no secret.
	ClientID     string
	ClientSecret string
	// RedirectURL is the callback route's absolute URL, as registered with
	// the provider: {public origin}{API prefix}/auth/external/{Name}/callback.
	RedirectURL string
	// Scopes are requested besides "openid". Default: email, profile.
	Scopes []string
	// HTTPClient makes the discovery, key and token requests. Default: a
	// client with a 15-second timeout.
	HTTPClient *http.Client
}

Config configures a Provider.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider is an OpenID Connect auth.IdentityProvider.

func New

func New(ctx context.Context, cfg Config) (*Provider, error)

New reads the issuer's discovery document and returns its Provider.

func (*Provider) AuthCodeURL

func (p *Provider) AuthCodeURL(req auth.AuthorizationRequest) (string, error)

AuthCodeURL implements auth.IdentityProvider: the authorization code request, with the state, the nonce and the PKCE challenge.

func (*Provider) Exchange

Exchange implements auth.IdentityProvider: it redeems the code (with the PKCE verifier), verifies the ID token and its nonce, and returns its subject and email.

func (*Provider) IssuesIDTokens

func (p *Provider) IssuesIDTokens() bool

IssuesIDTokens implements auth.IDTokenProvider: every identity carries the ID token's nonce, which the framework then requires.

func (*Provider) Name

func (p *Provider) Name() string

Name implements auth.IdentityProvider.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL