在行为和控制器上使用不同身份验证方案的Authorize属性的行为是什么

问题描述 投票:1回答:1
 [Authorize(AuthenticationSchemes = AuthenticationSchemes.CookieAuthenticationScheme)]
public class MyController : ControllerBase
{


    [HttpPost("ui")]
    [ProducesResponseType(
        (int) HttpStatusCode.Created)]
    public async Task Action1()
    {

    }


    [HttpPost]
    [ProducesResponseType(
        (int)HttpStatusCode.Created)]
    [Authorize(AuthenticationSchemes = AuthenticationSchemes.JwtAuthenticationScheme)]
    public async Task Action2()
    {

    }
}

我有这个控制器,其中Action2具有与Controller中的身份验证方案不同的Authorize属性。但是,当我使用有效的Cookie身份验证但使用无效的身份验证令牌来调用Action2时,那么Action2也会被授权-我期望得到401 / Unauthorized响应。

这是预期的行为吗?

使用Asp.net core 2.2

c# asp.net-core asp.net-core-webapi asp.net-core-2.2
1个回答
0
投票

在ASP.NET Core 2.1之前,所有策略都将单独评估,并且都需要得到满足。

© www.soinside.com 2019 - 2024. All rights reserved.