簡體   English   中英

ADFS 4.0:收到無效的客戶端憑據

[英]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

我試過也試過:

  • "grant_type"="authorization_code"

有人知道“客戶端憑據”在這種情況下意味着什么?

如果發送了“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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM