IDX10211: Unable to validate issuer. The 'issuer' parameter is null or whitespace
When doing this code in the start up file
app.UseJwtBearerAuthentication(options =>
{
options.AutomaticAuthentication = true;
options.TokenValidationParameters.IssuerSigningKey = key;
options.TokenValidationParameters.ValidAudience = audience;
options.TokenValidationParameters.ValidIssuer = issuer;
options.TokenValidationParameters.ValidateAudience = false;
options.Events = new JwtBearerEvents
{
OnAuthenticationFailed = context =>
{
context.HandleResponse();
return Task.FromResult(0);
}
};
});
the options are not been honor in the middle ware
Controller Code
JwtSecurityToken securityToken = handler.CreateToken
(
issuer: _bearerOptions.TokenValidationParameters.ValidIssuer,
audience: _bearerOptions.TokenValidationParameters.ValidAudience,
signingCredentials: _signingCredentials,
subject: new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.Email) }),
expires: DateTime.Today.AddDays(1)
);
string token = handler.WriteToken(securityToken);
Injection in the controller
private readonly JwtBearerOptions _bearerOptions;
private readonly SigningCredentials _signingCredentials;
private readonly IUserRepository _Repo;
public TokenController(IOptions<JwtBearerOptions> bearerOptions, SigningCredentials signingCredentials, IUserRepository repo)
{
_bearerOptions = bearerOptions.Value;
_signingCredentials = signingCredentials;
_Repo = repo;
}
Can you check if issuer is null or ""? Would hard coding options.TokenValidationParameters.ValidIssuer resolve your issue?
No they are not empty values, they are constants on my startup class, I debug the application and in the controller when is doing the signature the jtwbaeroptios does not have those values, looks like the middle ware is not honoring the setup in startup
You can't simply use app.UseJwtBearerAuthentication(options => { ... }) and expect the JWT options to be retrievable using IOptions<JwtBearerOptions> since app.UseJwtBearerAuthentication no longer relies on IOptions (nor injects it) in beta8.
@PinpointTownes is right, IOptions is no longer populated in services for this. You're getting a new options instance with a new TVP without any config. You probably need to configure these separately.