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 (*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 ¶
func (p *Provider) Exchange(ctx context.Context, req auth.ExchangeRequest) (auth.ExternalIdentity, error)
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 ¶
IssuesIDTokens implements auth.IDTokenProvider: every identity carries the ID token's nonce, which the framework then requires.