61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
using IM.InitCommon.Management;
|
||
|
||
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();
|
||
if (app.ApplyMigrationsIfRequested(args)) return;
|
||
|
||
// Configure the HTTP request pipeline.
|
||
if (app.Environment.IsDevelopment())
|
||
{
|
||
app.UseSwagger();
|
||
app.UseSwaggerUI();
|
||
}
|
||
|
||
app.UseAppDefault();
|
||
app.MapManagementHealth();
|
||
|
||
app.MapControllers();
|
||
app.MapAllGrpcServer();
|
||
|
||
app.Run();
|
||
}
|
||
}
|
||
}
|