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

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

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

        <tfoot id='NyB5o'></tfoot>
        <legend id='NyB5o'><style id='NyB5o'><dir id='NyB5o'><q id='NyB5o'></q></dir></style></legend>
      1. JwtSecurityToken 不會過期

        JwtSecurityToken doesn#39;t expire when it should(JwtSecurityToken 不會過期)
        <tfoot id='RsCTq'></tfoot>

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

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

        • <bdo id='RsCTq'></bdo><ul id='RsCTq'></ul>

        • <legend id='RsCTq'><style id='RsCTq'><dir id='RsCTq'><q id='RsCTq'></q></dir></style></legend>

                1. 本文介紹了JwtSecurityToken 不會過期的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我目前在 System.IdentityModels.Tokens 命名空間中使用 JwtSecurityToken 類.我使用以下內容創建了一個令牌:

                  I am currently using the JwtSecurityToken class in System.IdentityModels.Tokens namespace. I create a token using the following:

                  DateTime expires = DateTime.UtcNow.AddSeconds(10);
                  JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler();
                  var genericIdentity = new System.Security.Principal.GenericIdentity(username, "TokenAuth");
                  
                  ClaimsIdentity identity = new ClaimsIdentity(claims);
                  string secret = ConfigurationManager.AppSettings["jwtSecret"].ToString();
                  var securityKey = new     InMemorySymmetricSecurityKey(Encoding.Default.GetBytes(secret));
                  var signingCreds = new SigningCredentials(securityKey,     SecurityAlgorithms.HmacSha256Signature, SecurityAlgorithms.HmacSha256Signature);
                  var securityToken = handler.CreateToken(
                      issuer: issuer,
                      audience: ConfigurationManager.AppSettings["UiUrl"].ToString(),
                      signingCredentials: signingCreds,
                      subject: identity,
                      expires: expires,
                      notBefore: DateTime.UtcNow
                  );
                  return handler.WriteToken(securityToken); 
                  

                  由于某種原因,即使將 expires 設置為當前時間之后的 10 秒,在驗證令牌時它實際上不會拋出異常,直到大約 5 分鐘.看到這里,我想可能是最小過期時間為 5 分鐘,所以我將過期時間設置為:

                  For some reason even though the expires is set to 10 seconds after the current time it doesn't actually throw an exception when the token is being validated until about 5 minutes. After seeing this, I thought maybe there was a minimum expire time of 5 minutes, so I set the expire time to:

                  DateTime.UtcNow.AddMinutes(5);
                  

                  然后它在 10 分鐘過期,但是異常消息說過期時間設置為應有的時間(用戶登錄后 5 分鐘),當它在異常中顯示當前時間時它是過期時間后 5 分鐘.因此,它似乎知道它應該何時過期,但實際上直到過期時間后 5 分鐘才拋出異常.然后,由于令牌似乎在我將其設置為過期的任何時間上增加了 5 分鐘,因此我將過期時間設置為:

                  Then it expires at 10 minutes, but the exception message says that the expire time is set to what it is supposed to be (5 minutes after the user logs in), and when it shows the current time in the exception it is 5 minutes after the expire time. So, it seems to know when it SHOULD expire, but it doesn't actually throw the exception until 5 minutes after the expire time. Then, since the token seems to be adding 5 minutes to whatever time I set it to expire I set the expire time to:

                  DateTime.UtcNow.AddMinutes(-5).AddSecond(10);
                  

                  我對此進行了測試,到目前為止它還沒有過期(十多分鐘后).有人可以解釋為什么會發生這種情況以及我做錯了什么嗎?此外,如果您在我提供的代碼中看到任何其他內容,我們將不勝感激,因為我是使用 JWT 和這個庫的新手.

                  I tested this and so far it still hasn't expired (After more than ten minutes). Can someone please explain why this is happening and what I am doing wrong? Also, if you see anything else with the code I provided any guidance would be appreciated since I am new to using JWTs and this library.

                  推薦答案

                  閱讀@Denis Kucherov 的回答后,我發現我可以使用他發布的同一個自定義驗證器,而無需使用需要我添加的 JwtBearerOptions 類一個新的圖書館.

                  After reading through @Denis Kucherov's answer, I found out that I could use the same custom validator he posted without using the JwtBearerOptions class which would have required me to add a new library.

                  另外,由于有兩個命名空間包含許多相同的類,我將確保提到所有這些都使用 System.IdentityModels... 命名空間.(不是 Microsoft.IdentityModels...)

                  Also, Since there are two namespaces which contain a lot of these same classes I will make sure to mention that all of these are using the System.IdentityModels... namespaces. (NOT Microsoft.IdentityModels...)

                  下面是我最終使用的代碼:

                  Below is the code I ended up using:

                  private bool CustomLifetimeValidator(DateTime? notBefore, DateTime? expires, SecurityToken tokenToValidate, TokenValidationParameters @param)
                  {
                      if (expires != null)
                      {
                          return expires > DateTime.UtcNow;
                      }
                      return false;
                  }
                  private JwtSecurityToken ValidateJwtToken(string tokenString)
                  {
                     string secret = ConfigurationManager.AppSettings["jwtSecret"].ToString();
                     var securityKey = new InMemorySymmetricSecurityKey(Encoding.Default.GetBytes(secret));
                     JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler();
                     TokenValidationParameters validation = new TokenValidationParameters()
                     {
                         ValidAudience = "MyAudience",
                         ValidIssuer = "MyIssuer",
                         ValidateIssuer = true,
                         ValidateLifetime = true,
                         LifetimeValidator = CustomLifetimeValidator,
                         RequireExpirationTime = true,
                         IssuerSigningKey = securityKey,
                         ValidateIssuerSigningKey = true,
                     };
                     SecurityToken token;
                     ClaimsPrincipal principal = handler.ValidateToken(tokenString, validation, out token);
                     return (JwtSecurityToken)token;
                  }
                  

                  這篇關于JwtSecurityToken 不會過期的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
                      1. <legend id='aJU5G'><style id='aJU5G'><dir id='aJU5G'><q id='aJU5G'></q></dir></style></legend>
                          <bdo id='aJU5G'></bdo><ul id='aJU5G'></ul>

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

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

                              <tbody id='aJU5G'></tbody>

                            主站蜘蛛池模板: 日韩精品一区二区三区在线播放 | 成人性生交大片 | 国产日韩精品一区 | 天天草天天射 | 久久久久国产 | 久久999| 婷婷久久综合 | 国产精品伦理一区二区三区 | 国产精品不卡视频 | 国产一区二区三区四区三区四 | www.99久久.com | 中文字幕一区在线观看视频 | 在线视频亚洲 | 国产一区二区三区久久久久久久久 | 国产精品久久久久久一区二区三区 | 日韩不卡三区 | 热99精品视频 | 国产探花在线精品一区二区 | 黄网站免费在线观看 | 欧美精品一区三区 | 国产精品久久久久久久久久久免费看 | 国产精品中文字幕在线播放 | 日本三级网站在线观看 | www久久爱 | 一区二区三区视频 | 亚洲一级av毛片 | 中文字幕在线观看www | 自拍偷拍视频网 | 亚洲一区二区三区在线视频 | 日韩久久久一区二区 | 一区二区三区四区不卡 | 日韩久久久久久 | 亚洲人成在线播放 | 欧美在线亚洲 | 美美女高清毛片视频免费观看 | 免费午夜剧场 | 中文二区 | 国产激情一区二区三区 | 狠狠操狠狠干 | 99re视频在线免费观看 | jav成人av免费播放 |