【发布时间】:2014-07-18 11:26:24
【问题描述】:
我继承了现有的应用程序。此应用程序使用 ASP.NET MVC 3。它有一些 API。这些 API 如下所示:
[AcceptVerbs(HttpVerbs.Post)]
[Endpoint]
public ActionResult AuthenticatePlayer(string username, string password)
{
// Ensure that the user entered valid credentials
if (Membership.ValidateUser(username, password) == false)
return Json(new { statusCode = StatusCodes.INVALID_CREDENTIALS, message = "You entered an invalid username or password. Please try again." });
// Get the profile of the person that just logged in.
ProfileCommon userProfile = (ProfileCommon)(ProfileCommon.Create(username));
if (userProfile != null)
{
string name = username;
if (String.IsNullOrEmpty(userProfile.FirstName) == false)
name = userProfile.FirstName;
return Json(new {
statusCode = StatusCodes.SUCCESS,
payload = name,
username = username.ToLower(),
});
}
}
[AcceptVerbs(HttpVerbs.Get)]
[Endpoint]
public ActionResult SomeUserAction(string q)
{
// TODO: Ensure the user is authorized to perform this action via a token
// Do something
return Json(new { original = q, response = DateTime.UtcNow.Millisecond }, JsonRequestBehavior.AllowGet);
}
我试图弄清楚如何将基于令牌的授权模式集成到此过程中。据我了解,如果用户成功登录,基于令牌的系统将向用户返回一个短期令牌和一个刷新令牌。然后,每个方法都可以通过查看令牌来检查用户是否被授权执行操作。我正在尝试了解这是否是 ASP.NET MVC 内置的,或者是否有我可以使用的库。我需要找出完成这项工作的最短方法。
非常感谢!
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-3 asp.net-web-api