相关疑难解决方法(0)

ASP.NET Core 2.0身份验证中间件

随着Core 1.1遵循@ blowdart的建议并实施了自定义中间件:

/sf/answers/2202565921/

它的工作方式如下:

  1. 中间件运行了.从请求标头中选取一个令牌.
  2. 验证了令牌,如果有效,则构建一个包含多个声明的身份(ClaimsIdentity),然后通过HttpContext.User.AddIdentity()添加;
  3. 在使用services.AddAuthorization的ConfigureServices中,我添加了一个策略来要求中间件提供的声明.
  4. 在控制器/操作中,我将使用[授权(角色="中间件添加的某些角色")]

这有点适用于2.0,除了如果令牌无效(上面的步骤2)并且从未添加声明我得到"没有指定authenticationScheme,并且没有找到DefaultChallengeScheme."

所以现在我正在读取2.0中的auth更改:

https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x

在ASP.NET Core 2.0中我做同样的事情的正确途径是什么?我没有看到做真正的自定义身份验证的示例.

c# authentication asp.net-core asp.net-core-2.0

84
推荐指数
2
解决办法
5万
查看次数

ASP.NET Core 2.0 Preview 1:如何使用自定义登录路径设置Cookie身份验证

在ASP.NET Core 2.0中,.UseAuthentication()中间件有一个重大更改,不再允许此处提到旧语法工作.

新版本似乎在addAuthentication中处理配置,但我无法在任何地方找到有关如何更改指定自定义登录和注销URL的旧代码的任何详细信息.

        services.AddAuthentication(o =>
        {
            // Where can I specify this?????
            var opt = new CookieAuthenticationOptions()
            {
                LoginPath = "/api/login",
                LogoutPath = "/api/logout",
            };

           o.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
           o.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        });
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激...

c# authentication cookies asp.net-core

11
推荐指数
2
解决办法
1万
查看次数