auth0

package
v0.45.7 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package auth0 provides Auth0 JWT validation and claims mapping for go-auth.

Use this package with auth.WithTokenValidator to accept Auth0-issued tokens while preserving go-auth session and authorization behavior.

Index

Constants

View Source
const (
	// IdentifierProviderAuth0 is the provider name used for Auth0 identifiers.
	IdentifierProviderAuth0 = "auth0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth0ClaimsMapper

type Auth0ClaimsMapper struct {
	Namespace string

	DefaultRole           string
	PermissionToRoleMap   map[string]string
	ResourceRoleExtractor func(claims *Auth0CustomClaims) map[string]string

	RoleClaimKey          string
	PermissionsClaimKey   string
	ResourceRolesClaimKey string
	OrganizationClaimKey  string
	TenantClaimKey        string
}

Auth0ClaimsMapper maps Auth0 JWT claims to go-auth claims.

func (*Auth0ClaimsMapper) Map

func (m *Auth0ClaimsMapper) Map(ctx context.Context, externalClaims any) (*auth.JWTClaims, error)

Map implements ClaimsMapper.

type Auth0CustomClaims

type Auth0CustomClaims struct {
	Scope          string            `json:"scope"`
	Permissions    []string          `json:"permissions"`
	Email          string            `json:"email"`
	EmailVerified  bool              `json:"email_verified"`
	Name           string            `json:"name"`
	Nickname       string            `json:"nickname"`
	Picture        string            `json:"picture"`
	Metadata       map[string]any    `json:"app_metadata"`
	OrganizationID string            `json:"org_id"`
	TenantID       string            `json:"tenant_id"`
	ResourceRoles  map[string]string `json:"resource_roles"`
	Raw            map[string]any    `json:"-"`
}

Auth0CustomClaims holds custom claims from Auth0 tokens.

func (*Auth0CustomClaims) UnmarshalJSON

func (c *Auth0CustomClaims) UnmarshalJSON(data []byte) error

UnmarshalJSON captures both known and raw claims for custom mapping.

func (*Auth0CustomClaims) Validate

func (c *Auth0CustomClaims) Validate(ctx context.Context) error

Validate satisfies validator.CustomClaims.

type Auth0Identity

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

Auth0Identity represents an Auth0 user implementing auth.Identity.

func (*Auth0Identity) Email

func (u *Auth0Identity) Email() string

func (*Auth0Identity) ID

func (u *Auth0Identity) ID() string

func (*Auth0Identity) Metadata

func (u *Auth0Identity) Metadata() map[string]any

func (*Auth0Identity) Name

func (u *Auth0Identity) Name() string

func (*Auth0Identity) Picture

func (u *Auth0Identity) Picture() string

func (*Auth0Identity) Role

func (u *Auth0Identity) Role() string

func (*Auth0Identity) Username

func (u *Auth0Identity) Username() string

type ClaimsMapper

type ClaimsMapper interface {
	// Map converts provider-specific claims to go-auth JWTClaims.
	// Implementations should populate RegisteredClaims, UID, UserRole,
	// Resources, and Metadata for full go-auth compatibility.
	Map(ctx context.Context, externalClaims any) (*auth.JWTClaims, error)
}

ClaimsMapper transforms external claims to go-auth JWTClaims.

type Config

type Config struct {
	// Domain is the Auth0 tenant domain (e.g., "example.us.auth0.com").
	Domain string

	// Audience is the API identifier(s) to validate against.
	Audience []string

	// Issuer overrides the default issuer URL (optional).
	// Default: "https://{Domain}/".
	Issuer string

	// CacheTTL is how long to cache JWKS keys.
	// Default: 5 minutes.
	CacheTTL time.Duration

	// ClaimsMapper customizes claim mapping (optional).
	ClaimsMapper ClaimsMapper

	// CustomClaims defines custom claim types to extract.
	CustomClaims func() validator.CustomClaims

	// ContextFunc provides a context for JWKS fetch/validation.
	// Default: context.Background.
	ContextFunc func() context.Context

	// AllowInsecureLoopback permits HTTP issuers only for explicit local tests.
	AllowInsecureLoopback bool

	// HTTPClient optionally supplies transport settings for discovery/JWKS.
	HTTPClient *http.Client
}

Config holds Auth0 configuration for token validation.

func DefaultConfig

func DefaultConfig(domain string, audience []string) Config

DefaultConfig returns a Config with sensible defaults.

type IdentifierStore

type IdentifierStore = auth.IdentifierStore

IdentifierStore is kept as a compatibility alias for Auth0 callers. New code should depend on auth.IdentifierStore directly.

type IdentityProvider

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

IdentityProvider implements auth.IdentityProvider backed by Auth0.

func NewIdentityProvider

func NewIdentityProvider(ctx context.Context, cfg IdentityProviderConfig) (*IdentityProvider, error)

NewIdentityProvider creates an Auth0-backed identity provider.

func (*IdentityProvider) FindIdentityByIdentifier

func (p *IdentityProvider) FindIdentityByIdentifier(ctx context.Context, identifier string) (auth.Identity, error)

FindIdentityByIdentifier implements auth.IdentityProvider.

func (*IdentityProvider) VerifyIdentity

func (p *IdentityProvider) VerifyIdentity(ctx context.Context, identifier, password string) (auth.Identity, error)

VerifyIdentity is not supported for Auth0 provider (Auth0 handles authentication).

type IdentityProviderConfig

type IdentityProviderConfig struct {
	// ManagementDomain is the Auth0 management API domain.
	ManagementDomain string

	// ClientID is the M2M application client ID.
	ClientID string

	// ClientSecret is the M2M application client secret.
	ClientSecret string

	// LocalUsers is an optional local user repository for caching/enrichment.
	LocalUsers auth.Users

	// IdentifierStore maps external identifiers to local users (new table).
	IdentifierStore auth.IdentifierStore

	// SyncOnFetch enables automatic local sync when fetching users.
	SyncOnFetch bool
}

IdentityProviderConfig configures the Auth0 identity provider.

type TokenValidator

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

TokenValidator validates Auth0-issued JWTs using JWKS.

func NewTokenValidator

func NewTokenValidator(cfg Config) (*TokenValidator, error)

NewTokenValidator creates a new Auth0 token validator.

func (*TokenValidator) Validate

func (v *TokenValidator) Validate(tokenString string) (auth.AuthClaims, error)

Validate implements auth.TokenValidator.

Directories

Path Synopsis
Package sync provides optional Auth0 user synchronization helpers.
Package sync provides optional Auth0 user synchronization helpers.

Jump to

Keyboard shortcuts

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