/LiteDB.Identity

ASP.NET Core Identity provider for LiteDB database engine.

Primary LanguageC#MIT LicenseMIT

LiteDB.Identity

The implementation of ASP.NET Core Identity for the LiteDB database engine.

LiteDB.Identity will provide quick creation of login, registration, roles, claims, and token functionality for web applications.

Latest versions supports:

  • LiteDB 5.0.15
  • .NET 6 and .NET 7
  • .NETSTANDARD 2.1
  • Microsoft.Extensions.Identity.Stores 6.0.13 and 7.0.2

How to use it ?

Please install latest version of LiteDB.Identity using NuGet:

Install-Package LiteDB.Identity

For ASP.NET Core 7:

Install-Package LiteDB.Identity -Version 1.0.7

For ASP.NET Core 6:

Install-Package LiteDB.Identity -Version 1.0.6

For ASP.NET Core 3.1:

Install-Package LiteDB.Identity -Version 1.0.3

Next, in your Startup.cs file add reference to namespace:

using LiteDB.Identity.Extensions;

Add default LiteDb.Identity implementation in ConfigureServices method:

For ASP.NET Core 6 and 7 :

using LiteDB.Identity.Extensions;
using Microsoft.AspNetCore.Identity;

var builder = WebApplication.CreateBuilder(args);

// Add Identity services to the container.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddLiteDBIdentity(connectionString).AddDefaultTokenProviders().AddDefaultUI();
//...
builder.Services.AddControllersWithViews();

var app = builder.Build();
//...
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();

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

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapRazorPages();
app.Run();

For ASP.NET Core 3.1:

        public void ConfigureServices(IServiceCollection services)
        {

            string connectionString = Configuration.GetConnectionString("IdentityLiteDB");
            services.AddLiteDBIdentity(connectionString).AddDefaultTokenProviders().AddDefaultUI();

            services.AddControllersWithViews();
            services.AddRazorPages();
        }

NOTE: appsettings.json should contains connection string to your LiteDB file. For more implementation details please refer to sample project.

Stores implementation

Following interfaces has been implemented on :

  • UserStore :
    public class UserStore<TUser, TRole, TUserRole, TUserClaim, TUserLogin, TUserToken> : 
                                    IUserLoginStore<TUser>, 
                                    IUserStore<TUser>,
                                    IUserRoleStore<TUser>,
                                    IUserClaimStore<TUser>, 
                                    IUserPasswordStore<TUser>, 
                                    IUserSecurityStampStore<TUser>, 
                                    IUserEmailStore<TUser>, 
                                    IUserLockoutStore<TUser>, 
                                    IUserPhoneNumberStore<TUser>, 
                                    IQueryableUserStore<TUser>, 
                                    IUserTwoFactorStore<TUser>,
                                    IUserAuthenticationTokenStore<TUser>,
                                    IUserAuthenticatorKeyStore<TUser>,
                                    IUserTwoFactorRecoveryCodeStore<TUser>
  • RoleStore :
    public class RoleStore<TRole, TRoleClaim> : IQueryableRoleStore<TRole>, 
                                                IRoleStore<TRole>, 
                                                IRoleClaimStore<TRole>

Where to use it ?

  • Great for small and medium size website application based on:
    • ASP.NET Core MVC,
    • Blazor Server,
    • ASP.NET Core WebPages,
  • Quick implementation of Authentication and Authorization mechanism for WebAPIs.

Support

If you have found my contributions to the projects helpful, consider buying me a coffee to fuel my efforts :)
Buy Me A Coffee

References

License

MIT