authapi

package
v0.234.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package authapi mounts hand-coded Auth0 Authentication API endpoints onto chi. Unlike the Mgmt API, these endpoints are functional — they mint real RS256 JWTs and respond with valid OIDC discovery / JWKS payloads.

Index

Constants

View Source
const DefaultSubject = "auth0|mock-user"

DefaultSubject is the user the authorization-code flow logs in when /authorize carries no login_hint.

Variables

View Source
var Fragment []byte

Fragment is the per-package OpenAPI 3.1 partial document describing every Auth API endpoint registered in this package's Mount function. The genopenapi bundler merges it with the base Mgmt API spec to produce api/auth0-mock.openapi.json.

Functions

func Mount

func Mount(d Deps)

Mount registers all Auth API endpoints on d.Router.

Types

type AuthorizeHandler

type AuthorizeHandler struct {
	// PKCE may be nil; when set, /authorize will stash any code_challenge it
	// receives so the matching /oauth/token exchange can verify the
	// code_verifier.
	PKCE *pkce.Store
	// AllowedRedirectURIs is the allow-list of absolute redirect_uri values
	// that /authorize will 302 to. Mirrors Auth0's per-application
	// "Allowed Callback URLs" tenant setting. Same threat model as
	// LogoutHandler.AllowedReturnURLs but on the higher-value endpoint:
	// /authorize carries `code` / `access_token` in the URL, so an
	// unvalidated redirect_uri leaks them to attacker-controlled hosts.
	// Relative URIs are always permitted. Empty list = no enforcement
	// (test-friendly default).
	AllowedRedirectURIs []string
	// Errors holds the failure rules; nil means no rules.
	Errors *authorizeerr.Store
	// Token mints the access and id tokens for response types other than code; required for those types.
	Token *TokenHandler
	// Sessions holds the login sessions behind the auth0 cookie; nil means no
	// sessions, so prompt=none always answers login_required.
	Sessions *session.Store
}

AuthorizeHandler handles OIDC authorization requests.

func (*AuthorizeHandler) ServeHTTP

