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

<tfoot id='UbvVO'></tfoot>
  • <legend id='UbvVO'><style id='UbvVO'><dir id='UbvVO'><q id='UbvVO'></q></dir></style></legend>

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

    1. <i id='UbvVO'><tr id='UbvVO'><dt id='UbvVO'><q id='UbvVO'><span id='UbvVO'><b id='UbvVO'><form id='UbvVO'><ins id='UbvVO'></ins><ul id='UbvVO'></ul><sub id='UbvVO'></sub></form><legend id='UbvVO'></legend><bdo id='UbvVO'><pre id='UbvVO'><center id='UbvVO'></center></pre></bdo></b><th id='UbvVO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='UbvVO'><tfoot id='UbvVO'></tfoot><dl id='UbvVO'><fieldset id='UbvVO'></fieldset></dl></div>
        • <bdo id='UbvVO'></bdo><ul id='UbvVO'></ul>
      1. JWT 驗證失敗

        JWT Validation fails(JWT 驗證失敗)

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

            <tbody id='yjeiJ'></tbody>
        1. <tfoot id='yjeiJ'></tfoot>
                <bdo id='yjeiJ'></bdo><ul id='yjeiJ'></ul>
                <legend id='yjeiJ'><style id='yjeiJ'><dir id='yjeiJ'><q id='yjeiJ'></q></dir></style></legend>

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

                • 本文介紹了JWT 驗證失敗的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我通過如下所示設置 Payload 創(chuàng)建了一個 JwtToken

                  var payload = new JwtPayload{{"aud", "wellmark.com" },{"iss", "wellmark" },{"iat", DateTime.Now.Ticks },{"exp", DateTime.Now.AddDays(90).Ticks },};

                  我必須使用刻度的原因是因為這是獲取發(fā)布時間和到期時間的整數(shù)值的唯一方法.我同意 ticks 實際上是 long 而不是 int,但這是唯一的方法.

                  現(xiàn)在當我回來驗證令牌時,我正在執(zhí)行以下操作

                  var tokenValidationParams = new TokenValidationParameters{IssuerSigningKey = new X509SecurityKey(jwtCert),ValidAudience = "蒙面",ValidIssuer = "屏蔽",IssuerSigningKeyResolver =(字符串令牌,Microsoft.IdentityModel.Tokens.SecurityToken securityToken,字符串孩子,TokenValidationParameters 驗證參數(shù))=>新列表<X509SecurityKey>{ 新 X509SecurityKey(jwtCert) }};tokenHandler.ValidateToken(id, tokenValidationParams,出驗證令牌);

                  但是說不出來

                  <塊引用>

                  生命周期驗證失敗.令牌缺少過期時間.令牌類型:'System.IdentityModel.Tokens.Jwt.JwtSecurityToken'.

                  這很可能是因為驗證方法試圖將 long 轉(zhuǎn)換為 int 并且由于它無法轉(zhuǎn)換它,所以它只是返回 null,如顯示的文檔中所示 這里.

                  有沒有人在這個機制上取得了成功.請注意,我使用 X509 證書來簽署我的 Jwt.

                  納拉辛哈姆

                  解決方案

                  Exp時間戳不能使用Ticks

                  JWT 中的時間戳是從 01.01.1970 00:00 UTC 開始計算的 UNIX 時間戳:https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4 解釋說數(shù)字日期用于 exp 聲明(也用于 nbf(不是之前)和 iat(簽發(fā)于)索賠)

                  https://www.rfc-editor.org/rfc/rfc7519#section-2 定義數(shù)字日期:

                  <塊引用>

                  一個 JSON 數(shù)值,表示從1970-01-01T00:00:00Z UTC 直到指定的 UTC 日期/時間,忽略閏秒.

                  如果您像在示例中那樣直接創(chuàng)建有效負載,則需要計算自 1.1.1970 UTC 以來的秒數(shù),例如:

                  DateTime CenturyBegin = new DateTime(1970, 1, 1);var exp = new TimeSpan(DateTime.Now.AddDays(90).Ticks - CenturyBegin.Ticks).TotalSeconds;

                  exp 是從現(xiàn)在開始的 90 天.當然,您也可以使用任何其他 Add... 方法來計算到期時間.參考 https://msdn.microsoft.com/de-de/library/system.datetimeoffset(v=vs.110).aspx 查看其他 Add 方法.

                  一些框架(例如 System.IdentityModel.Tokens.Jwt)提供了創(chuàng)建令牌的函數(shù),這些令牌接受 DateTimeOffset 類型的參數(shù),這更容易處理.

                  使用 http://www.unixtimestamp.com/ 或類似網(wǎng)站檢查您的時間戳p>

                  I have created a JwtToken by setting up the Payload as shown below

                  var payload = new JwtPayload
                          {
                              {"aud", "wellmark.com" },
                              {"iss", "wellmark" },
                              {"iat", DateTime.Now.Ticks },
                              {"exp", DateTime.Now.AddDays(90).Ticks },
                          };
                  

                  The reason I had to use ticks is because that is the only way to get an integer value for the issued at and expiration times. I agree that ticks is in fact a long and not an int, but that was the only way.

                  Now when I come back to validate the token, I am doing the below

                  var tokenValidationParams = new TokenValidationParameters
                              {
                                  IssuerSigningKey = new X509SecurityKey(jwtCert),
                                  ValidAudience = "masked",
                                  ValidIssuer = "masked",
                                  IssuerSigningKeyResolver = (string token, Microsoft.IdentityModel.Tokens.SecurityToken securityToken, string kid, TokenValidationParameters validationParameters) => new List<X509SecurityKey> { new X509SecurityKey(jwtCert) }
                              };
                  
                              tokenHandler.ValidateToken(id, tokenValidationParams
                                     , out validatedToken);
                  

                  It is however failing saying

                  Lifetime validation failed. The token is missing an Expiration Time. Tokentype: 'System.IdentityModel.Tokens.Jwt.JwtSecurityToken'.

                  This is most likely because the validation method is trying to convert the long to an int and because it is unable to convert it, it simply returns a null as indicated in the documentation shown here.

                  Has anyone had success with this mechanism. Please note that I am using X509 Certificate to Sign my Jwt.

                  Narasimham

                  解決方案

                  You can't use Ticks for the exp timestamp

                  The timestamps in JWT are UNIX timestamps counting from 01.01.1970 00:00 UTC: https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4 explains that a numeric date is used for the exp claim (and also for the nbf (not before) and iat (issued at) claims)

                  https://www.rfc-editor.org/rfc/rfc7519#section-2 defines the numeric date:

                  A JSON numeric value representing the number of seconds from 1970-01-01T00:00:00Z UTC until the specified UTC date/time, ignoring leap seconds.

                  If you create the payload directly like you did in your example you need to calculate the seconds since 1.1.1970 UTC for example like this:

                  DateTime centuryBegin = new DateTime(1970, 1, 1);
                  var exp = new TimeSpan(DateTime.Now.AddDays(90).Ticks - centuryBegin.Ticks).TotalSeconds;
                  

                  exp is then 90 days from now. Of course you can use any of the other Add... methods as well to calculate the expriation time. Refer to https://msdn.microsoft.com/de-de/library/system.datetimeoffset(v=vs.110).aspx to see the other Add methods.

                  Some frameworks (e.g. System.IdentityModel.Tokens.Jwt) offer functions to create tokens which accept parameters of the type DateTimeOffset, which is easier to handle.

                  Use http://www.unixtimestamp.com/ or similar sites to check your timestamps

                  這篇關于JWT 驗證失敗的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關文檔推薦

                  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(從函數(shù)調(diào)用按鈕 OnClick)

                    <tbody id='IyBZ3'></tbody>

                  <legend id='IyBZ3'><style id='IyBZ3'><dir id='IyBZ3'><q id='IyBZ3'></q></dir></style></legend>
                    <bdo id='IyBZ3'></bdo><ul id='IyBZ3'></ul>

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

                            <i id='IyBZ3'><tr id='IyBZ3'><dt id='IyBZ3'><q id='IyBZ3'><span id='IyBZ3'><b id='IyBZ3'><form id='IyBZ3'><ins id='IyBZ3'></ins><ul id='IyBZ3'></ul><sub id='IyBZ3'></sub></form><legend id='IyBZ3'></legend><bdo id='IyBZ3'><pre id='IyBZ3'><center id='IyBZ3'></center></pre></bdo></b><th id='IyBZ3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IyBZ3'><tfoot id='IyBZ3'></tfoot><dl id='IyBZ3'><fieldset id='IyBZ3'></fieldset></dl></div>
                            <tfoot id='IyBZ3'></tfoot>
                            主站蜘蛛池模板: 91精品国产乱码久久久久久 | 玩丰满女领导对白露脸hd | 欧美理论片在线观看 | 国产精品亚洲一区 | 欧美一区二区三区在线播放 | 精品二区视频 | 亚洲精品无| 国产日本精品视频 | 亚洲福利视频一区二区 | 欧美成人第一页 | 中文字幕在线观看一区二区 | www.亚洲视频 | 成人av免费在线观看 | 羞羞视频在线观免费观看 | 美女久久久久久久 | 久久久精| 成人亚洲精品久久久久软件 | 欧美日韩亚洲成人 | 国产激情视频在线观看 | 欧美日韩精品免费观看 | 欧美日韩在线视频观看 | 国产精品久久久久久福利一牛影视 | 成人免费影院 | www.激情.com| 国产剧情一区二区三区 | 国产一级在线视频 | 日韩成人免费在线视频 | 在线播放中文字幕 | 国产精品三级 | 国产黑丝av | 午夜精品一区二区三区在线观看 | 久久综合亚洲 | 亚洲一区二区免费 | 国产精品成人一区二区三区夜夜夜 | 久久久国产一区二区三区四区小说 | 久草视频2 | 精品久久久久久久人人人人传媒 | 欧美福利视频一区 | 亚洲午夜三级 | 一区观看 | 国产精品福利视频 |