[英]ADFS 4.0: Received invalid Client credentials
任何想法为什么会发生这种情况? 我们的 IT 已将 ADFS 从版本 3 更新到版本 4。更新后,我们的 ASP.NET Core 应用程序出现以下错误:
错误代码:
"Unhandled remote failure. (OAuth token endpoint failure: Status: BadRequest;
Body: {\"error\":\"invalid_client\",\"error_description\":\"MSIS9623: Received invalid Client credentials. The OAuth client is not configured to authenticate using passed in client credentials.\"};)"
请求:
https://.../adfs/oauth2/authorize?client_id=d...4c&scope=&response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A44377%2F&state=CfDJ8...Og&resource=https%3A%2F%2Flocalhost%3A44377&redirect_url=https%3A%2F%2Flocalhost%3A44377
我试过也试过:
有人知道“客户端凭据”在这种情况下意味着什么?
如果发送了“client_secret”,则 ADFS 4.0 会引发错误。 ADFS 3.0 已忽略该值。
UseOAuthAuthentication 总是发送一个“client_secret”。 我肮脏的解决方案是拦截http请求并删除“client_secret”。 如果有人有更好的解决方案...
if (securityService.IsOAuthEnabled)
{
HttpClientHandler clientHandler = new HttpClientHandlerInterceptor(){};
var options = securityService.GetOAuthOptions();
options.BackchannelHttpHandler = clientHandler;
app.UseOAuthAuthentication(options);
}
HttpClientHandler拦截器:
public class HttpClientHandlerInterceptor : HttpClientHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.Content is FormUrlEncodedContent)
{
var x = ((FormUrlEncodedContent) request.Content).ReadAsStringAsync().Result;
var contenttype = request.Content.Headers.ContentType.MediaType;
x = x.Replace("client_secret=will+be+ignored&", "");
request.Content = new StringContent(x, Encoding.UTF8, contenttype);
}
return base.SendAsync(request, cancellationToken);
}
}
当您通过向导在 ADFS 端配置应用程序时,您将获得一个 clientId。
这是您在请求中传递的 clientId。
检查您是否传递了正确的 clientId。
另请查看 ADFS 错误日志。
请注意在您的请求字符串中: response_type= code
当我从Startup.Auth.cs 中的ConfigureAuth函数中注释掉 UseOAuthe2CodeRedeemer 时,它缓解了手头的问题。
见下文:
// code_grant is present in the querystring (&code=<code>).
//app.UseOAuth2CodeRedeemer(
// new OAuth2CodeRedeemerOptions
// {
// ClientId = AuthenticationConfig.ClientId,
// ClientSecret = AuthenticationConfig.ClientSecret,
// RedirectUri = AuthenticationConfig.RedirectUri
// }
//);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.