简体   繁体   English

在ASP.NET MVC 5中使用自定义角色提供程序进行Oauth

[英]Oauth with Custom Role Provider in asp.net mvc 5

I am using Thinktecture Identity Server V3 (Oauth) for authentication with custom user store and I want to use role based authorization. 我正在使用Thinktecture Identity Server V3(Oauth)进行自定义用户存储的身份验证,并且我想使用基于角色的授权。

I am trying to use custom role provider to check for the roles. 我正在尝试使用自定义角色提供程序来检查角色。 username attribute is null for IsInRole method. IsInRole方法的username属性为null。 How can I add user data to current context? 如何将用户数据添加到当前上下文?

Is it good idea to use RoleProvider in this case or add the roles as Claims? 在这种情况下使用RoleProvider或将角色添加为Claims是个好主意吗? If I add them to Claims how can I use [Authorize] attribute? 如果将它们添加到Claims中,如何使用[Authorize]属性? Do I need to write a custom Authorize attribute? 我是否需要编写自定义的Authorize属性?

The AuthorizeAttribute does work for authorization based on the role claim, but it sounds like your claims aren't being stored properly. AuthorizeAttribute确实可以根据角色声明进行授权,但是听起来您的声明未正确存储。

If this is the case, see this Form Post client (AccountController) or this OWIN/Katana client (Startup class) for good examples. 如果是这种情况,请参见此Form Post客户端 (AccountController)或此OWIN / Katana客户端 (启动类)以获取良好示例。

Also, roles should be considered and handled as a claim. 另外,应考虑角色并作为要求来处理。

Thinktecture also have their own authorization manager package if you are interested. 如果您有兴趣,Thinktecture也有自己的授权管理器软件包。 See Dominick Baier's blog post about this for more details. 有关更多详细信息,请参见Dominick Baier的博客文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM