AuthPlus.Identity 1.0.16

dotnet add package AuthPlus.Identity --version 1.0.16
                    
NuGet\Install-Package AuthPlus.Identity -Version 1.0.16
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AuthPlus.Identity" Version="1.0.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AuthPlus.Identity" Version="1.0.16" />
                    
Directory.Packages.props
<PackageReference Include="AuthPlus.Identity" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AuthPlus.Identity --version 1.0.16
                    
#r "nuget: AuthPlus.Identity, 1.0.16"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AuthPlus.Identity@1.0.16
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AuthPlus.Identity&version=1.0.16
                    
Install as a Cake Addin
#tool nuget:?package=AuthPlus.Identity&version=1.0.16
                    
Install as a Cake Tool

AuthPlus.Identity

AuthPlus.Identity is a .NET 8+ class library designed to simplify user authentication and authorization in your ASP.NET Core applications. It provides ready-to-use APIs for users, roles, JWT authentication, email confirmation, password reset, and external login providers.


Features

  • User Registration and Login
  • Password Reset and Email Confirmation
  • User Management (CRUD)
  • Role Management (CRUD, assign/remove roles)
  • JWT-Based Authentication
  • Configurable Email Service
  • External Authentication Providers (Google, Facebook, LinkedIn, etc.)
  • Extendable Validators and Policies
  • Ready-to-use Controllers and Endpoints
  • Supports SQL Server, PostgreSQL (via EF Core)

Getting Started

Prerequisites

  • .NET 8 SDK or later
  • NuGet Package Manager

Installation

Add the package to your project:

dotnet add package AuthPlus.Identity

Configuration

Add the following settings to your appsettings.json:

{
  "JwtSettings": {
   "SecretKey": "your-32-character-super-secret-key-here", // Min 32 chars
    "Issuer": "your-app-name",
    "Audience": "your-app-clients",
    "ExpirationMinutes": 60
  },
  "EmailSettings": {
    "SmtpServer": "smtp.example.com",
    "SmtpPort": 587,
    "SmtpUser": "your-email@example.com",
    "SmtpPassword": "your-email-password",
    "BaseUrl": "https://your-app-url"
  },
  "ConnectionStrings": {
    "DefaultConnection": "Server=.;Database=AuthDb;Trusted_Connection=True;"
  }
}

Optional: Add external login providers by implementing IExternalAuthProvider (e.g., Google, Facebook, LinkedIn).


Setup in Program.cs

var builder = WebApplication.CreateBuilder(args);

// Add AuthPlus Identity (select your database provider)
builder.Services.AddAuthPlusIdentity(builder.Configuration, options =>
{
    options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"));
    // options.UsePostgres(...);
    // options.UseMySql(...);
});

// Register external authentication providers (optional)
builder.Services.AddHttpClient<GoogleAuthProvider>();
builder.Services.AddHttpClient<MicrosoftAuthProvider>();
builder.Services.AddScoped<IExternalAuthProvider, GoogleAuthProvider>();
builder.Services.AddScoped<IExternalAuthProvider, MicrosoftAuthProvider>();

// Add controllers
builder.Services.AddControllers();

var app = builder.Build();
// IMPORTANT: Middleware must be in correct order
app.UseRouting(); // This must come first!
app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();
app.Run();

AddAuthPlusIdentity automatically registers:

  • Identity services
  • JWT authentication
  • Email service
  • IUserService, IRoleService, IAuthService
  • Policies (RequireAdminRole, RequireUserRole, RequireAdminOrUserRole)
  • Validators for DTOs (LoginDto, RegisterDto, UserDto, ResetPasswordDto)

Controllers & Endpoints

AuthController

Endpoint Method Description
/api/auth/register POST Register a new user
/api/auth/login POST Login a user
/api/auth/external-login POST Login via external provider (Google, Facebook, etc.)
/api/auth/refresh-token POST Refresh JWT token
/api/auth/forgot-password POST Send password reset email
/api/auth/reset-password POST Reset user password

UserController

Endpoint Method Authorization Description
/api/user GET Admin Get all users
/api/user/{id} GET User/Admin Get user by ID
/api/user POST Admin Create a user
/api/user/{id} PUT User/Admin Update user info
/api/user/{id} DELETE Admin Delete a user
/api/user/{userId}/roles/{roleName} POST Admin Assign role to user
/api/user/{userId}/roles/{roleName} DELETE Admin Remove role from user
/api/user/confirm-email?token=&userId= GET Anonymous Confirm user email

RoleController

Endpoint Method Authorization Description
/api/role/all GET Admin Get all roles
/api/role/{id} GET Admin Get role by ID
/api/role POST Admin Create a new role
/api/role/{id} PUT Admin Update role
/api/role/{id} DELETE Admin Delete role

Extending

You can extend and customize the library:

  • Roles & Policies: Extend AuthorizationPolicies or add custom roles.
  • Validators: Override or create custom DTO validators.
  • ApplicationUser: Add new properties to your user class.
  • Email Service: Implement IEmailService for custom email logic.
  • External Providers: Implement IExternalAuthProvider for social logins.

Optional: Override Default Validators

public class CustomRegisterDtoValidator : RegisterDtoValidator
{
    public CustomRegisterDtoValidator()
    {
        RuleFor(x => x.Password)
            .Must(p => p.Contains("@"))
            .WithMessage("Password must contain '@'.");

        RuleFor(x => x.Password)
            .Matches(@"\d")
            .WithMessage("Password must contain at least one number.");
    }
}

// Register in Program.cs to replace default validator
builder.Services.AddTransient<IBaseValidator<RegisterDto>, CustomRegisterDtoValidator>();

Example: Register User in Controller

[HttpPost("register")]
public async Task<IActionResult> Register([FromBody] RegisterDto registerDto)
{
    var result = await _authService.RegisterAsync(registerDto);
    return !result.Succeeded ? BadRequest(result.Errors) : Ok(result);
}

License & Support

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.16 118 1/15/2026
1.0.15 112 1/15/2026
1.0.14 110 1/14/2026
1.0.13 115 1/14/2026
1.0.12 113 1/14/2026
1.0.11 114 1/14/2026
1.0.10 229 9/15/2024
1.0.9 183 9/5/2024
1.0.8 170 9/4/2024
1.0.7 161 9/4/2024
1.0.6 165 9/4/2024
1.0.4 161 9/2/2024
1.0.3 171 9/2/2024
1.0.2 163 9/2/2024
1.0.1 172 9/1/2024
1.0.0 178 9/1/2024