Use this file to discover all available pages before exploring further.
The Intent.AspNetCore.Identity module introduces ASP.NET Core Identity for user authentication, authorization, and account management using Entity Framework Core. It provides a complete user management system with role-based access control.
ASP.NET Core Identity is a membership system that adds login functionality to your application. This module integrates Identity with your Intent Architect application, generating all the necessary entities, configurations, and infrastructure code.
public static class IdentityServiceCollectionExtensions{ public static IServiceCollection AddIdentityServices( this IServiceCollection services) { services.AddScoped<ICurrentUserService, CurrentUserService>(); services.AddScoped<UserManager<ApplicationUser>>(); services.AddScoped<SignInManager<ApplicationUser>>(); services.AddScoped<RoleManager<ApplicationRole>>(); return services; }}
public async Task<SignInResult> LoginAsync( LoginDto dto, CancellationToken cancellationToken){ var user = await _userManager.FindByEmailAsync(dto.Email); if (user == null) return SignInResult.Failed; var result = await _signInManager.CheckPasswordSignInAsync( user, dto.Password, lockoutOnFailure: true); return result;}
public class RoleService : IRoleService{ private readonly RoleManager<ApplicationRole> _roleManager; private readonly UserManager<ApplicationUser> _userManager; public async Task CreateRoleAsync(string roleName) { if (!await _roleManager.RoleExistsAsync(roleName)) { var role = new ApplicationRole(roleName); await _roleManager.CreateAsync(role); } } public async Task AssignRoleAsync(Guid userId, string roleName) { var user = await _userManager.FindByIdAsync(userId.ToString()); if (user != null) { await _userManager.AddToRoleAsync(user, roleName); } } public async Task<List<string>> GetUserRolesAsync(Guid userId) { var user = await _userManager.FindByIdAsync(userId.ToString()); if (user == null) return new List<string>(); var roles = await _userManager.GetRolesAsync(user); return roles.ToList(); }}
[Authorize][ApiController][Route("api/admin")]public class AdminController : ControllerBase{ [Authorize(Roles = "Admin")] [HttpGet("users")] public async Task<ActionResult<List<UserDto>>> GetAllUsers() { // Only users in Admin role can access } [Authorize(Roles = "Admin,Manager")] [HttpGet("reports")] public async Task<ActionResult<ReportDto>> GetReports() { // Users in Admin OR Manager role can access } [Authorize(Policy = "RequireAdminAndManagerRoles")] [HttpPost("sensitive-action")] public async Task<ActionResult> SensitiveAction() { // Custom policy-based authorization }}
public async Task<string> GeneratePasswordResetTokenAsync(string email){ var user = await _userManager.FindByEmailAsync(email); if (user == null) throw new NotFoundException("User not found"); return await _userManager.GeneratePasswordResetTokenAsync(user);}public async Task<IdentityResult> ResetPasswordAsync( string email, string token, string newPassword){ var user = await _userManager.FindByEmailAsync(email); if (user == null) throw new NotFoundException("User not found"); return await _userManager.ResetPasswordAsync(user, token, newPassword);}
public async Task<string> GenerateEmailConfirmationTokenAsync(Guid userId){ var user = await _userManager.FindByIdAsync(userId.ToString()); if (user == null) throw new NotFoundException("User not found"); return await _userManager.GenerateEmailConfirmationTokenAsync(user);}public async Task<IdentityResult> ConfirmEmailAsync( Guid userId, string token){ var user = await _userManager.FindByIdAsync(userId.ToString()); if (user == null) throw new NotFoundException("User not found"); return await _userManager.ConfirmEmailAsync(user, token);}
public async Task<IdentityResult> EnableTwoFactorAsync(Guid userId){ var user = await _userManager.FindByIdAsync(userId.ToString()); if (user == null) throw new NotFoundException("User not found"); await _userManager.SetTwoFactorEnabledAsync(user, true); return IdentityResult.Success;}public async Task<string> GenerateTwoFactorTokenAsync(Guid userId){ var user = await _userManager.FindByIdAsync(userId.ToString()); if (user == null) throw new NotFoundException("User not found"); return await _userManager.GenerateTwoFactorTokenAsync( user, TokenOptions.DefaultPhoneProvider);}