Skip to content

RFC: Authentication Module 2.0 #3126

Closed
3 of 7 issues completed
Closed

Description

@SandPod

Improved Authentication Module

Image

Summary

The Serverpod framework's current authentication module has served as a robust foundation for enabling user authentication. However, over time, we have identified key areas where the module falls short in meeting the evolving needs of our users.

Reworking the existing authentication module to address these limitations would introduce significant overhead and slow down development, as it would require maintaining backward compatibility with older clients.

Drawing from these insights, this RFC proposes the introduction of a new authentication module, serverpod_oauth, that address these limitations and lays the groundwork for a more scalable, flexible, and standards-compliant solution.

Adding a new authentication module allows developers to migrate their applications and users at their own pace.

Key improvements

  1. Modular Authentication Providers

    • Goal: Allow users to include only the authentication providers relevant to their projects, enabling fine-grained control over which methods are implemented.
    • Solution: Separate each authentication provider (e.g., Google, Facebook, Apple) into distinct modules. Users can explicitly add providers as dependencies, reducing unnecessary bloat. While this limits code sharing between providers, the simplified implementation of each provider should minimize this drawback.
  2. Enhanced Custom Provider Support

    • Goal: Simplify the implementation of custom authentication providers and provide developers more control over authentication logic.
    • Solution: Rework the authentication API so that the core module focuses on user management and token issuance. Custom providers will implement only integration-specific logic in separate modules, allowing seamless addition or modification without affecting the core module.
  3. OAuth 2.0 Compatibility

    • Goal: Adhere to OAuth 2.0 standards for secure and reliable authentication.
    • Solution: Implement Access and Refresh tokens. Extend the client SDK to handle token refresh scenarios, ensuring uninterrupted access for users when tokens expire or are revoked.
  4. JWT-Based Authentication

    • Goal: Improve authentication performance by reducing reliance on server-side database lookups for every request.
    • Solution: Replace session-based authentication with JSON Web Tokens (JWT). JWTs will contain user claims and be signed by the server, enabling stateless authentication while reducing server load and improving response times.
  5. Enable Database Relations for Authentication Metadata

    • Goal: Enable richer integration of user-related metadata in the database.
    • Solution: Leverage Serverpod's relational database support to associate additional information application specific information with authenticated users. This allows developers to easily link external accounts or log user activities.
  6. Improved Provider APIs for Enhanced Flexibility

    • Goal: Allow developers greater flexibility to address potential authentication issues.
    • Solution: Improve the APIs for all authentication providers, enabling developers to easily intercept and act on specific authentication scenarios, such as retries, error handling, or custom logic. This ensures a more adaptable and robust integration experience.

Implementation guidelines

The new authentication module will be developed as a standalone core module, with each provider implemented as its own independent module that utalizes the core module.

Image

Other modules, such as the chat module, will be reworked to support seamless integration with various authentication modules. This approach ensures that users can leverage Serverpod-supplied modules while also having the flexibility to integrate their own custom authentication solutions.

The module should follow the transport layer best practies and guidelines such as HTTP codes and header usage.

Migration Support

To ease the transition to the new authentication module, we will provide tools in the old authentication module. These methods will allow developers to run both the old and new authentication modules simultaneously, enabling seamless user migration at their own pace.

Related issues

The new authentication module is expected to enable or solve the following issues:

Sub-issues

Sub-issues

3 of 7 Issues completed
Loading 7 sub-issues

Activity

  1. converted this from a draft issue on Jan 15, 2025
  2. added
    rfc
    area: authentication
    on Jan 15, 2025
  3. Errechydy commented on Jan 17, 2025

    @Errechydy

    Support Sign up with phone number (send verification code from backend)

  4. MrFahrenheit-55 commented on Jan 17, 2025

    @MrFahrenheit-55

    Can 2FA be supported or is it already part of #2113?

  5. vanlooverenkoen commented on Jan 17, 2025

    @vanlooverenkoen
    Contributor

    Maybe this one should be included as well: #3121

  6. obiwanzenobi commented on Jan 19, 2025

    @obiwanzenobi
    Contributor

    Server side email code validation - so we could create widget page in web server for code validation, or our own endpoint for validation. While sending validation email developer can opt in (or code by himself) including url (public url + /validate_account) instead of just a code inside validation emails.

  7. sotomski commented on Jan 19, 2025

    @sotomski

    Ability to log out of an individual device without logging out the user on all devices.
    Note: This is probably a much larger feature request involving handling multiple sessions per user 🤔

  8. Isakdl commented on Jan 19, 2025

    @Isakdl
    Collaborator

    Ability to log out of an individual device without logging out the user on all devices.
    Note: This is probably a much larger feature request involving handling multiple sessions per user 🤔

    This is already supported 🙂

  9. SandPod commented on Jan 20, 2025

    @SandPod
    ContributorAuthor

    Awesome to get all the comment and feedback here! 🎉

    Support Sign up with phone number (send verification code from backend)

    @Errechydy - That should be covered by #2050 right?

    Can 2FA be supported or is it already part of #2113?

    @MrFahrenheit-55 - I would say this is separate from that issue. Providing callbacks to implement 2FA should be included for all providers that require it. But it would also be interesting to provide a library or module with common 2FA implementations such as OTP codes or email validation.

    Maybe this one should be included as well: #3121

    @vanlooverenkoen - Yes, that should be part of this as well!

    Server side email code validation...

    @obiwanzenobi - Yes, that is an experience we would like to improve in the current implementation. For example, make it simple to create and use magic links.

  10. SandPod commented on Jan 20, 2025

    @SandPod
    ContributorAuthor
  11. dkbast commented on Jan 31, 2025

    @dkbast
    Contributor

    @SandPod I think adding magic links as a first party feature would be super helpful for all those indie projects - are there any plans to add some form of email provider to the hosted serverpod version?

  12. SandPod commented on Feb 25, 2025

    @SandPod
    ContributorAuthor

    @dkbast - Good observation and suggestion! Magic links would be a great addition to the authentication module.

    I will take your feature suggestion for adding an email provider to the hosted serverpod version as a suggestion to Serverpod Cloud.

  13. dkbast commented on Feb 27, 2025

    @dkbast
    Contributor

    Having auth available in Serverpod Mini would solve the usecase where the app doesn't really need a backend and the backend is only used to hide API keys from the user to avoid abuse.

    Could also be a usecase for having serverpod as a middleware to any other backend. We would still want to know if the user is authenticated but don't care much about anything else.

    Solutions that come to my mind would be using 3rd party auth providers like Firebase Auth or Auth0, potentially there could be others in an enterprise environment.

    For the latter it would be paramount to be able to pass the auth token on to further requests.

  14. 44 remaining items

  15. added
    epic
    on Aug 13, 2025
  16. marcelomendoncasoares commented on Dec 22, 2025

    @marcelomendoncasoares
    Collaborator

    Since all pending issues are extra from the new authentication system and organized into its own topics, we can consider this RFC closed! New features will be treated as normal improvements from now.

  17. moved this from In Progress 🔥 to Done 🚀 in Serverpod Frameworkson Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: authenticationepicrfc

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions