久久久久久久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国内外精品自在线播放 | 精品日韩一区二区 | 午夜影院在线 | 成人精品一区二区 | 国产精品99久久久久久宅男 | 欧美一区不卡 | 亚洲欧洲日韩精品 中文字幕 | 日本又色又爽又黄的大片 | 91偷拍精品一区二区三区 | 日韩av网址在线观看 | 国产成人精品一区二 | 国产一区久久久 | 亚洲九九精品 | 欧美综合一区二区三区 | 亚洲毛片 | 久久91| 亚洲成人综合社区 | 国产原创在线观看 | 五月婷婷激情网 | 日韩一区在线播放 | 久草在线免费资源 | 国产午夜三级一区二区三 | 天天操天天干天天爽 | 亚洲乱码国产乱码精品精98午夜 | 成人欧美一区二区三区黑人孕妇 | 亚洲人成人一区二区在线观看 | 羞羞在线观看视频 | 中文字幕在线第二页 | 日本二区在线观看 | 日本爱爱视频 | 四虎最新| 欧美高清视频一区 | 97日韩精品 | 久久鲁视频 | 激情av免费看 | 在线日韩欧美 | 精品国产色 | 欧美在线观看一区 | 欧美日韩亚洲国产 | 超碰人人人 |