Note: Instead of custom implementation, we recommend that you delegate these routine tasks to OAuth2 providers. Microsoft, Google, Azure, and GitHub services enable user and document management that's familiar to anyone who works with business apps. Your XAF application can easily integrate these OAuth2 providers into the logon form. You only need to add boilerplate code. Refer to the following help topic for additional information: Active Directory and OAuth2 Authentication Providers in ASP.NET Core Blazor Applications.
This example contains a reusable Security.Extensions module that implements the capability to register a new user from the login form and the "Forgot Password" feature.
The module includes the following notable building blocks:
- Non-persistent data models for parameter screens (LogonActionParameters.cs).
- A View Controller (ManageUsersOnLogonController.cs) for the login Detail View. The controller declares custom Actions and their behavior. See the
CreateCustomLogonWindowControllers
event in Module.cs to find controller registration code and other service logic. - Services for restoring passwords (RestorePasswordService.cs) and registering new users (UserRegistrationService.cs).
- A custom login view for restoring a user's password (see the
Application_CreateCustomLogonAction
event handler in Module.cs).
Perform the following steps to integrate this module in your project:
-
Download the Security.Extensions module project and add it to your XAF solution. Reference the module project in your Blazor project and rebuild the solution.
See the following topic for details: How to: Add Projects to a Solution.
-
Add the
SecurityExtensionsModule
to your application:File to review: DXApplication1.Blazor.Server/Startup.cs
public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddXaf(Configuration, builder => { builder.Modules .AddSecurityExtensions(options => options.CreateSecuritySystemUser = DXApplication1.Module.DatabaseUpdate.Updater.CreateUser) // ... // ... }); // ... } // ... }
In the previous code sample,
Updater.CreateUser
is your custom method that matches the following definition:public delegate IAuthenticationStandardUser CreateSecuritySystemUser(IObjectSpace objectSpace, string userName, string email, string password, bool isAdministrator);
-
Add the
Email
property to theApplicationUser
class:File to review: ApplicationUser.cs
public class ApplicationUser : /*...*/ { // ... public virtual string Email { get; set; } }
- Updater.cs
- Startup.cs
- LogonActionCustomizationController.cs
- ManageUsersOnLogonController.cs
- RestorePasswordService.cs
- UserRegistrationService.cs
- ApplicationBuilderExtensions.cs
- LogonActionParameters.cs
- Module.cs
- XafApplication.CreateCustomLogonWindowControllers
- Authentication System Architecture (Blazor)
- Active Directory and OAuth2 Authentication Providers in ASP.NET Core Blazor Applications
- Customize Standard Authentication Behavior and Supply Additional Logon Parameters (.NET Framework Applications)
(you will be redirected to DevExpress.com to submit your response)