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

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

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

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

      .NetCore JwtBearerAuthentication 不拒絕過期令牌

      .NetCore JwtBearerAuthentication not rejecting expired tokens(.NetCore JwtBearerAuthentication 不拒絕過期令牌)

        1. <tfoot id='mgUjd'></tfoot>

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

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

                <legend id='mgUjd'><style id='mgUjd'><dir id='mgUjd'><q id='mgUjd'></q></dir></style></legend>
                  <tbody id='mgUjd'></tbody>

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

                問題描述

                限時送ChatGPT賬號..

                我正在生成用于我的 WebApi 項目的 JWT.我將令牌設置為在一分鐘內過期,以便我可以測試它在過期日期之后提交時是否拒絕令牌.

                I am generating JWT's to use with my WebApi project. I'm set the token to expire in one minute so that I can test if it rejects the token when submitted after the expiration date.

                創建令牌控制器

                public async Task<IActionResult> CreateToken([FromBody] CredentialModel model)
                {
                    var user = await _unitOfWork.UserManager.FindByNameAsync(model.UserName);
                
                    if (user == null) return BadRequest();
                    if (Hasher.VerifyHashedPassword(user, user.PasswordHash, model.Password) !=
                        PasswordVerificationResult.Success) return BadRequest();
                
                    var userClaims = await UserManager.GetClaimsAsync(user);
                
                    var claims = new[]
                    {
                        new Claim(JwtRegisteredClaimNames.Sub, user.UserName),
                        new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                        new Claim(JwtRegisteredClaimNames.Iat, DateTime.UtcNow.ToString()),
                        new Claim(JwtRegisteredClaimNames.GivenName, user.FirstName), 
                        new Claim(JwtRegisteredClaimNames.FamilyName, user.LastName),
                        new Claim(JwtRegisteredClaimNames.Email, user.Email)
                    }
                    .Union(userClaims);
                
                    var cert = new Certificate(Configuration["Tokens:Certificate"]);
                    var token = new JwtSecurityToken(
                        issuer: Configuration["Tokens:Issuer"],
                        audience: Configuration["Tokens:Audience"],
                        claims: claims,
                        expires: DateTime.UtcNow.AddMinutes(1),
                        signingCredentials: cert.Signature
                    );
                
                    return Ok(new
                    {
                        token = new JwtSecurityTokenHandler().WriteToken(token),
                        expiration = token.ValidTo
                    });
                }
                

                令牌認證 - 啟動類

                app.UseJwtBearerAuthentication(new JwtBearerOptions()
                {
                    AutomaticAuthenticate = true,
                    AutomaticChallenge = true,
                    TokenValidationParameters = new TokenValidationParameters()
                    {
                        ValidIssuer = Configuration["Tokens:Issuer"],
                        ValidAudience = Configuration["Tokens:Audience"],
                        ValidateIssuerSigningKey = true,
                        IssuerSigningKey = new Certificate(Configuration["Tokens:Certificate"]).SecurityKey,
                        ValidateLifetime = true
                    },
                });
                

                雖然我設置了 validateLifetime = true,但兩分鐘后令牌不會被拒絕.它將繼續接受令牌.是否有我不知道的最短到期時間或我的設置有誤?

                Although I am setting validateLifetime = true the tokes are not rejected two minutes later. It will keep accepting the token. Is there a minimum expiration time that I am not aware of or is my setup wrong?

                推薦答案

                我偶然發現了答案 這里如果有人感興趣的話.ClockSkew 的默認值為 5 分鐘.

                I stumbled over the answer here if anyone is interested. Default value for ClockSkew is 5 minutes.

                app.UseJwtBearerAuthentication(new JwtBearerOptions()
                {
                    AutomaticAuthenticate = true,
                    AutomaticChallenge = true,
                    TokenValidationParameters = new TokenValidationParameters()
                    {
                        ValidIssuer = Configuration["Tokens:Issuer"],
                        ValidAudience = Configuration["Tokens:Audience"],
                        ValidateIssuerSigningKey = true,
                        IssuerSigningKey = new Certificate(certPath: Configuration["Tokens:Certificate"], isValid: false).SecurityKey,
                        ValidateLifetime = true,
                        ValidateIssuer = true,
                        ValidateAudience = true,
                        ClockSkew = TimeSpan.Zero
                    },
                });
                

                這篇關于.NetCore JwtBearerAuthentication 不拒絕過期令牌的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)

                <small id='9AJxk'></small><noframes id='9AJxk'>

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

                      <bdo id='9AJxk'></bdo><ul id='9AJxk'></ul>
                        <tbody id='9AJxk'></tbody>

                        <legend id='9AJxk'><style id='9AJxk'><dir id='9AJxk'><q id='9AJxk'></q></dir></style></legend>

                      • <tfoot id='9AJxk'></tfoot>

                        • 主站蜘蛛池模板: 密色视频 | 欧美日韩中文在线 | 久久国产一区二区 | 夜夜爽99久久国产综合精品女不卡 | 成人av鲁丝片一区二区小说 | 日韩av美女电影 | 亚洲视频免费在线播放 | 欧美一区二区在线观看 | 国产第一页在线播放 | 亚洲国产一区二区在线 | 欧美性猛交一区二区三区精品 | 波多野结衣精品在线 | 久久久久久成人 | 一级网站 | 日韩欧美国产一区二区三区 | 99精品视频一区二区三区 | 欧美国产一区二区三区 | 韩日视频在线观看 | 国产精品a久久久久 | 中文字幕精品一区二区三区在线 | 日日摸夜夜爽人人添av | 天天操天天干天天曰 | 亚洲手机视频在线 | 中国美女撒尿txxxxx视频 | a级毛片毛片免费观看久潮喷 | 99亚洲精品 | 一区二区高清 | 久久精品国产99国产精品亚洲 | 人成久久 | 激情伊人网 | 国产精品日韩欧美一区二区三区 | 国产精品视频免费观看 | 欧美一区二区三区在线观看 | 亚洲视频一区二区三区 | www.国产一区| 亚洲五码在线 | 成人网av| 欧美视频1 | av国产精品毛片一区二区小说 | 精品九九九 | 国产偷久久一级精品60部 |