回退到OAuth来配置ASP.NET Core Web应用程序以使用Windows Auth的步骤如下:
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = "your_issuer",
ValidAudience = "your_audience",
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("your_secret_key"))
};
})
.AddNegotiate();
services.AddAuthorization();
services.AddControllers();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"JwtBearer": {
"Authority": "https://your_authority",
"Audience": "your_audience",
"RequireHttpsMetadata": false
}
}
[ApiController]
[Route("api/[controller]")]
[Authorize]
public class ValuesController : ControllerBase
{
// Controller actions
}
这样配置后,ASP.NET Core Web应用程序将使用OAuth进行身份验证和授权。在请求时,客户端将提供有效的JWT令牌,并通过OAuth验证。如果验证成功,请求将被授权访问受限资源。
推荐的腾讯云相关产品和产品介绍链接地址:
请注意,以上答案仅供参考,具体的配置和推荐产品可能因实际需求和环境而异。
领取专属 10元无门槛券
手把手带您无忧上云