Repository navigation
Description
Improved Authentication Module
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
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
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:
- Custom session data #3121
- Support for enforcing single device sign in #2995
- Decouple auth module #2269
- Introduce AuthUser with a single authentication user that can be referred in relation. #2114
- Client support for refresh and access tokens #2113
- Add email and random number authentication #2100) (Consideration for email authentication module)
- Sign in with SMS #2050
defaultAuthenticationHandlershould use a JWT #1720- createAccountRequest should return more info than just a boolean #1565
- WebAuthn / passwordless auth module #1414
- User creation by invitation #1270
- Add more methods for working with UserInfo (most importantly delete) #791
- Built in support for common authentication #19
- auth should not depend on
image_picker&file_picker#3336
Sub-issues
Collapse Sub-issuesSub-issues
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone 🚀

Activity
Errechydy commentedon Jan 17, 2025
Support Sign up with phone number (send verification code from backend)
MrFahrenheit-55 commentedon Jan 17, 2025
Can 2FA be supported or is it already part of #2113?
vanlooverenkoen commentedon Jan 17, 2025
Maybe this one should be included as well: #3121
obiwanzenobi commentedon Jan 19, 2025
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.
sotomski commentedon Jan 19, 2025
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 🤔
Isakdl commentedon Jan 19, 2025
This is already supported 🙂
SandPod commentedon Jan 20, 2025
Awesome to get all the comment and feedback here! 🎉
@Errechydy - That should be covered by #2050 right?
@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.
@vanlooverenkoen - Yes, that should be part of this as well!
@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.
SandPod commentedon Jan 20, 2025
@sotomski - It was a recent addition but we have documentation around it here:
dkbast commentedon Jan 31, 2025
@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?
SandPod commentedon Feb 25, 2025
@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.
dkbast commentedon Feb 27, 2025
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.
44 remaining items
intuserIdinSessionLogEntry#3448UserProfile/serverpod_auth_profilepackage #3447serverpod_auth_sessionpackage #3446AuthUser/serverpod_auth_userpackage #3445userIdin core ServerpodAuthenticationInfo#3444marcelomendoncasoares commentedon Dec 22, 2025
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.