feat(mTLS): add Mutual TLS (RFC 8705) client authentication support#851
Open
cschetan77 wants to merge 1 commit into
Open
feat(mTLS): add Mutual TLS (RFC 8705) client authentication support#851cschetan77 wants to merge 1 commit into
cschetan77 wants to merge 1 commit into
Conversation
Implements RFC 8705 mTLS client authentication, allowing applications to authenticate with Auth0 using a TLS client certificate instead of a client_secret. Certificate-bound access tokens (cnf.x5t#S256) are issued automatically when the IdP supports them. Key changes: - New `useMtls` config option (also via AUTH0_MTLS env var); defaults to false - When enabled, switches client auth method to `tls_client_auth` (TlsClientAuth() from openid-client v6) and sets `use_mtls_endpoint_aliases: true` so token/userinfo requests are routed to the mtls_endpoint_aliases advertised in discovery - `customFetch` is required when useMtls=true; throws MtlsError at init time if missing - `clientSecret` is no longer required when useMtls=true — the cert is the credential - New MtlsError / MtlsErrorCode exported from the package for structured error handling - 14 new tests covering config validation, clientMetadata flag, endpoint alias routing, customFetch invocation and graceful fallback when aliases are absent
| @@ -1,6 +1,7 @@ | |||
| const { assert } = require('chai'); | |||
| const { assert, expect } = require('chai'); | |||
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
Implements RFC 8705 Mutual TLS client authentication, allowing applications to authenticate with Auth0 using a TLS client certificate instead of a
clientSecret. When the IdP supports it, issued access tokens will carry acnf.x5t#S256claim binding them to the client certificate fingerprint (certificate-bound tokens).useMtls: boolean— new opt-in config flag (defaultfalse); also settable viaAUTH0_MTLS=trueenv varuseMtls: true, the SDK switches client authentication fromClientSecretPosttoTlsClientAuth()(openid-client v6 /oauth4webapi) and setsuse_mtls_endpoint_aliases: trueon client metadata so all token/userinfo requests are routed to themtls_endpoint_aliasesadvertised in the OIDC discovery documentcustomFetchis required whenuseMtls: true— the standardfetchglobal has no API for attaching client certificates; a TLS-aware implementation (e.g.undiciAgentwithconnect: { key, cert }) must be provided. AMtlsErrorwith codemtls_requires_custom_fetchis thrown atauth()initialization time if it is missing (fail-fast)clientSecretis no longer required whenuseMtls: true— the certificate is the sole client credentialMtlsErrorclass andMtlsErrorCodeenum exported from the package for structured error handlingmtls_endpoint_aliases, the SDK falls back to the standard endpoints without throwingUsage
Files changed
lib/errors.jsMtlsErrorclass andMtlsErrorCodelib/config.jsuseMtlsJoi option,AUTH0_MTLSenv var, fail-fast validation,tls_client_authadded to validclientAuthMethodvalues, relaxedclientSecretrequirementlib/client.jstls_client_authcase ingetClientAuth()callingTlsClientAuth(),use_mtls_endpoint_aliaseson client metadataindex.jsMtlsError/MtlsErrorCodeindex.d.tsuseMtlsinConfigParams, exportMtlsErrorclass andMtlsErrorCodeconst with full JSDoctest/config.tests.jstest/client.tests.jsTest plan
useMtlsdefaults tofalseuseMtls: true+customFetch→ no throw,clientAuthMethodresolves totls_client_authuseMtls: truewithoutcustomFetch→ throwsMtlsErrorwithmtls_requires_custom_fetchAUTH0_MTLS=trueenv var respectedclientSecretnot required whenuseMtls: trueuse_mtls_endpoint_aliases: trueset onclientMetadatamtls_endpoint_aliasesfrom discovery document surfaced inserverMetadatamtls_endpoint_aliasescustomFetchis invoked during discovery whenuseMtls: trueReferences