MinimalApi.Identity.API 1.0.86

There is a newer version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package MinimalApi.Identity.API --version 1.0.86
                    
NuGet\Install-Package MinimalApi.Identity.API -Version 1.0.86
                    
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="MinimalApi.Identity.API" Version="1.0.86" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MinimalApi.Identity.API" Version="1.0.86" />
                    
Directory.Packages.props
<PackageReference Include="MinimalApi.Identity.API" />
                    
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 MinimalApi.Identity.API --version 1.0.86
                    
#r "nuget: MinimalApi.Identity.API, 1.0.86"
                    
#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 MinimalApi.Identity.API@1.0.86
                    
#: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=MinimalApi.Identity.API&version=1.0.86
                    
Install as a Cake Addin
#tool nuget:?package=MinimalApi.Identity.API&version=1.0.86
                    
Install as a Cake Tool

Packages MinimalApi Identity API

Library for dynamically managing users, roles, claims, modules and license, using .NET 8 Minimal API, Entity Framework Core and SQL Server.

I created this library in order to avoid duplication of repetitive code whenever I implement Asp.Net Core Identity as an authentication and authorization provider

The MinimalApi.Identity.API library used in this sample project, is still under development of new implementations.

🏗️ ToDo

  • Add endpoints to manage claims (with possible deletion only if the data is not default)
  • Add endpoints to manage users
  • Add endpoints to impersonate the user
  • Add endpoints to manage user disablement
  • Add endpoints to handle user password change every X days
  • Add endpoints to handle refresh token (currently generated, but not usable)
  • Add endpoints for two-factor authentication
  • Add endpoint for forgotten password recovery
  • Add endpoint for password change
  • Add endpoints for two-factor authentication management
  • Add endpoints for downloading and deleting personal data
  • Add API documentation

🛠️ Installation

The library is available on NuGet. Just search for MinimalApi.Identity.API in the Package Manager GUI or run the following command in the .NET CLI:

dotnet add package MinimalApi.Identity.API

🚀 Configuration

Adding this sections in the appsettings.json file:

{
    "Kestrel": {
        "Limits": {
            "MaxRequestBodySize": 5242880
        }
    },
    "JwtOptions": {
        "Issuer": "[ISSUER]",
        "Audience": "[AUDIENCE]",
        "SecurityKey": "[SECURITY-KEY]",
    },
    "NetIdentityOptions": {
        "RequireUniqueEmail": true,
        "RequireDigit": true,
        "RequiredLength": 8,
        "RequireUppercase": true,
        "RequireLowercase": true,
        "RequireNonAlphanumeric": true,
        "RequiredUniqueChars": 4,
        "RequireConfirmedEmail": true,
        "MaxFailedAccessAttempts": 3,
        "AllowedForNewUsers": true,
        "DefaultLockoutTimeSpan": "00:05:00"
    },
    "SmtpOptions": {
        "Host": "smtp.example.org",
        "Port": 25,
        "Security": "StartTls",
        "Username": "Username del server SMTP",
        "Password": "Password del server SMTP",
        "Sender": "MyApplication <noreply@example.org>",
        "SaveEmailSent": false 
    },
    "UsersOptions": {
        "AssignAdminRoleOnRegistration": "admin@example.org"
    },
    "ConnectionStrings": {
        "DefaultConnection": "Data Source=[HOSTNAME];Initial Catalog=[DATABASE];User ID=[USERNAME];Password=[PASSWORD];Encrypt=False"
    }
}

Note: If SaveEmailSent is false, only emails that failed while sending will be saved, if SaveEmailSent is true, both emails that were sent successfully and emails that failed will be saved

Registering services at Program.cs file:

var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetDatabaseConnString("DefaultConnection");

var jwtOptions = builder.Configuration.GetSettingsOptions<JwtOptions>(nameof(JwtOptions));
var identityOptions = builder.Configuration.GetSettingsOptions<NetIdentityOptions>(nameof(NetIdentityOptions));
var smtpOptions = builder.Configuration.GetSettingsOptions<SmtpOptions>(nameof(SmtpOptions));

builder.Services.AddCors(options => options.AddPolicy("cors", builder
    => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));

builder.Services.AddRegisterServices<Program>(builder.Configuration, connectionString, jwtOptions, identityOptions);
builder.Services.AddAuthorization(options =>
{
    // Adds default authorization policies
    options.AddDefaultAuthorizationPolicy();

    // Here you can add additional authorization policies
});

var app = builder.Build();

//If you need to add more exceptions you need to add the ExtendedExceptionMiddleware middleware.
//In the demo project, in the Middleware folder, you can find an implementation example.
app.UseMiddleware<ExtendedExceptionMiddleware>();

//Otherwise you can add this middleware MinimalApiExceptionMiddleware to your pipeline that handles exceptions from this library.
//app.UseMiddleware<MinimalApiExceptionMiddleware>();

app.UseRouting();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger().UseSwaggerUI();
}

app.UseCors("cors");

app.UseAuthentication();
app.UseAuthorization();

app.UseMapEndpoints();
app.Run();

📚 Demo

You can find a sample project in the example project.

📦 Dependencies

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

⭐ Give a Star

If you find this project useful, please give it a ⭐ on GitHub to show your support and help others discover it!

🤝 Contributing

Suggestions are always welcome! Feel free to open suggestion issues in the repository and we will implement them as possible.

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 was computed.  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 was computed.  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.