-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
Hello Everyone!
Problem Description
When creating a RESTful API with .NET Core and Identity, the UserManager requires a value for the UserName field even if it is explicitly removed from the user entity. Current community solutions involve:
- Manually setting the UserName to the user’s email (with sanitized characters) or
- Creating a custom UserValidator to bypass the requirement.
While these workarounds function, they feel hacky and counterintuitive for modern authentication flows where email/password is standard and username/password is less common.
Describe the solution you'd like
Expected Behavior
The UserManager should allow developers to configure authentication to use email-only (without requiring UserName). Example:
services.Configure<IdentityOptions>(options => {
options.User.RequireUserName = false; // Hypothetical
});
Current Behavior
The UserName field is mandatory, forcing developers to implement non-standard workarounds.
Proposed Solution
Add a configuration parameter to IdentityOptions to control whether authentication uses:
- UserName only
- Email only
- Both
This would align with modern authentication patterns and reduce boilerplate code.
Additional context
Research links:
Lastly, thanks for your time and if you have a better solution please share it with me.