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

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

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

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

      在 C# 中正確使用 JwtTokens

      Correct use of JwtTokens in C#(在 C# 中正確使用 JwtTokens)
      <i id='4nxLn'><tr id='4nxLn'><dt id='4nxLn'><q id='4nxLn'><span id='4nxLn'><b id='4nxLn'><form id='4nxLn'><ins id='4nxLn'></ins><ul id='4nxLn'></ul><sub id='4nxLn'></sub></form><legend id='4nxLn'></legend><bdo id='4nxLn'><pre id='4nxLn'><center id='4nxLn'></center></pre></bdo></b><th id='4nxLn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4nxLn'><tfoot id='4nxLn'></tfoot><dl id='4nxLn'><fieldset id='4nxLn'></fieldset></dl></div>
      <tfoot id='4nxLn'></tfoot>
          <tbody id='4nxLn'></tbody>

        <legend id='4nxLn'><style id='4nxLn'><dir id='4nxLn'><q id='4nxLn'></q></dir></style></legend>

          • <small id='4nxLn'></small><noframes id='4nxLn'>

              <bdo id='4nxLn'></bdo><ul id='4nxLn'></ul>
                本文介紹了在 C# 中正確使用 JwtTokens的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

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

                我正在使用 JwtTokens 并且無(wú)法使它們正常工作.我正在使用 http://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/ 為它.我知道代碼是一團(tuán)糟,但只是為了展示我正在嘗試做的事情.問(wèn)題是我希望 JwtTokenHandler 因?yàn)樯芷诙鵁o(wú)法通過(guò)驗(yàn)證.

                I'm playing a with JwtTokens and can't make them work properly. I'm using http://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/ for it. I know the code is a mess but is just to show what I'm trying to do. The problem is that I want the JwtTokenHandler to fail the validation because of the lifetime.

                var key = "5A0AB091-3F84-4EC4-B227-0834FCD8B1B4";
                var domain = "http://localhost";
                var allowedAudience = "http://localhost";
                var signatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256";
                var digestAlgorithm = "http://www.w3.org/2001/04/xmlenc#sha256";
                var issuer = "self";
                var securityKey = System.Text.Encoding.Unicode.GetBytes(key);
                var inMemorySymmetricSecurityKey = new InMemorySymmetricSecurityKey(securityKey);
                
                var now = DateTime.UtcNow;
                var expiry = now.AddSeconds(1);
                var tokenHandler = new JwtSecurityTokenHandler();
                var claimsList = new List<Claim>()
                {
                    new Claim(ClaimTypes.Name, "user"),
                    new Claim(ClaimTypes.Webpage, allowedAudience),
                    new Claim(ClaimTypes.Uri, domain),                
                    new Claim(ClaimTypes.Expiration,expiry.Ticks.ToString())
                };
                var roles = new List<string>() { "admin" };
                claimsList.AddRange(roles.Select(role => new Claim(ClaimTypes.Role, role)));
                
                var identity = new GenericIdentity("user");
                
                var tokenDescriptor = new SecurityTokenDescriptor
                {
                    Subject = new ClaimsIdentity(identity, claimsList),
                    TokenIssuerName = issuer,
                    AppliesToAddress = allowedAudience,
                    Lifetime = new Lifetime(now, expiry),
                    SigningCredentials = new SigningCredentials(inMemorySymmetricSecurityKey, signatureAlgorithm, digestAlgorithm),
                };
                
                var token = tokenHandler.WriteToken(tokenHandler.CreateToken(tokenDescriptor));
                
                var validationParameters = new TokenValidationParameters()
                {
                    ValidIssuer = issuer,
                    ValidAudience = allowedAudience,
                    IssuerSigningToken = new BinarySecretSecurityToken(securityKey)
                };
                
                Thread.Sleep(2000);
                try
                {
                    SecurityToken securityToken;
                    tokenHandler.ValidateToken(token, validationParameters, out securityToken);
                    Console.WriteLine("OK");
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error {0}", e.Message);
                }
                

                由于我等待 2 秒,這不是假設(shè)會(huì)失敗嗎?如果我將 ValidationTokenParameter 的頒發(fā)者更改為x",它會(huì)失敗...

                Isn't this suppose to fail since I'm waiting 2 seconds? It fails if I change the issuer of the ValidationTokenParameter to "x"...

                推薦答案

                發(fā)現(xiàn)問(wèn)題.驗(yàn)證參數(shù)的默認(rèn)時(shí)鐘偏差為 5 分鐘

                Found the issue. The validation parameters have a default clock skew of 5 minutes

                /// <summary>
                /// Default for the clock skew.
                /// 
                /// </summary>
                /// 
                /// <remarks>
                /// 300 seconds (5 minutes).
                /// </remarks>
                public static readonly TimeSpan DefaultClockSkew;
                

                將其設(shè)置為 0 使這項(xiàng)工作.仍然不明白為什么傾斜是 5 分鐘,如果我將到期時(shí)間設(shè)置在某個(gè)時(shí)間點(diǎn)!!!

                Setting that to 0 make this work. Still don't understand why the skew is 5 minutes, if I set the expiry at some point!!!

                這篇關(guān)于在 C# 中正確使用 JwtTokens的文章就介紹到這了,希望我們推薦的答案對(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?(車牌檢測(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)

                    <tfoot id='oAecP'></tfoot>
                      <tbody id='oAecP'></tbody>
                    <legend id='oAecP'><style id='oAecP'><dir id='oAecP'><q id='oAecP'></q></dir></style></legend>
                    • <bdo id='oAecP'></bdo><ul id='oAecP'></ul>

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

                        • <i id='oAecP'><tr id='oAecP'><dt id='oAecP'><q id='oAecP'><span id='oAecP'><b id='oAecP'><form id='oAecP'><ins id='oAecP'></ins><ul id='oAecP'></ul><sub id='oAecP'></sub></form><legend id='oAecP'></legend><bdo id='oAecP'><pre id='oAecP'><center id='oAecP'></center></pre></bdo></b><th id='oAecP'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='oAecP'><tfoot id='oAecP'></tfoot><dl id='oAecP'><fieldset id='oAecP'></fieldset></dl></div>
                        • 主站蜘蛛池模板: 免费在线看黄视频 | 日韩一区二区三区视频 | 国产成人精品久久久 | 久久97精品 | 国产精品欧美一区二区三区 | 在线免费观看黄色 | 一级免费在线视频 | 欧美久久久久久 | 久久日韩粉嫩一区二区三区 | 亚洲综合在线一区二区 | 国产黄色小视频在线观看 | 日韩av在线一区 | 国产成人精品一区二区三 | 国产精品久久久久久久久久东京 | 福利视频网 | 国产一级影片 | 久久久久国产一级毛片高清网站 | 欧美日韩精品一区 | 精品一区在线 | av久久| www精品美女久久久tv | 久久99国产精品久久99果冻传媒 | 免费观看羞羞视频网站 | 黄色免费av | www.亚洲视频.com | 日韩中文字幕一区二区 | 伊人天堂网 | 国产一级在线 | 国产97视频在线观看 | 免费一区 | 国产精品美女久久久久久免费 | 国产激情视频 | 欧美日韩a | h视频在线观看免费 | 国产免费一区二区三区最新6 | 天堂亚洲 | 成人不卡 | 久久一区二区三区电影 | 成人精品啪啪欧美成 | 91麻豆精品国产91久久久久久久久 | 久久tv在线观看 |