久久久久久久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 不會(huì)過(guò)期

        JwtSecurityToken doesn#39;t expire when it should(JwtSecurityToken 不會(huì)過(guò)期)
        <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 不會(huì)過(guò)期的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  我目前在 System.IdentityModels.Tokens 命名空間中使用 JwtSecurityToken 類(lèi).我使用以下內(nèi)容創(chuàng)建了一個(gè)令牌:

                  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 設(shè)置為當(dāng)前時(shí)間之后的 10 秒,在驗(yàn)證令牌時(shí)它實(shí)際上不會(huì)拋出異常,直到大約 5 分鐘.看到這里,我想可能是最小過(guò)期時(shí)間為 5 分鐘,所以我將過(guò)期時(shí)間設(shè)置為:

                  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 分鐘過(guò)期,但是異常消息說(shuō)過(guò)期時(shí)間設(shè)置為應(yīng)有的時(shí)間(用戶登錄后 5 分鐘),當(dāng)它在異常中顯示當(dāng)前時(shí)間時(shí)它是過(guò)期時(shí)間后 5 分鐘.因此,它似乎知道它應(yīng)該何時(shí)過(guò)期,但實(shí)際上直到過(guò)期時(shí)間后 5 分鐘才拋出異常.然后,由于令牌似乎在我將其設(shè)置為過(guò)期的任何時(shí)間上增加了 5 分鐘,因此我將過(guò)期時(shí)間設(shè)置為:

                  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);
                  

                  我對(duì)此進(jìn)行了測(cè)試,到目前為止它還沒(méi)有過(guò)期(十多分鐘后).有人可以解釋為什么會(huì)發(fā)生這種情況以及我做錯(cuò)了什么嗎?此外,如果您在我提供的代碼中看到任何其他內(nèi)容,我們將不勝感激,因?yàn)槲沂鞘褂?JWT 和這個(gè)庫(kù)的新手.

                  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 的回答后,我發(fā)現(xiàn)我可以使用他發(fā)布的同一個(gè)自定義驗(yàn)證器,而無(wú)需使用需要我添加的 JwtBearerOptions 類(lèi)一個(gè)新的圖書(shū)館.

                  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.

                  另外,由于有兩個(gè)命名空間包含許多相同的類(lèi),我將確保提到所有這些都使用 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;
                  }
                  

                  這篇關(guān)于JwtSecurityToken 不會(huì)過(guò)期的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

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

                            主站蜘蛛池模板: 精品精品| 日韩精品国产一区 | 亚洲成人精品 | 国产福利小视频 | 亚洲免费在线 | 久久精品视频一区二区 | 97精品在线观看 | 色综合久久天天综合网 | 亚洲小说欧美激情另类 | 免费a网站 | 国产精品国产精品国产专区不卡 | 亚洲成人a v | 日本一区二区不卡 | 国产精品欧美一区二区 | 日韩av免费在线观看 | 国产成人精品一区二区三区视频 | 可以免费看av的网站 | 四虎影视最新地址 | 久久久精品国产sm调教网站 | 操操影院 | 成人毛片100免费观看 | 超碰av在线播放 | 黄色av免费在线观看 | 在线一区二区三区 | 久草国产视频 | 国产成人91 | 中文字幕第一页在线 | 成人在线不卡 | 亚洲激情四射 | 欧美激情成人 | 国产在线免费 | 日韩av在线免费 | 国产精品一区二区三区四区 | 中文字幕欧美在线 | 国产性色av | 狠狠操天天干 | 国产午夜精品久久久久久久 | 黄色影音 | 黄色一级片免费 | 黄色av一区 | 毛片毛片毛片毛片毛片毛片 |