【问题标题】:How to Get token from Duende Identity Server (IdentityServer4)如何从 Duende 身份服务器 (IdentityServer4) 获取令牌
【发布时间】: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


    【解决方案1】:

    clientID 和 secrets 用于识别想要连接到 IdentityServer 的应用程序而不是用户;为什么不能将 clientID/secret 用于其预期用途?

    此外,OpenID 连接的主要目的是不让客户端应用程序接触或查看用户的用户名/密码。这就是我们将身份验证委托给 IdentityServer 的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-05
      • 2018-10-05
      • 2015-11-02
      • 2023-02-17
      • 2016-04-25
      • 1970-01-01
      • 2018-06-11
      • 1970-01-01
      相关资源
      最近更新 更多