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

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

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

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

        無法驗(yàn)證 UseJwtBearerAuthentication 中的令牌.授權(quán)被拒

        Cannot validate token in UseJwtBearerAuthentication. Authorization has been denied(無法驗(yàn)證 UseJwtBearerAuthentication 中的令牌.授權(quán)被拒絕)
            1. <small id='E87HV'></small><noframes id='E87HV'>

                <tbody id='E87HV'></tbody>

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

                  <bdo id='E87HV'></bdo><ul id='E87HV'></ul>
                  本文介紹了無法驗(yàn)證 UseJwtBearerAuthentication 中的令牌.授權(quán)被拒絕的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

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

                  使用單個(gè) asp.net(4.6.1) Web 項(xiàng)目,顯然我無法驗(yàn)證在同一服務(wù)器上生成的 jwt 令牌.
                  Startup.cs:

                  Using a single asp.net(4.6.1) web project, apparently I'm unable to validate the jwt token that was generated on the same server.
                  Startup.cs:

                          var secret = Encoding.UTF8.GetBytes("12341234123412341234");
                          var jwtFormatter = new CustomJwtFormat("Any", "local", secret);
                  
                          // This part checks the tokens
                          app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions
                          {
                              AuthenticationType = DefaultAuthenticationTypes.ExternalBearer,
                              AuthenticationMode = AuthenticationMode.Active, // Block requests
                              AllowedAudiences = new []{"Any"},
                              TokenValidationParameters = new TokenValidationParameters
                              {
                                  IssuerSigningKey = new InMemorySymmetricSecurityKey(secret),
                                  ValidAudience = "Any",
                                  ValidIssuer = "local"
                              }
                          });
                          
                          // This part issues tokens
                          app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
                          {
                              AllowInsecureHttp = false,
                              TokenEndpointPath = new PathString("/auth"),
                              AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
                              Provider = new CustomOAuthProvider(),
                              AccessTokenFormat = jwtFormatter,
                              RefreshTokenFormat = jwtFormatter
                              
                          });
                  
                          app.UseWebApi(config);
                  

                  生成令牌的類看起來像

                  public class CustomJwtFormat : ISecureDataFormat<AuthenticationTicket>
                  {
                      private readonly string _allowedAudience;
                      private readonly string _issuer;
                      private readonly byte[] _jwtTokenSignKey;
                  
                      public CustomJwtFormat(string allowedAudience, string issuer, byte[] jwtTokenSignKey)
                      {
                          _allowedAudience = allowedAudience;
                          _issuer = issuer;
                          _jwtTokenSignKey = jwtTokenSignKey;
                      }
                  
                      public string Protect(AuthenticationTicket data)
                      {
                          if (data == null) throw new ArgumentNullException(nameof(data));
                          
                          var signingCredentials = new SigningCredentials
                          (
                              new InMemorySymmetricSecurityKey(_jwtTokenSignKey),
                              "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256",
                              "http://www.w3.org/2001/04/xmlenc#sha256"
                          );
                  
                          return new JwtSecurityTokenHandler().WriteToken(new JwtSecurityToken(
                              _issuer, 
                              _allowedAudience, 
                              data.Identity.Claims, 
                              DateTime.UtcNow, DateTime.UtcNow.AddMinutes(10), 
                              signingCredentials
                          ));
                          
                      }
                  
                      public AuthenticationTicket Unprotect(string protectedText)
                      {
                          throw new NotImplementedException();
                      }
                  }
                  

                  我從 /auth 收到的令牌看起來有效,并在 jwt.io 上通過調(diào)試器(沒有標(biāo)記 base64 進(jìn)行簽名)

                  The tokens I receive from /auth look valid and pass the debugger on jwt.io (without marking base64 for signature)

                  但是 UseJwtBearerAuthentication 拒絕驗(yàn)證令牌.

                  However UseJwtBearerAuthentication refuses to validate the token.

                  這可能是什么原因?

                  此外,我嘗試在沒有 [Authorize] 的情況下手動(dòng)驗(yàn)證控制器中的相同令牌,它會(huì)完美驗(yàn)證:

                  Moreover, I've tried manually validating the same token in a controller without [Authorize] and it would perfectly validate:

                  <代碼>變種T =" eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjEiLCJpc3MiOiJsb2NhbCIsImF1ZCI6IkFueSIsImV4cCI6MTQ3MjkxMDcwMSwibmJmIjoxNDcyOTEwMTAxfQ.ipSrRSGmje7wfzERsd-M1IDFJnN99AIC4Hs7YX4FIeI英寸;var TokenHandler = new JwtSecurityTokenHandler();;var key = Encoding.UTF8.GetBytes("12341234123412341234");SecurityToken 驗(yàn)證令牌;TokenValidationParameters paras = new TokenValidationParameters(){IssuerSigningKey = new InMemorySymmetricSecurityKey(key),ValidAudience =任何",ValidIssuer =本地"};TokenHandler.ValidateToken(t, paras, out validToken);

                  歐文 3.0.1.0System.IdentityModel.Tokens.Jwt 4.0.3.308261200

                  Owin 3.0.1.0 System.IdentityModel.Tokens.Jwt 4.0.3.308261200

                  推薦答案

                  問題不在于令牌驗(yàn)證,而在于聲明沒有傳遞給 Thread.CurrentPrincipal[Authorize] 屬性正在讀取.

                  The problem wasn't in the token validation, but rather the that the claims were not passed on to Thread.CurrentPrincipal that the [Authorize] attribute was reading from.

                  在 webapi 配置中:

                  config.SuppressDefaultHostAuthentication();
                  config.Filters.Add(new HostAuthenticationFilter(DefaultAuthenticationTypes.ExternalBearer));
                  

                  在啟動(dòng)配置中:

                  app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
                  {
                      AuthenticationType = DefaultAuthenticationTypes.ExternalBearer,
                      ...
                  });
                  
                  app.UseJwtBearerAuthentication1(new JwtBearerAuthenticationOptions()
                  {
                      AuthenticationType = DefaultAuthenticationTypes.ExternalBearer,
                      ..
                  });
                  

                  在 OAuthAuthorizationServerProvider 的 GrantResourceOwnerCredentials 中:
                  使用相同的身份驗(yàn)證類型,您可以從 context.Options

                  var identity = new ClaimsIdentity(youClaimsList, context.Options.AuthenticationType);
                  context.Validated(identity);
                  

                  并確保所有 四個(gè) 位置都具有與 AuthenticationType 相同的字符串.如果 HostAuthenticationFilter 將具有不同的 authenticationType 作為輸入,它不會(huì)將聲明從 owin 傳遞到 webapi.

                  And ensure all four places have the same string as AuthenticationType. If the HostAuthenticationFilter will have a different authenticationType as input, it will not pass on the claims from owin to webapi.

                  這篇關(guān)于無法驗(yàn)證 UseJwtBearerAuthentication 中的令牌.授權(quán)被拒絕的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(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)

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

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

                      1. <tfoot id='Q3yGk'></tfoot>
                          <legend id='Q3yGk'><style id='Q3yGk'><dir id='Q3yGk'><q id='Q3yGk'></q></dir></style></legend>
                            <tbody id='Q3yGk'></tbody>
                            <bdo id='Q3yGk'></bdo><ul id='Q3yGk'></ul>
                          • 主站蜘蛛池模板: 精品免费国产一区二区三区四区介绍 | 欧美视频成人 | 欧美a级成人淫片免费看 | 久久99精品国产自在现线小黄鸭 | 免费看淫片 | 福利影院在线看 | 亚洲最大福利网 | 激情一区二区三区 | 国产成人精品一区二区三区四区 | 精品一区二区三区电影 | www,黄色,com | 国产精品 亚洲一区 | 久久亚洲国产精品 | 亚洲成人午夜电影 | 人人性人人性碰国产 | 欧美日韩亚洲视频 | 一区二区视频 | 亚洲精品乱码久久久久久按摩观 | 二区在线观看 | 亚洲综合五月天婷婷 | 麻豆精品国产91久久久久久 | 日韩精品一区二区三区视频播放 | 91av在线不卡 | 久久一区二区精品 | 99热这里都是精品 | 日韩福利 | 久久精品一区二区三区四区 | 天天综合久久 | 日韩不卡在线观看 | 国产a级毛片| 亚洲一区二区国产 | 国产一区二区三区www | 极品一区| 91九色网站 | 亚洲视频一区 | 亚洲一区二区三区视频在线 | 毛片一区二区 | 久久久久久亚洲精品 | 精品久久国产 | 亚洲一二三区在线观看 | 成年人网站在线观看视频 |