相关疑难解决方法(0)

ASP.Net Core 2.0混合身份验证JWT和Windows身份验证不接受凭据

我在asp.net core 2.0中创建了API,我正在使用混合模式身份验证.对于一些控制器JWT和一些使用Windows身份验证.

我对使用JWT授权的控制器没有任何问题.但对于我想要使用Windows身份验证的控制器,我无限期地提示使用chrome的用户名和密码对话框.

这里是我的示例控制器代码,我想使用Windows身份验证而不是JWT.

[Route("api/[controller]")]
[Authorize(AuthenticationSchemes = "Windows")]
public class TestController : Controller
{
    [HttpPost("processUpload")]
    public async Task<IActionResult> ProcessUploadAsync(UploadFileModel uploadFileModel)
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

我的配置服务代码

public void ConfigureServices(IServiceCollection services)
{
     services.AddAuthentication(options =>
     {
        options.DefaultAuthenticateScheme = IISDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
     })
     .AddJwtBearer("Bearer", options =>
     {
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateAudience = false,       
            ValidateIssuer = false,  
            ValidateIssuerSigningKey = true,
            IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("blahblahKey")),
            ValidateLifetime = true, //validate the expiration and not before values in the token
            ClockSkew = TimeSpan.FromMinutes(5) //5 minute …
Run Code Online (Sandbox Code Playgroud)

c# authorization authorize-attribute asp.net-core-2.0

16
推荐指数
1
解决办法
6625
查看次数