Conflict between System.IdentityModel.Tokens and Microsoft.IdentityModel.Tokens

前端 未结 2 1857
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 12:55

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

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.         


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-30 13:28

    May be you are using Jwt version 5.0.0.0 or above. I have faced the same issue before.

    The new version of JWT handler accepts Microsoft.IdentityModel.Tokens namespace.

    var tokenDescriptor = new Microsoft.IdentityModel.Tokens.SecurityTokenDescriptor
                {
                    Subject = claimsIdentity,
                    Audience = allowedAudience,
                    Issuer = issuerName,
                    Expires = DateTime.MaxValue,
                    SigningCredentials = new Microsoft.IdentityModel.Tokens.SigningCredentials(
                        new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(symmetricKey), //symmetric key
                        System.IdentityModel.Tokens.SecurityAlgorithms.HmacSha256Signature,
                        System.IdentityModel.Tokens.SecurityAlgorithms.Sha256Digest)
                };
    
                var tokenHandler = new JwtSecurityTokenHandler();
                var token = tokenHandler.CreateToken(tokenDescriptor);
    

提交回复
热议问题