添加项目文件。
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
|
||||
using IdentityService.Domain.Entities;
|
||||
using IdentityService.Infrastructure;
|
||||
using IM.InitCommon;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace IdentityService.WebApi
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.ConfigureDbConfiguration();
|
||||
builder.ConfigExtraServices();
|
||||
// 2. 🌟 微软 Identity 终极注册组合拳
|
||||
builder.Services.AddIdentityCore<User>(options =>
|
||||
{
|
||||
// 这里可以顺手配置一下密码规则,比如不需要大写字母、最小长度等
|
||||
options.Password.RequireLowercase = false;
|
||||
options.Password.RequireNonAlphanumeric = false;
|
||||
options.Password.RequireUppercase = false;
|
||||
options.Password.RequiredLength = 6;
|
||||
})
|
||||
.AddRoles<Role>()
|
||||
.AddEntityFrameworkStores<UserDbContext>() // 👈 灵魂所在:自动向 DI 注入 IUserStore<User> 等几十个底层接口!
|
||||
.AddUserManager<IdUserManager>() // 👈 告诉框架:不要用你默认的 UserManager,用我自定义的 IdUserManager!
|
||||
.AddRoleManager<RoleManager<Role>>()
|
||||
.AddDefaultTokenProviders(); // 👈 顺带注册生成验证码/重置密码Token的服务
|
||||
|
||||
|
||||
builder.Services.AddAllGrpcServer();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseAppDefault();
|
||||
|
||||
app.MapControllers();
|
||||
app.MapAllGrpcServer();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user