首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义身份验证方案授权失败- asp.net-core 3.0

自定义身份验证方案授权失败- asp.net-core 3.0
EN

Stack Overflow用户
提问于 2019-09-10 16:32:35
回答 1查看 388关注 0票数 0

我使用的是:

代码语言:javascript
复制
services.AddAuthentication().AddCookie("custom", options=> {
                options.LoginPath = "/admin/in";
                options.LogoutPath = "/admin/out";
            });

ConfigureServices中注册自定义身份验证方案。

当我尝试在我的控制器中使用这个方案时:

代码语言:javascript
复制
[Authorize(Roles = "admin", AuthenticationSchemes = "custom")]
        public ActionResult Index()
        {
            return View();
        }

它只是将我重定向到登录页面,即使用户已经登录并且是正确的角色。

现在,如果我将AuthenticationScheme更改为:

代码语言:javascript
复制
[Authorize(Roles = "admin", AuthenticationSchemes = "Identity.Application")]
        public ActionResult Index()
        {
            return View();
        }

一切工作正常,用户已获得授权。

在自定义身份验证方案的设置中,我是否遗漏了什么?如何让我的自定义身份验证方案以Identity.Application的方式工作?

谢谢

ps:我使用的是asp.net core 3.0预览版9

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-11 02:02:47

设置options.ForwardAuthenticate = "Identity.Application";似乎解决了这个问题:

代码语言:javascript
复制
public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication().AddCookie("custom", options=> {
                options.LoginPath = "/admin/in";
                options.LogoutPath = "/admin/out";
                options.AccessDeniedPath= "/admin/in";
                options.ForwardAuthenticate = "Identity.Application";
            });

        }

这真的应该被记录下来

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57866897

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档