• <bdo id='jGkTm'></bdo><ul id='jGkTm'></ul>
    1. <small id='jGkTm'></small><noframes id='jGkTm'>

    2. <tfoot id='jGkTm'></tfoot>

      <i id='jGkTm'><tr id='jGkTm'><dt id='jGkTm'><q id='jGkTm'><span id='jGkTm'><b id='jGkTm'><form id='jGkTm'><ins id='jGkTm'></ins><ul id='jGkTm'></ul><sub id='jGkTm'></sub></form><legend id='jGkTm'></legend><bdo id='jGkTm'><pre id='jGkTm'><center id='jGkTm'></center></pre></bdo></b><th id='jGkTm'></th></span></q></dt></tr></i><div id='jGkTm'><tfoot id='jGkTm'></tfoot><dl id='jGkTm'><fieldset id='jGkTm'></fieldset></dl></div>
        <legend id='jGkTm'><style id='jGkTm'><dir id='jGkTm'><q id='jGkTm'></q></dir></style></legend>
      1. OAuth Bearer 令牌身份验证未通过签名验证

        时间:2023-06-01
          <tfoot id='IP0Qd'></tfoot>
          <i id='IP0Qd'><tr id='IP0Qd'><dt id='IP0Qd'><q id='IP0Qd'><span id='IP0Qd'><b id='IP0Qd'><form id='IP0Qd'><ins id='IP0Qd'></ins><ul id='IP0Qd'></ul><sub id='IP0Qd'></sub></form><legend id='IP0Qd'></legend><bdo id='IP0Qd'><pre id='IP0Qd'><center id='IP0Qd'></center></pre></bdo></b><th id='IP0Qd'></th></span></q></dt></tr></i><div id='IP0Qd'><tfoot id='IP0Qd'></tfoot><dl id='IP0Qd'><fieldset id='IP0Qd'></fieldset></dl></div>
          1. <small id='IP0Qd'></small><noframes id='IP0Qd'>

              <bdo id='IP0Qd'></bdo><ul id='IP0Qd'></ul>

                  <legend id='IP0Qd'><style id='IP0Qd'><dir id='IP0Qd'><q id='IP0Qd'></q></dir></style></legend>
                    <tbody id='IP0Qd'></tbody>
                • 本文介绍了OAuth Bearer 令牌身份验证未通过签名验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在令牌使用者上收到以下错误.任何解决此问题的帮助将不胜感激.谢谢.

                  I get the following error on the token consumer. Any help resolving this will be most appreciated. Thanks.

                  IDX10503:签名验证失败.

                  "IDX10503: Signature validation failed.

                  尝试的键:'System.IdentityModel.Tokens.SymmetricSecurityKey'.例外捕获:'System.InvalidOperationException:IDX10636:SignatureProviderFactory.CreateForVerifying 为键返回 null:'System.IdentityModel.Tokens.SymmetricSecurityKey',签名算法:'http://www.w3.org/2001/04/xmldsig-更多#hmac-sha256'.在Microsoft.IdentityModel.Logging.LogHelper.Throw(字符串消息,类型exceptionType,EventLevel logLevel,异常 innerException)在System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateSignature(字节[]encodedBytes、Byte[] 签名、SecurityKey 密钥、字符串算法)在System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateSignature(字符串令牌,令牌验证参数验证参数)'.令牌:'令牌信息在这里'"

                  Keys tried: 'System.IdentityModel.Tokens.SymmetricSecurityKey '. Exceptions caught: 'System.InvalidOperationException: IDX10636: SignatureProviderFactory.CreateForVerifying returned null for key: 'System.IdentityModel.Tokens.SymmetricSecurityKey', signatureAlgorithm: 'http://www.w3.org/2001/04/xmldsig-more#hmac-sha256'. at Microsoft.IdentityModel.Logging.LogHelper.Throw(String message, Type exceptionType, EventLevel logLevel, Exception innerException) at System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateSignature(Byte[] encodedBytes, Byte[] signature, SecurityKey key, String algorithm) at System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateSignature(String token, TokenValidationParameters validationParameters) '. token: 'token info was here'"

                  OAuth 服务器上的令牌生成代码

                   using (var ctlr = new EntityController())
                          {
                              var authRepo = ctlr.GetAuthModelRepository();
                  
                              string clientId;
                  
                              ticket.Properties.Dictionary.TryGetValue(WebConstants.OwinContextProps.OAuthClientIdPropertyKey, out clientId);
                  
                              if (string.IsNullOrWhiteSpace(clientId))
                              {
                                  throw new InvalidOperationException("AuthenticationTicket.Properties does not include audience");
                              }
                  
                  
                              //audience record
                              var client = authRepo.FindAuthClientByOAuthClientID(clientId);
                  
                              var issued = ticket.Properties.IssuedUtc;
                              var expires = ticket.Properties.ExpiresUtc;
                  
                  
                              var hmac = new HMACSHA256(Convert.FromBase64String(client.Secret));
                              var signingCredentials = new SigningCredentials(
                                  new InMemorySymmetricSecurityKey(hmac.Key),
                                  Algorithms.HmacSha256Signature, Algorithms.Sha256Digest);
                  
                              TokenValidationParameters validationParams =
                                  new TokenValidationParameters()
                                  {
                                      ValidAudience = clientId,
                                      ValidIssuer = _issuer,
                                      ValidateLifetime = true,
                                      ValidateAudience = true,
                                      ValidateIssuer = true,
                                      RequireSignedTokens = true,
                                      RequireExpirationTime = true,
                                      ValidateIssuerSigningKey = true,
                                      IssuerSigningToken = new BinarySecretSecurityToken(hmac.Key)
                                  };
                  
                              var jwtHandler = new JwtSecurityTokenHandler();
                  
                              var jwt = new JwtSecurityToken(_issuer, clientId, ticket.Identity.Claims, issued.Value.UtcDateTime, expires.Value.UtcDateTime, signingCredentials);
                  
                              jwtOnTheWire = jwtHandler.WriteToken(jwt);
                  
                              SecurityToken validatedToken = null;
                              jwtHandler.ValidateToken(jwtOnTheWire, validationParams,out validatedToken);
                              if (validatedToken == null)
                                  return "token_validation_failed";
                  
                          }
                          return jwtOnTheWire;
                  

                  Owin Startup.cs 中的令牌消耗验证 ASP.Net 5 vNext 站点

                  public void ConfigureServices(IServiceCollection services)

                  services.ConfigureOAuthBearerAuthentication(config =>
                          {
                  
                              //oauth validation
                              var clientSecret = "not the real secret";
                  
                              var hmac = new HMACSHA256(Convert.FromBase64String(clientSecret));
                              var signingCredentials = new SigningCredentials(
                                  new SymmetricSecurityKey(hmac.Key), Algorithms.HmacSha256Signature, Algorithms.Sha256Digest);
                  
                              config.TokenValidationParameters.ValidAudience = "myappname";
                              config.TokenValidationParameters.ValidIssuer = "mydomain.com";
                              config.TokenValidationParameters.RequireSignedTokens = true;
                              config.TokenValidationParameters.RequireExpirationTime = true;
                              config.TokenValidationParameters.ValidateLifetime = true;
                              config.TokenValidationParameters.ValidateIssuerSigningKey = true;
                              config.TokenValidationParameters.ValidateSignature = true;
                              config.TokenValidationParameters.ValidateAudience = true;
                              config.TokenValidationParameters.IssuerSigningKey = signingCredentials.SigningKey;
                          });
                  

                  public void Configure(IApplicationBuilder 应用程序)

                  app.UseOAuthBearerAuthentication(config =>
                              {
                  
                                  config.AuthenticationScheme = "Bearer";
                                  config.AutomaticAuthentication = true;
                              });
                  

                  推荐答案

                  我能够将自己的签名验证添加到 TokenValidationParameters 然后我将 JWT 的传入 Raw 签名与编译的签名进行比较在此代码中,如果它匹配签名是有效的.

                  I was able to add my own signature validation to the TokenValidationParameters Then I compared the incoming Raw signature of the JWT to the compiled signature in this code and if it matches the signature is valid.

                  为什么使用内置签名验证没有发生这种情况我无法理解,也许这可能是 vNext Identity 令牌框架 beta 6 中的一个错误.

                  Why this didn't happen using the builtin signature validation is beyond me, maybe it's a possible bug in beta 6 of the vNext Identity token framework.

                  public void ConfigureServices(IServiceCollection services)

                  config.TokenValidationParameters.SignatureValidator =
                                  delegate (string token, TokenValidationParameters parameters)
                                  {
                                      var clientSecret = "not the real secret";
                  
                                      var jwt = new JwtSecurityToken(token);
                  
                                      var hmac = new HMACSHA256(Convert.FromBase64String(clientSecret));
                  
                                      var signingCredentials = new SigningCredentials(
                                         new SymmetricSecurityKey(hmac.Key), SecurityAlgorithms.HmacSha256Signature, SecurityAlgorithms.Sha256Digest);
                  
                                      var signKey = signingCredentials.SigningKey as SymmetricSecurityKey;
                  
                  
                                      var encodedData = jwt.EncodedHeader + "." + jwt.EncodedPayload;
                                      var compiledSignature = Encode(encodedData, signKey.Key);
                  
                                      //Validate the incoming jwt signature against the header and payload of the token
                                      if (compiledSignature != jwt.RawSignature)
                                      {
                                          throw new Exception("Token signature validation failed.");
                                      }
                  
                                      return jwt;
                                  };
                  

                  编码辅助方法

                   public string Encode(string input, byte[] key)
                          {
                              HMACSHA256 myhmacsha = new HMACSHA256(key);
                              byte[] byteArray = Encoding.UTF8.GetBytes(input);
                              MemoryStream stream = new MemoryStream(byteArray);
                              byte[] hashValue = myhmacsha.ComputeHash(stream);
                              return Base64UrlEncoder.Encode(hashValue);
                          }
                  

                  这篇关于OAuth Bearer 令牌身份验证未通过签名验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:无法使用 Google Calendar API 加载 System.Threading.Task 下一篇:无法使用 ASP.NET Core 从 JWT 令牌获取声明

                  相关文章

                  最新文章

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