func (h *AuthorizeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type DBConnectionsChangePasswordHandler

type DBConnectionsChangePasswordHandler struct{}

DBConnectionsChangePasswordHandler handles password change requests.

func (*DBConnectionsChangePasswordHandler) ServeHTTP

type DBConnectionsSignupHandler

type DBConnectionsSignupHandler struct{}

DBConnectionsSignupHandler handles user signup via database connections.

func (*DBConnectionsSignupHandler) ServeHTTP

type Deps

type Deps struct {
	Router          chi.Router
	Keys            *jwks.KeySet
	Issuer          string
	DefaultAudience string
	Log             zerolog.Logger
	Claims          *claims.Store
	ClaimMappings   *claims.MappingStore
	Permissions     *permissions.Store
	PKCE            *pkce.Store
	MFA             *mfa.Store
	// Sessions may be nil (no remembered profiles).
	Sessions                     *session.Store
	LogoutAllowedURLs            []string
	AuthorizeAllowedRedirectURIs []string
	// AuthorizeErrors may be nil (no /authorize failure rules).
	AuthorizeErrors *authorizeerr.Store
}

Deps is the parameter object for Mount.

type DiscoveryHandler

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

DiscoveryHandler serves the OIDC discovery document. The document depends only on the issuer (fixed at Mount time), so it is marshaled once in NewDiscoveryHandler and every request just writes the cached bytes — mirroring jwks.KeySet's precomputed JWKSJSON.

In auto mode (issuer == jwks.AutoIssuer) the document is built per request from the address the request was sent to.

func NewDiscoveryHandler added in v0.230.0

func NewDiscoveryHandler(issuer string) *DiscoveryHandler

NewDiscoveryHandler builds the OIDC discovery document for issuer once.

func (*DiscoveryHandler) ServeHTTP

func (h *DiscoveryHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LogoutHandler

type LogoutHandler struct {
	AllowedReturnURLs []string
	// Sessions may be nil; the login cookie is then cleared without ending a session.
	Sessions *session.Store
}

LogoutHandler 302-redirects to the returnTo query parameter (or "/" when missing). When AllowedReturnURLs is empty (the default) every returnTo is permitted — this is a CI/local-testing mock, so the permissive default matches the same opt-in pattern as AuthorizeHandler and means SDK tests calling `/v2/logout?returnTo=https://app/…` work out of the box. When AllowedReturnURLs is set (via LOGOUT_ALLOWED_URLS) the handler enforces the allow-list like real Auth0 does, with the URL-scheme / backslash bypass guards described in isAllowed.

Never expose the mock to untrusted networks — see the README disclaimer.

func (*LogoutHandler) ServeHTTP

func (h *LogoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type OIDCLogoutHandler added in v0.233.0

type OIDCLogoutHandler struct {
	Keys              *jwks.KeySet
	AllowedReturnURLs []string
	// Sessions may be nil; the login cookie is then cleared without ending a session.
	Sessions *session.Store
}

OIDCLogoutHandler mirrors Auth0's /oidc/logout (OIDC RP-Initiated Logout). It reads id_token_hint, client_id, post_logout_redirect_uri and state from the GET query or POST form body. With no post_logout_redirect_uri it renders a static logged-out page; otherwise it 302-redirects there, appending state. When AllowedReturnURLs is empty (the default) every post_logout_redirect_uri is permitted — the same permissive default as LogoutHandler, so SDK tests work out of the box. When set (via LOGOUT_ALLOWED_URLS) the allow-list is enforced with the guards described in isSafeRedirect.

An id_token_hint must be an id_token minted by this mock; it may be expired, as the spec allows.

Never expose the mock to untrusted networks — see the README disclaimer.

func (*OIDCLogoutHandler) ServeHTTP added in v0.233.0

func (h *OIDCLogoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type PasswordlessStartHandler

type PasswordlessStartHandler struct{}

PasswordlessStartHandler initiates a passwordless authentication flow.

func (*PasswordlessStartHandler) ServeHTTP

type PasswordlessVerifyHandler

type PasswordlessVerifyHandler struct {
	Token *TokenHandler
}

PasswordlessVerifyHandler verifies a passwordless OTP and mints tokens. It is a thin wrapper over the passwordless grant on /oauth/token.

func (*PasswordlessVerifyHandler) ServeHTTP

type RevokeHandler

type RevokeHandler struct{}

RevokeHandler is a no-op mock; refresh tokens aren't tracked.

func (*RevokeHandler) ServeHTTP

func (h *RevokeHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request)

type TokenHandler

type TokenHandler struct {
	Keys            *jwks.KeySet
	Issuer          string
	DefaultAudience string
	Log             zerolog.Logger
	Claims          *claims.Store
	// ClaimMappings may be nil. When a request-parameter → claim-name
	// mapping is registered (via /admin0/claims/mappings), the value of that
	// body parameter is projected into every minted access token, taking
	// precedence over the global claims store. Empty store = feature off.
	ClaimMappings *claims.MappingStore
	Permissions   *permissions.Store
	// PKCE may be nil. When set and the authorization_code grant supplies a
	// code that was stashed at /authorize with a code_challenge, the matching
	// code_verifier is required and verified.
	PKCE *pkce.Store
	// MFA may be nil. When set and IsRequired() returns true, the password
	// and password-realm grants return 403 mfa_required + mfa_token instead
	// of minting; the three Auth0 mfa-* grants then trade the mfa_token plus
	// a fixed canned challenge for an access_token.
	MFA *mfa.Store
	// Sessions may be nil. When set, the profile of every id_token minted
	// is remembered per subject so /userinfo can return it, and each refresh
	// token's grant is remembered so refreshes keep the same user.
	Sessions *session.Store
}

TokenHandler handles OAuth token requests.

func (*TokenHandler) ServeHTTP

func (h *TokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type UserInfoHandler

type UserInfoHandler struct {
	Keys *jwks.KeySet
	// Sessions may be nil. When set, the profile remembered for the token's
	// subject is added beneath the token's own claims.
	Sessions *session.Store
}

UserInfoHandler returns claims for the authenticated user.

func (*UserInfoHandler) ServeHTTP

func (h *UserInfoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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