EasilyNET.IdentityServer.MongoStorage 2.1.9

dotnet add package EasilyNET.IdentityServer.MongoStorage --version 2.1.9                
NuGet\Install-Package EasilyNET.IdentityServer.MongoStorage -Version 2.1.9                
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="EasilyNET.IdentityServer.MongoStorage" Version="2.1.9" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasilyNET.IdentityServer.MongoStorage --version 2.1.9                
#r "nuget: EasilyNET.IdentityServer.MongoStorage, 2.1.9"                
#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.
// Install EasilyNET.IdentityServer.MongoStorage as a Cake Addin
#addin nuget:?package=EasilyNET.IdentityServer.MongoStorage&version=2.1.9

// Install EasilyNET.IdentityServer.MongoStorage as a Cake Tool
#tool nuget:?package=EasilyNET.IdentityServer.MongoStorage&version=2.1.9                
IdentityServer 7.x Data Persistence for MongoDB

参考项目 Github

寻求帮助: 希望能有懂 Razor 的同学帮我根据官方的 QuickUI 写一个管理页面, 若是能教我 Razor 的话那就更 Nice 了.

  • 本地使用 docker 启动 MongoDB 服务
docker run --name mongo1 -p 27017:27017 -d --rm -it -e MONGO_INITDB_ROOT_USERNAME=guest -e MONGO_INITDB_ROOT_PASSWORD="guest" mongo:latest
如何使用.
  • Install Package
Install-Package EasilyNET.IdentityServer.MongoStorage
  • appsettings.json 内容
{
  "ConnectionStrings": {
    "MongoDB": "mongodb://guest:guest@127.0.1:27017/?authSource=admin&serverSelectionTimeoutMS=1000"
  }
}
  • Add the following code to the Program.cs file in the root of the project
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddIdentityServer(options =>
       {
           options.Events.RaiseErrorEvents = true;
           options.Events.RaiseInformationEvents = true;
           options.Events.RaiseFailureEvents = true;
           options.Events.RaiseSuccessEvents = true;
           // see https://docs.duendesoftware.com/identityserver/v6/fundamentals/resources/
           options.EmitStaticAudienceClaim = true;
       })
       .AddConfigurationStore(c =>
       {
           c.ConnectionString = builder.Configuration.GetConnectionString("MongoDB")!;
           c.Database = "IdentityServer";
       })
       .AddOperationalStore(tco =>
       {
           tco.Enable = true;
           tco.Interval = 3600;
       })
       // 其他配置
       //.AddCustomTokenRequestValidator<CustomTokenRequestValidator>()
       .AddDeveloperSigningCredential();

builder.Services.AddAuthentication()
       .AddOpenIdConnect("demoidsrv", "IdentityServer", options =>
       {
           options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
           options.SignOutScheme = IdentityServerConstants.SignoutScheme;
           options.Authority = "https://demo.identityserver.io/";
           options.ClientId = "implicit";
           options.ResponseType = "id_token";
           options.SaveTokens = true;
           options.CallbackPath = new("/signin-idsrv");
           options.SignedOutCallbackPath = new("/signout-callback-idsrv");
           options.RemoteSignOutPath = new("/signout-idsrv");
           options.TokenValidationParameters = new() { NameClaimType = "name", RoleClaimType = "role" };
       });

var app = builder.Build();
if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseRouting();

// this seeding is only for the template to bootstrap the DB and users.
// in production you will likely want a different approach.
// 初次运行发送配置数据到数据库
using (var scop = app.Services.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
    SendData.EnsureSeedData(scop.ServiceProvider.GetRequiredService<IConfigurationDbContext>());
}
app.UseIdentityServer();
app.UseAuthorization();
app.Run();
internal static class SendData
{
    internal static void EnsureSeedData(IConfigurationDbContext context)
    {
        if (!context.Clients.Any())
        {
            foreach (var client in Config.Clients)
            {
                context.AddClient(client.ToEntity());
            }
        }
        if (!context.IdentityResources.Any())
        {
            foreach (var resource in Config.IdentityResources)
            {
                context.AddIdentityResource(resource.ToEntity());
            }
        }
        if (!context.ApiResources.Any())
        {
            foreach (var resource in Config.ApiResources)
            {
                context.AddApiResource(resource.ToEntity());
            }
        }
        if (!context.ApiScopes.Any())
        {
            foreach (var resource in Config.ApiScopes)
            {
                context.AddApiScope(resource.ToEntity());
            }
        }
    }
}
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. 
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
2.1.9 245 2/21/2024