处理2种授权

时间:2018-10-25 14:06:57

标签: authentication asp.net-core

我是.Net Core的新手,从未遇到授权。我在身份验证处理方面遇到了1个挑战。

我有一个带有Cookie身份验证的.net核心应用。该应用程序执行简单的库存操作。

在startup.cs中,我对授权有这样的定义

    public void ConfigureServices(IServiceCollection services)
    {
            services.AddAuthentication(options =>
            {
                options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultSignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            });}

还使用UserManager<TUser>类登录用户等。

这里是HomeController的定义:

[Authorize]
public class HomeController : Controller
{
   // Some staff here
}

现在,我有1个ApiController应该使用基本授权:

[ApiController]
[Route("InventoryApi")]
public class ApiController: Controller
{
   // Add some inventory staff
}

如果我使用[Authorize]属性请求,则不会由api控制器处理。

例如,我是否需要创建自己的属性来处理基本身份验证,还是可以在Startup.cs中处理此类身份验证而无需取消主要授权?

0 个答案:

没有答案
相关问题