feat(mtls): mTLS (RFC 8705) client authentication - #865
Open
jd3vi1 wants to merge 2 commits into
Open
Conversation
Contributor
Author
|
Both majors fixed in 4fc699c:
On the Verified: both fixes exercised end to end; full suite (402), tsd, e2e, and lint all green. |
Authenticate to the token endpoint with a TLS client certificate instead of a client secret, enabled via useMtls: true (or AUTH0_MTLS=true). Routes token, refresh, revocation, userinfo, and PAR requests to the server's mtls_endpoint_aliases, and surfaces the certificate-bound cnf.x5t#S256 claim. The certificate is presented by a developer-provided customFetch (undici Agent), never by the SDK. Adds MtlsError and MtlsErrorCode for construction-time guards: customFetch is required, clientSecret/clientAssertionSigningKey are rejected, and a missing mtls_endpoint_aliases in discovery is a hard error.
… method Address review feedback on mTLS: - Remove 'tls_client_auth' from the clientAuthMethod Joi .valid() list. A JS caller could previously set it directly (without useMtls), passing validation while every mTLS guard keyed off useMtls stayed inactive -> no customFetch required, no endpoint aliases, silent invalid_client at runtime. The useMtls default resolver still returns the value (a .default() is not checked against .valid()), so mTLS keeps working; only explicit input is rejected. - Reject useMtls combined with an explicit non-mTLS clientAuthMethod (MTLS_INCOMPATIBLE_CLIENT_AUTH), which otherwise produced use_mtls_endpoint_aliases metadata with a contradictory auth strategy. - Fix the mislabeled test (it passed self_signed_tls_client_auth, never a valid value) and add explicit tls_client_auth rejection plus both incompatible-method cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds mTLS (RFC 8705) client authentication. When enabled, the SDK authenticates to the token endpoint with a TLS client certificate instead of a client secret, and issued access tokens carry a
cnf.x5t#S256claim binding them to the certificate (certificate-bound tokens).What's included
useMtls: boolean(orAUTH0_MTLS=true) — single opt-in flag. Internally usesTlsClientAuth()and setsuse_mtls_endpoint_aliases: trueon the client metadata, so token, refresh, revocation, userinfo, and PAR requests route to the server'smtls_endpoint_aliases. There is no separate CA-signed vs self-signed option; that distinction is an authorization-server concern.customFetchis required withuseMtls, and must present the client certificate at the TLS layer (e.g. anundiciAgentwithconnect: { key, cert }). The standardfetchglobal has no client-certificate API, so the certificate is never configured through the SDK directly.MtlsError/MtlsErrorCode(exported), thrown at construction/discovery time:mtls_requires_custom_fetch—useMtlswithout acustomFetch.mtls_incompatible_client_auth—useMtlscombined withclientSecretorclientAssertionSigningKey.mtls_endpoint_aliases_missing— the discovery document does not advertisemtls_endpoint_aliases.token_endpoint(fails fast rather than silently sending unbound requests).useMtlsis used against a canonical*.auth0.comissuer, since mTLS requires a custom domain.Usage
Tests
use_mtls_endpoint_aliasesmetadata, alias surfacing, the alias-missing error, token grants routing to the mTLS alias, and all construction guards (customFetchrequired, incompatible client auth,AUTH0_MTLSenv).useMtls/customFetchsurface and that mTLS strings are not part of the publicclientAuthMethodunion.EXAMPLES.mdand an example atexamples/mtls.js.