Security icon indicating copy to clipboard operation
Security copied to clipboard

IDX10211: Unable to validate issuer. The 'issuer' parameter is null or whitespace

Open afoliaco opened this issue 11 years ago • 4 comments

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;
} 

afoliaco avatar Oct 22 '15 00:10 afoliaco

Can you check if issuer is null or ""? Would hard coding options.TokenValidationParameters.ValidIssuer resolve your issue?

muratg avatar Oct 22 '15 21:10 muratg

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

afoliaco avatar Oct 22 '15 21:10 afoliaco

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.

kevinchalet avatar Oct 23 '15 18:10 kevinchalet

@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.

Tratcher avatar Oct 29 '15 23:10 Tratcher