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

      <tfoot id='X99QU'></tfoot>

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

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

        System.IdentityModel.Tokens 和 Microsoft.IdentityModel.Token

        时间:2023-06-01

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

          1. <legend id='l1WiI'><style id='l1WiI'><dir id='l1WiI'><q id='l1WiI'></q></dir></style></legend>

            <tfoot id='l1WiI'></tfoot>
              <bdo id='l1WiI'></bdo><ul id='l1WiI'></ul>
                  <tbody id='l1WiI'></tbody>
                  <i id='l1WiI'><tr id='l1WiI'><dt id='l1WiI'><q id='l1WiI'><span id='l1WiI'><b id='l1WiI'><form id='l1WiI'><ins id='l1WiI'></ins><ul id='l1WiI'></ul><sub id='l1WiI'></sub></form><legend id='l1WiI'></legend><bdo id='l1WiI'><pre id='l1WiI'><center id='l1WiI'></center></pre></bdo></b><th id='l1WiI'></th></span></q></dt></tr></i><div id='l1WiI'><tfoot id='l1WiI'></tfoot><dl id='l1WiI'><fieldset id='l1WiI'></fieldset></dl></div>
                1. 本文介绍了System.IdentityModel.Tokens 和 Microsoft.IdentityModel.Tokens 之间的冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在使用 System.IdentityModel.Tokens 时发生冲突:

                  I have a conflict when using System.IdentityModel.Tokens :

                  using System;
                  using System.Configuration;
                  using System.Data;
                  using System.Data.SqlClient;
                  using System.IdentityModel.Tokens;
                  using System.IdentityModel.Tokens.Jwt;
                  using System.Text;
                  
                  public voidGenereToken()
                  {
                      const string sec = "401b09eab3c013d4ca54922bb802bec8fd5318192b0a75f201d8b3727429090fb337591abd3e44453b954555b7a0812e1081c39b740293f765eae731f5a65ed1";
                      var now = DateTime.UtcNow;
                      var securityKey = new InMemorySymmetricSecurityKey(Encoding.Default.GetBytes(sec));
                      var signingCredentials = new SigningCredentials(securityKey,
                              SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest);
                  
                      var header = new JwtHeader(signingCredentials);
                  
                      var payload = new JwtPayload
                      {
                          {"iss", "a5fgde64-e84d-485a-be51-56e293d09a69"},
                          {"scope", "https://example.com/ws"},
                          {"aud", "https://example.com/oauth2/v1"},
                          {"iat", now},
                      };
                  
                      var secToken = new JwtSecurityToken(header, payload);
                  
                      var handler = new JwtSecurityTokenHandler();
                      var tokenString = handler.WriteToken(secToken);
                      Console.writeLine(tokenString)
                  }
                  

                  创建标头时出现以下错误 (var header = new JwtHeader(signingCredentials);):

                  I get following error when I create header (var header = new JwtHeader(signingCredentials);) :

                  参数类型System.IdentityModel.Tokens.SigningCredentials"不是可分配给参数类型'Microsoft.IdentityModel.Tokens.SigningCredentials'

                  Argument type 'System.IdentityModel.Tokens.SigningCredentials' is not assignable to parameter type 'Microsoft.IdentityModel.Tokens.SigningCredentials'

                  我不明白,因为我的所有类型都引用 System.IdentityModel.Tokens.并且在文档中 JwtHeader Constructor 需要 System.IdentityModel.Tokens.SigningCredentials

                  I don't understand because all my type refers to System.IdentityModel.Tokens. and in documentation JwtHeader Constructor need System.IdentityModel.Tokens.SigningCredentials

                  不知道怎么了……

                  推荐答案

                  System.IdentityModel.Tokens.Jwt 版本 5.0.0.0 依赖于 Microsoft.IdentityModel.Tokens.

                  System.IdentityModel.Tokens.Jwt version 5.0.0.0 depends on Microsoft.IdentityModel.Tokens.

                  您需要在 Microsoft.IdentityModel.Tokens 命名空间中使用 SigningCredentials.

                  You need to use SigningCredentials in the Microsoft.IdentityModel.Tokens namespace.

                  例子:

                  using System;
                  using System.IdentityModel.Tokens;
                  using System.IdentityModel.Tokens.Jwt;
                  using System.Text;
                  
                  public void voidGenereToken() {
                      const string sec = "401b09eab3c013d4ca54922bb802bec8fd5318192b0a75f201d8b3727429090fb337591abd3e44453b954555b7a0812e1081c39b740293f765eae731f5a65ed1";
                      var now = DateTime.UtcNow;
                      var securityKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.Default.GetBytes(sec));
                      var signingCredentials = new Microsoft.IdentityModel.Tokens.SigningCredentials(
                          securityKey,
                          SecurityAlgorithms.HmacSha256Signature);
                  
                      var header = new JwtHeader(signingCredentials);
                  
                      var payload = new JwtPayload
                      {
                              {"iss", "a5fgde64-e84d-485a-be51-56e293d09a69"},
                              {"scope", "https://example.com/ws"},
                              {"aud", "https://example.com/oauth2/v1"},
                              {"iat", now},
                          };
                  
                      var secToken = new JwtSecurityToken(header, payload);
                  
                      var handler = new JwtSecurityTokenHandler();
                      var tokenString = handler.WriteToken(secToken);
                      Console.WriteLine(tokenString);
                  }
                  

                  这篇关于System.IdentityModel.Tokens 和 Microsoft.IdentityModel.Tokens 之间的冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 Owin 从 JWT 获取自定义声明 下一篇:JWT 和 Web API (JwtAuthForWebAPI?) - 寻找示例

                  相关文章

                  最新文章

                  <i id='2OyoE'><tr id='2OyoE'><dt id='2OyoE'><q id='2OyoE'><span id='2OyoE'><b id='2OyoE'><form id='2OyoE'><ins id='2OyoE'></ins><ul id='2OyoE'></ul><sub id='2OyoE'></sub></form><legend id='2OyoE'></legend><bdo id='2OyoE'><pre id='2OyoE'><center id='2OyoE'></center></pre></bdo></b><th id='2OyoE'></th></span></q></dt></tr></i><div id='2OyoE'><tfoot id='2OyoE'></tfoot><dl id='2OyoE'><fieldset id='2OyoE'></fieldset></dl></div>
                    • <bdo id='2OyoE'></bdo><ul id='2OyoE'></ul>

                  1. <tfoot id='2OyoE'></tfoot>
                    1. <small id='2OyoE'></small><noframes id='2OyoE'>

                    2. <legend id='2OyoE'><style id='2OyoE'><dir id='2OyoE'><q id='2OyoE'></q></dir></style></legend>