Skip to content

feat: MFA-4417 support configurable OTP length for phone factor#95

Draft
sebadoom wants to merge 1 commit into
auth0:masterfrom
sebadoom:mfa-4417/configurable-otp-length
Draft

feat: MFA-4417 support configurable OTP length for phone factor#95
sebadoom wants to merge 1 commit into
auth0:masterfrom
sebadoom:mfa-4417/configurable-otp-length

Conversation

@sebadoom

@sebadoom sebadoom commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Make the OTP length configurable for the phone factor (SMS/voice) instead of hardcoding it to 6; enables the classic Guardian widget to honour a tenant's configured phone OTP length.

Changes

  • lib/utils/validations.jsvalidateOtp(otp, otpLength) now accepts an optional length. Defaults to 6 when omitted or non-numeric, so existing callers are unaffected. Exposes DEFAULT_OTP_LENGTH.
  • lib/index.js — the public auth0GuardianJS(options) entry accepts options.otpLength, threaded into both start and resume.
  • lib/transaction/factory.js + lib/transaction/index.js — carry otpLength into the transaction, applied only to the SMS auth and SMS enrollment strategies. TOTP/recovery codes keep their fixed lengths.
  • lib/auth_strategies/{sms,otp}_auth_strategy.js and lib/enrollment_strategies/sms_enrollment_strategy.js — validate the OTP against the configured length.

Backwards compatibility

Purely additive. validateOtp(otp) and auth0GuardianJS({...}) called without a length behave exactly as before (length 6). No public signatures removed or reordered — only optional params added. Consumers opt in by passing otpLength; no coordination is required for existing integrations.

Testing

  • npm test (eslint + mocha): 245 passing (+9 new), covering the validation primitive with explicit/omitted lengths, SMS auth verify, and SMS enrollment confirm.

Notes

  • ⚠️ Standalone build: npm run build currently fails to minify (guardian-js.min.js) because socket.io-client@4.x ships ES6 that the pinned UglifyJS (webpack 1.x) cannot parse. This is a pre-existing issue (introduced when socket.io-client was bumped from v2 to v4), not caused by this change, but it must be resolved before publishing a standalone release. Tracking separately.

Make validateOtp accept an optional length (default 6, preserving
existing behaviour) and thread an otpLength option from the public
entry point through the transaction factory to the SMS auth and SMS
enrollment strategies. TOTP and recovery codes keep their fixed
lengths. Enables the classic Guardian widget to honour a tenant's
configured phone OTP length.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant