【发布时间】:2022-11-21 03:11:31
【问题描述】:
有几天我在阅读 Duende 身份服务器 (IdentityServer4),所以我了解不同的概念及其用法,例如范围、资源、客户端......
我感到困惑的领域是客户。所以我将 AspIdentity 作为 ApplicationUser 集成到 IdentityServer 中(您可以在下面的代码部分找到配置)但是当我想调用 Duende 的预定义端点 /connect/token 时,它需要添加 ClientId 和秘密,但我想使用我注册用户的用户名和密码。
所以我想到的想法是创建一个自定义端点:在使用 SignInManager 验证用户的凭据之后,我将找到用户客户端,然后登录到 Duende IdentityServer,但是我尝试这样做,但这有点不方便再次对同一服务进行 HTTP 调用以获取用户的令牌。
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(connectionString));
builder.Services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
builder.Services.AddSwaggerGen();
builder.Services
.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
options.EmitStaticAudienceClaim = true;
})
.AddAspNetIdentity<ApplicationUser>()
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = b =>
b.UseSqlite(connectionString, dbOpts => dbOpts.MigrationsAssembly(typeof(Program).Assembly.FullName));
})
.AddOperationalStore(options =>
{
options.ConfigureDbContext = b =>
b.UseSqlite(connectionString, dbOpts => dbOpts.MigrationsAssembly(typeof(Program).Assembly.FullName));
options.EnableTokenCleanup = true;
options.RemoveConsumedTokens = true;
});
builder.Services.AddAuthentication();
如果我能以一种方便的方式解决这个问题,那么其他步骤就非常明显和直接了当。
【问题讨论】:
标签: c# asp.net-core identityserver4 duende