'Inheritance security rules violated while overriding member exception

I run into an issue that only appears on new server(win 2019), but works quite well on old server (win 2012). The Auth issuer is same. Exception type: Exception Exception message: Found error in ValidateToken. Exception:Microsoft.IdentityModel.Tokens.SecurityTokenSignatureKeyNotFoundException: IDX10501: Signature validation failed. Unable to match key: kid: 'System.String'. Exceptions caught: 'System.Text.StringBuilder'. token: 'System.IdentityModel.Tokens.Jwt.JwtSecurityToken'. at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateSignature(String token, TokenValidationParameters validationParameters) The code is

        var temporarySigningCert = new X509Certificate2(this.issuerKey);
        var temporarySigningSecurityKey = new X509SecurityKey(temporarySigningCert);

        var validationParameters = new TokenValidationParameters
        {
            IssuerSigningKey = temporarySigningSecurityKey,
            ValidateAudience = false,
            IssuerSigningKeyResolver = (string token, Microsoft.IdentityModel.Tokens.SecurityToken securityToken, string kid,
                TokenValidationParameters validParameters) => new List<X509SecurityKey> { new X509SecurityKey(temporarySigningCert) }
        };
        Microsoft.IdentityModel.Tokens.SecurityToken tempToken;
        var tokenHandler = new JwtSecurityTokenHandler();
        tokenHandler.ValidateToken(this.AccessToken, validationParameters, out tempToken);

The last line of code throws exception. However, there is no issue on old server. I don't know what I missed in new server.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source