【问题标题】:OpenIdConnect HTTP Basic authentication scheme for client authentication用于客户端身份验证的 OpenIdConnect HTTP 基本身份验证方案
【发布时间】:2018-07-03 11:53:51
【问题描述】:

我正在尝试实现 OpenIdConnect 登录到我的 .net core 2.0 站点。 我尝试使用的 IdentityServer 仅支持 'client_secret_basic' 作为 token_endpoint_auth_methods。 我将应用程序配置如下:

            services.AddAuthentication(options =>
        {
            options.DefaultAuthenticateScheme = "Cookies";
            options.DefaultSignInScheme = "Cookies";
            options.DefaultChallengeScheme = "oidc";
        })
       .AddCookie()
       .AddOpenIdConnect(options =>
       {
           options.SignInScheme = "Cookies";
           options.Authority = Auhtority;
           options.ClientId = ClientID;
           options.ClientSecret = ClientSecret;
           options.ResponseType = "code";
           options.SaveTokens = true;
           options.Scope.Add("profile");
           options.Scope.Add("rrn");
       });

但这似乎将 ClientId 和 ClientSecret 发布到请求的正文中,而不是使用 HTTP Basic 身份验证。 我可能遗漏了一些明显的东西,但我似乎找不到如何配置 OpenIdConnect 以使用 client_secret_basic 而不是 client_secret_post。 有什么想法吗?

【问题讨论】:

  • 不相关:您的 options.DefaultChallengeScheme 应该是 OpenIdConnect。
  • 不支持令牌端点的替代身份验证方法。您可以使用 AuthorizationCodeReceived 事件自行兑换代码。
  • 好的,谢谢,有关于如何兑换代码的示例吗?
  • 我有一个使用 Azure AD 的小示例:github.com/juunas11/aspnetcore2aadauth/blob/master/Core2AadAuth/…。它使用AAD库来获取令牌,但是获取令牌后使用HandleCodeRedemption(accessToken, idToken)的一般方法是相同的。
  • 这里展示了如何使用该事件,但它不涵盖该流程。您需要使用 HttpClient 发送您自己的请求。 github.com/aspnet/Security/blob/…

标签: asp.net-mvc asp.net-core openid-connect


【解决方案1】:

我遇到了同样的问题,我终于使用以下选项/事件挂钩using System.Net.Http;

options.Events.OnAuthorizationCodeReceived = context =>
        {
            context.Backchannel.SetBasicAuthenticationOAuth(context.TokenEndpointRequest.ClientId, context.TokenEndpointRequest.ClientSecret);
            return Task.CompletedTask;
        };

我主要是从您的问题的 cmets 中得到的,其中提到的方法被标记为已弃用,并提示我使用的新扩展方法。

【讨论】:

  • 你刚刚拯救了我的一天!谢谢!
  • 您还需要从请求正文中删除client_id/client_secret(来自rfc客户端不得在每个请求中使用多个身份验证方法。 )。只需在context.TokenEnpointRequest 中将它们设置为null
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-23
  • 2011-10-27
  • 1970-01-01
相关资源
最近更新 更多