Skip to content

Sign in with SMS #2050

Open
Open

Description

@SandPod

Is your feature request related to a problem? Please describe.
Similar to Email authentication it should be possible to create an account using SMS authentication.

Describe the solution you'd like
SMS authentication added to the serverpod_auth_module complete with server and flutter code.

Documentation for the new provider in the Serverpod docs.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
PR to start the work from here: #1362

Might be able to incorporate and close this issue: #729

Activity

  1. added
    enhancement
    on Mar 25, 2024
  2. moved this to Version 2.0 - Essentials 🔥 in Serverpod Frameworkson Mar 25, 2024
  3. moved this from Version 2.0 - Essentials 🔥 to Version 2.0 - Priority 🌟 in Serverpod Frameworkson May 21, 2024
  4. moved this from Next 🌟 to Later 🥳 in Serverpod Frameworkson Jul 1, 2024
  5. added
    area: authentication
    on Jan 3, 2025
  6. SandPod commented on May 22, 2025

    @SandPod
    ContributorAuthor

    Draft implementation here: #1362

  7. Metaildust commented on Feb 1, 2026

    @Metaildust

    provided solution in #4667

    Hi, I've implemented an SMS authentication module for Serverpod that's already published on pub.dev:

    📦 serverpod_auth_sms - https://pub.dev/packages/serverpod_auth_sms

    Features:

    • SMS login, registration, and phone binding
    • Two storage strategies: Hash (HMAC-SHA256) and Crypto (AES-256-GCM)
    • Rate limiting for verification codes
    • Full documentation (English + Chinese)
    • Compatible with Serverpod 3.2.3+

    Architecture:

    • Follows the new IDP (Identity Provider) pattern from Serverpod 3.x
    • 7 modular packages with clear separation of concerns
    • Already battle-tested in production

    I'd be happy to discuss contributing this to the official auth module,
    or keeping it as a community package. What's the team's preference?
    @SandPod @vlidholt

  8. marcelomendoncasoares commented on Feb 5, 2026

    @marcelomendoncasoares
    Collaborator

    I'd be happy to discuss contributing this to the official auth module, or keeping it as a community package. What's the team's preference?

    @Metaildust I will be very nice if you want to implement the SMS support on the new auth module! We already have several utilities that might facilitate the work a lot (for hashing, creating secret challenges and rate limiting). If you want to work on it, I can assign you to the issue and give you more details on how it could be implemented reusing these utils.

  9. Metaildust commented on Feb 5, 2026

    @Metaildust

    Hi @marcelomendoncasoares and Serverpod team,

    I've built a community SMS authentication module that's currently published on pub.dev:

    Current Implementation

    The package already uses official Serverpod utilities:

    • Argon2HashUtil for password/verification code hashing
    • SecretChallengeUtil for the verification flow (create → verify → complete)
    • DatabaseRateLimitedRequestAttemptUtil for rate limiting

    Architecture (mirrors serverpod_auth_email):

    • serverpod_auth_sms - Main integration package
    • serverpod_auth_sms_core / _client - Core logic
    • serverpod_auth_sms_hash / _client - Hash-based phone storage (HMAC-SHA256 for lookup)
    • serverpod_auth_sms_crypto / _client - Crypto-based phone storage (AES-GCM encrypted + hash)

    Features:

    • Phone number + verification code authentication
    • Pluggable SMS providers via callback interface
    • Configurable rate limiting and verification code expiry
    • Database schema following email auth patterns

    Questions for Discussion

    1. Design alignment: Does this architecture align with Serverpod's expectations, or are there changes needed?
    2. Provider abstraction: Currently using a callback interface for SMS sending - is this the preferred approach, or should we have a dedicated SMS provider abstraction?
    3. Phone storage strategies: I've split hash-only (serverpod_auth_sms_hash) and encrypted (serverpod_auth_sms_crypto) into separate packages, allowing developers to choose based on their privacy requirements. Should these remain separate, or be consolidated?

    I'm ready to adapt the implementation based on feedback and work through the PR process. Please let me know how to proceed.

  10. Metaildust commented on Feb 5, 2026

    @Metaildust

    To clarify the current implementation status (and align with the proposed two-step approach):

    Step 1: Generic passwordless provider (OTP-only)

    I’ve implemented the generic providers/passwordless provider and opened PR #4699:

    • startLogin → verifyLoginCode → finishLogin (built on SecretChallengeUtil)
    • server-side storage PasswordlessLoginRequest (with migration)
    • client-serializable PasswordlessLoginException (+ Reason enum)
    • base endpoint + configurable callbacks (normalizeHandle, buildNonce, sendLoginVerificationCode, resolveAuthUserId)

    Step 2: SMS as an extension (OTP-only)

    Once Step 1 is merged, I’ll submit a follow-up PR that refactors the SMS provider to build on passwordless and keeps the phone-specific pieces:

    • PhoneIdHashStore / PhoneIdCryptoStore
    • phone normalization + binding flow
    • widgets on Flutter side

    Phone hashing strategy

    The phone lookup hash is deterministic and uses HMAC-SHA256 (not Argon2), because it needs to support indexing / account lookup.

    Out of scope

    • phone+password flow: to be proposed after Step 1 + Step 2
    • 2FA/MFA: separate issue

    @marcelomendoncasoares If this looks good, is there anything you’d like adjusted in Step 1 before review/merge? Otherwise I’ll start preparing the Step 2 refactor in parallel.

  11. Metaildust commented on Feb 5, 2026

    @Metaildust

    Hi @marcelomendoncasoares,

    I'm ready to start the PR work. Before proceeding, I'd like to confirm the expected code structure.

    Currently in the repo, email auth is a provider directory under:

    serverpod_auth_idp_server/lib/src/providers/email/
    

    My existing implementation uses separate packages, but I'm leaning toward option 1 for the PR:

    Proposed approach: Restructure into providers/sms/ (like email)

    • All SMS auth code in one provider directory
    • Two phone storage strategies (hash-only vs encrypted) as internal implementations
    • Strategy selection via configuration, not separate packages

    This keeps consistency with the email pattern and simplifies the user experience - one integration, configuration-based flexibility.

    If this approach works, I'll start the PR. Please let me know if you have a different preference!

  12. added a commit that references this issue on Feb 5, 2026
    8b23592
  13. marcelomendoncasoares commented on Feb 5, 2026

    @marcelomendoncasoares
    Collaborator

    @Metaildust Nice to know that you're reusing all of the internals and that you have followed the email implementation! This will make the integration a lot simpler, then. For the design of the feature, I'll make a proposition to build it in two steps:

    1. A generic providers/passwordless provider that exposes the workflow for any passwordless login alternative.
    2. An SMS extension to the passwordless provider that adds the phone-specific features and widgets.

    This will both simplify the review process and make the core of the feature reusable for other providers in the future. It is the same pattern we have done on the other providers that resulted in the utilities that will be reused here. If you agree with this direction, I'll suggest splitting each step in a PR, so that we can ensure that each is properly tested.

    For the tests of the passwordless implementation, I suggest taking inspiration on the email tests - which will be very natural since you have already followed the email implementation.

    Regarding your other questions from the first message:

    • Provider abstraction: Using the callback is just fine and makes it very easy to integrate with providers.
    • Phone storage strategies: Nice that you have followed all best practices! Since there are no complex dependencies, you can put them both in the existing IDP packages (server and flutter, as needed). We try to minimize the number of dependencies, since Dart's tree shaking already handles removing unnecessary code from the compiled binaries. The only reason for splitting is when some IDP depends on platform-specific implementations, since native code is not tree-shaken and can break users code. But this also happens only on the Flutter side, as with Firebase.

    What do you think?

  14. Metaildust commented on Feb 5, 2026

    @Metaildust

    Thanks! I agree with option A.

    Update: I’ve opened PR #4699 for Step 1 (generic passwordless/OTP provider). I’ll keep the initial PRs strictly passwordless-first (generic passwordless + SMS OTP extension), and move phone+password to a follow-up PR once the first two are merged.

    2FA/MFA will be handled in a separate issue/PR after this.

  15. marcelomendoncasoares commented on Feb 5, 2026

    @marcelomendoncasoares
    Collaborator

    For an upstream PR, would you prefer: A) keep the initial PRs strictly passwordless-first (generic passwordless provider + SMS OTP), and move phone+password to a follow-up PR (optionally behind a feature flag), or B) add configuration flags so users can explicitly enable/disable each flow (and we can choose conservative defaults)?

    I would go with option A, to first have the passwordless in and then add the password option as a follow-up. We can then evaluate if the best strategy is to create a new one extending the passwordless SMS or expose the password as configuration flag.

    Related: do you consider SMS 2FA (second factor after a primary login) in scope for this work, or should that be handled separately?

    We should discuss it separately. On a general thought, to add 2FA (or MFA), we need to:

    1. Expose a way for developers to configure a list of additional IDPs that should be invoked after a first successful authentication. This needs to account for all possible strategies:
      • Enforce a sequence of fixed IDPs that must be used - like SMS as 2FA.
      • Require N from any IDPs that a user has registered - excepting the one that was used to authenticate.
      • Require N from an intersection of IDPs between a fixed list and the ones a user has registered.
    2. Add a hook to the additional IDPs - which might require allowing to flag an AuthSuccess as incomplete and bearing extra information to know which IDP to invoke next on the app.
    3. Enhance the SignInWidget to parse the extra information on the app to invoke the required IDPs for the next required authentication.

    Besides this, we need to also allow specifying which providers can be used as login or MFA or both.

    If you want to work on this, I can create an issue with these details and assign it to you! But I'd suggest leaving it for after the first PRs just to avoid opening too many fronts at once.

  16. moved this from Backlog 🗂️ to Contributor In Progress 👩‍💻 in Serverpod Frameworkson Feb 5, 2026
  17. Metaildust commented on Feb 5, 2026

    @Metaildust

    @marcelomendoncasoares I’ve opened PR #4699 for Step 1 (generic providers/passwordless, OTP-only) and the checks are now passing.

    Once Step 1 is merged, I’ll follow up with Step 2 (SMS extension, OTP-only) refactor.

    Any feedback on the Step 1 PR would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: authenticationenhancement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions