使用属性调用控制器的OAuth安全性?

时间:2012-10-23 21:37:29

标签: asp.net-mvc oauth asp.net-mvc-4 oauth-2.0

无论如何,你可以说在MVC中使用OAuth并使用像验证过程中的属性来启用对控制器的访问。 让我说我有

public class myownController
{ 
  [LoginRequired]
  public ActionResult Index(){
  //this can be accesed only of the user is logged in.
  }
}

1 个答案:

答案 0 :(得分:2)

如果您使用的是ASP.Net MVC 4,则应使用默认的AuthorizeAttribute内置。如果不是,我建议您手动将标准表单身份验证机制与您选择的OAuth提供程序集成。看看ASP.NET MVC Authentication - Customizing Authentication and Authorization The Right Way

由于您使用的是ASP.Net MVC 4,我强烈建议您阅读SimpleMembership, Membership Providers, Universal Providers and the new ASP.NET 4.5 Web Forms and ASP.NET MVC 4 templates。 MVC 4中有重大变化,使整个会员和OAuth变得非常简单。