Identity.Mongo
1.0.1
See the version list below for details.
dotnet add package Identity.Mongo --version 1.0.1
NuGet\Install-Package Identity.Mongo -Version 1.0.1
<PackageReference Include="Identity.Mongo" Version="1.0.1" />
<PackageVersion Include="Identity.Mongo" Version="1.0.1" />
<PackageReference Include="Identity.Mongo" />
paket add Identity.Mongo --version 1.0.1
#r "nuget: Identity.Mongo, 1.0.1"
#:package Identity.Mongo@1.0.1
#addin nuget:?package=Identity.Mongo&version=1.0.1
#tool nuget:?package=Identity.Mongo&version=1.0.1
Identity.Mongo
Overview
Identity.Mongo is an open-source library that extends Identity Framework to integrate MongoDB as the backing store. It enables user authentication, roles, and claims management using MongoDB.
Installation
Install the package via NuGet:
dotnet add package Identity.Mongo
Or through the NuGet Package Manager:
Install-Package Identity.Mongo
Getting Started
Step 1: Create a Class that Extends the Base Class
To use the library, create a new class that extends the provided base class MongoDbContext
:
using Identity.Mongo;
public class AppDbContext : MongoDbContext
{
protected override void ConfigureCollections()
{
// Add your collections here
}
}
Step 2: Register the Class in Program.cs
In your Program.cs
, register the extended class as a service. For example:
using Identity.Mongo;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddMongoDb<AppDbContext>("connectionString","databaseName");
builder.Services.AddIdentity<IdentityUser, IdentityRole>()
.AddMongoStores()
.AddDefaultTokenProviders();
var app = builder.Build();
// Configure the HTTP request pipeline.
// Additional middleware setup if necessary
app.Run();
Usage
Identity Framework: Now that you configured your db context and added mongo stores to identity framework you could start using identity framework as normal
public class MyController(UserManager<IdentityUser> uMgr) : ControllerBase
{
[HttpGet("/add-user")]
public async Task<IActionResult> AddAndGetUser()
{
var result = await uMgr.CreateAsync(new IdentityUser
{
Email = "test@test.com",
UserName = "abdo"
});
return Ok(result);
}
}
Optionally you could add collections to your db context by using the built in Database property.
using Identity.Mongo;
public class AppDbContext : MongoDbContext
{
protected override void ConfigureCollections()
{
Collection = Database.GetCollection<YourModel>("collectionName");
}
public IMongoCollection<YourModel> Collection { get; set; }
}
Then inject it in other classes and start using the context to access mongodb.
public class MyController(AppDbContext ctx) : ControllerBase
{
[HttpGet]
public async Task<IActionResult> DoSomething()
{
var results = ctx.Collection
.Find(_ => true)
.ToListAsync();
return Ok(results);
}
}
Support
If you encounter any issues or have questions, feel free to open an issue on the GitHub repository.
Product | Versions 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. |
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Identity.Stores (>= 8.0.10)
- MongoDB.Driver (>= 2.29.0)
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.1.0 | 139 | 10/21/2024 |
1.0.2 | 104 | 10/16/2024 |
1.0.1 | 105 | 10/16/2024 |
1.0.0 | 112 | 10/16/2024 |
1.0.0-alpha.6 | 68 | 10/15/2024 |
1.0.0-alpha.5 | 69 | 10/14/2024 |
1.0.0-alpha.3 | 69 | 10/13/2024 |
1.0.0-alpha.2 | 65 | 10/13/2024 |
1.0.0-alpha.1 | 65 | 10/13/2024 |