Exceptions caught:
'Microsoft.IdentityModel.Tokens.SecurityTokenInvalidAlgorithmException: IDX10696: The algorithm 'RS256' is not in the user-defined accepted list of algorithms.
at Microsoft.IdentityModel.Tokens.Validators.ValidateAlgorithm(String algorithm, SecurityKey securityKey, SecurityToken securityToken, TokenValidationParameters validationParameters)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateSignature(Byte[] encodedBytes, Byte[] signature, SecurityKey key, String algorithm, SecurityToken securityToken, TokenValidationParameters validationParameters)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateSignature(String token, TokenValidationParameters validationParameters)
This is the error that I am getting while authenticating dotnet core application.
Here the signing credentials that I am using is
var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
Also while validating, in ConfigureServices method My code is like this.
services.AddAuthentication(x =>
{
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
//options.Authority = authUrl;
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = authUrl,
ValidAudience = authUrl,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)),
ValidAlgorithms = new[] { SecurityAlgorithms.HmacSha256 }
};
});
Could some one help on this?
Also I have seen the list of supported algorithms, I have tested few from this also. But the issue is still there. Few posts I have seen in Github that not to use Symmetric keys for this.
If not using Symmetric key based algorithms, is it possible to suggest one best method of generating jwt for production grade applications?