久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <tfoot id='ucW1l'></tfoot>
    1. <i id='ucW1l'><tr id='ucW1l'><dt id='ucW1l'><q id='ucW1l'><span id='ucW1l'><b id='ucW1l'><form id='ucW1l'><ins id='ucW1l'></ins><ul id='ucW1l'></ul><sub id='ucW1l'></sub></form><legend id='ucW1l'></legend><bdo id='ucW1l'><pre id='ucW1l'><center id='ucW1l'></center></pre></bdo></b><th id='ucW1l'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ucW1l'><tfoot id='ucW1l'></tfoot><dl id='ucW1l'><fieldset id='ucW1l'></fieldset></dl></div>

        <small id='ucW1l'></small><noframes id='ucW1l'>

          <bdo id='ucW1l'></bdo><ul id='ucW1l'></ul>
      1. <legend id='ucW1l'><style id='ucW1l'><dir id='ucW1l'><q id='ucW1l'></q></dir></style></legend>
      2. 使用 OWIN 和 JWT 時如何記錄身份驗證失敗的原因

        How to log authentication failure reasons when using OWIN and JWT?(使用 OWIN 和 JWT 時如何記錄身份驗證失敗的原因?)

          1. <legend id='Rn4J0'><style id='Rn4J0'><dir id='Rn4J0'><q id='Rn4J0'></q></dir></style></legend>
              <tbody id='Rn4J0'></tbody>
          2. <tfoot id='Rn4J0'></tfoot>

              • <bdo id='Rn4J0'></bdo><ul id='Rn4J0'></ul>
              • <small id='Rn4J0'></small><noframes id='Rn4J0'>

                1. <i id='Rn4J0'><tr id='Rn4J0'><dt id='Rn4J0'><q id='Rn4J0'><span id='Rn4J0'><b id='Rn4J0'><form id='Rn4J0'><ins id='Rn4J0'></ins><ul id='Rn4J0'></ul><sub id='Rn4J0'></sub></form><legend id='Rn4J0'></legend><bdo id='Rn4J0'><pre id='Rn4J0'><center id='Rn4J0'></center></pre></bdo></b><th id='Rn4J0'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Rn4J0'><tfoot id='Rn4J0'></tfoot><dl id='Rn4J0'><fieldset id='Rn4J0'></fieldset></dl></div>
                  本文介紹了使用 OWIN 和 JWT 時如何記錄身份驗證失敗的原因?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在使用 c# 自托管 OWIN 服務器,并已將我的應用程序配置為使用 JWT 授權,如下所示.這可以正常工作,無效令牌會被 401 Unauthorized 拒絕并接受有效令牌.

                  I am using a c# self hosted OWIN server and have configured my application to use authorise with JWT as below. This works properly, and invalid tokens are rejected with a 401 Unauthorized and valid tokens are accepted.

                  我的問題是我怎樣才能寫一個為什么請求被拒絕的日志.是不是過期了?是不是觀眾錯了?沒有令牌存在嗎?我希望記錄所有失敗的請求,但我似乎找不到任何示例.

                  My question is how can I write a log of why requests are rejected. Was it expired? Was it the wrong audience? Was no token present? I want all failed requests to be logged, but I can't seem to find any example of how.

                  public class Startup
                      {
                          public void Configuration(IAppBuilder appBuilder)
                          {
                  
                              // Configure Web API for self-host. 
                              config.Routes.MapHttpRoute(
                                  name: "DefaultApi",
                                  routeTemplate: "api/{controller}/{id}",
                                  defaults: new { id = RouteParameter.Optional }
                              );
                  
                              // Enable 
                              config.Filters.Add(new AuthorizeAttribute());
                  
                              appBuilder.UseJwtBearerAuthentication(new JwtOptions());
                              appBuilder.UseWebApi(config);
                          }
                      }
                  

                  JwtOptions.cs

                  JwtOptions.cs

                  public class JwtOptions : JwtBearerAuthenticationOptions
                      {
                          public JwtOptions()
                          {
                              var issuer = WebConfigurationManager.AppSettings["CertificateIssuer"];
                              var audience = WebConfigurationManager.AppSettings["CertificateAudience"];
                  
                              var x590Certificate = Ap21X509Certificate.Get(WebConfigurationManager.AppSettings["CertificateThumbprint"]);
                  
                              AllowedAudiences = new[] { audience };
                              IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
                              {
                                  new X509CertificateSecurityTokenProvider(issuer, new X509Certificate2(x590Certificate.RawData))
                              };
                          }
                      }
                  

                  我猜我需要實現自己的驗證才能做到這一點,但也不確定如何實現.

                  I am guessing I will need to implement my own validation to do this, but not sure how to implement that either.

                  推薦答案

                  我知道現在已經很晚了,但是對于正在努力尋找答案的人來說很有用.

                  I know that it is quite late, but can be useful for one how is struggling to find an answer.

                  基本上 AuthenticationMiddleware 具有嵌入式日志記錄.您只需要將 OWIN 日志重定向到您正在使用的記錄器.NLog.Owin.Logging 適合我.log4net 也有類似的解決方案.

                  Basically AuthenticationMiddleware has embedded logging. You just need to redirect OWIN logs to logger you are using. NLog.Owin.Logging works well for me. There is similar solution for log4net.

                  有替代解決方案.擴展 JwtSecurityTokenHandler 并手動記錄原因.

                  There is alternative solution. Extend JwtSecurityTokenHandler and log the reason manually.

                  public class LoggingJwtSecurityTokenHandler : JwtSecurityTokenHandler
                  {
                      public override ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParameters validationParameters, out SecurityToken validatedToken)
                      {
                          try
                          {
                              return base.ValidateToken(securityToken, validationParameters, out validatedToken);
                          }
                          catch (Exception ex)
                          {
                              //log the error
                              throw;
                          }
                      }
                  }
                  

                  并像這樣使用它:

                  app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions
                  {
                      TokenHandler = new LoggingJwtSecurityTokenHandler()
                  });
                  

                  這篇關于使用 OWIN 和 JWT 時如何記錄身份驗證失敗的原因?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                  onClick event for Image in Unity(Unity中圖像的onClick事件)
                  Running Total C#(運行總 C#)
                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                  Calling A Button OnClick from a function(從函數調用按鈕 OnClick)

                    <bdo id='9kKac'></bdo><ul id='9kKac'></ul>
                  • <tfoot id='9kKac'></tfoot>
                        <tbody id='9kKac'></tbody>

                      <small id='9kKac'></small><noframes id='9kKac'>

                    • <legend id='9kKac'><style id='9kKac'><dir id='9kKac'><q id='9kKac'></q></dir></style></legend>
                          <i id='9kKac'><tr id='9kKac'><dt id='9kKac'><q id='9kKac'><span id='9kKac'><b id='9kKac'><form id='9kKac'><ins id='9kKac'></ins><ul id='9kKac'></ul><sub id='9kKac'></sub></form><legend id='9kKac'></legend><bdo id='9kKac'><pre id='9kKac'><center id='9kKac'></center></pre></bdo></b><th id='9kKac'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='9kKac'><tfoot id='9kKac'></tfoot><dl id='9kKac'><fieldset id='9kKac'></fieldset></dl></div>
                            主站蜘蛛池模板: 亚洲一区国产 | 国产一区二区成人 | 天天干国产| 精品视频网 | 九一在线 | 羞羞的视频免费在线观看 | 日本精品裸体写真集在线观看 | 欧美一区两区 | 欧美性视频在线播放 | 亚洲精品成人在线 | 91热在线| 亚洲日日操| 日韩欧美国产一区二区三区 | 中文字幕亚洲视频 | 免费观看黄a一级视频 | 色吊丝在线| 白浆在线 | 啪啪免费网 | 午夜爽爽男女免费观看hd | 亚洲综合大片69999 | 午夜国产一级 | 成人亚洲网| 草草草草视频 | www..99re| 国产激情一区二区三区 | 蜜桃精品视频在线 | 亚洲成人av在线播放 | 日韩精品久久久久 | 伊人久久在线 | 成人av一区二区在线观看 | 精品1区2区| 一区二区三区精品在线 | 久久久久亚洲精品国产 | 国产免费又黄又爽又刺激蜜月al | 精品国产18久久久久久二百 | 欧美在线观看一区 | 一级看片 | 天天爽夜夜爽精品视频婷婷 | 国产区高清 | 黑人久久 | 爱爱视频日本 |