Web API - 身份验证建议

时间:2013-11-07 20:22:13

标签: c# asp.net asp.net-web-api

背景: - 使用VS 2012在ASP.Net 4.0 / C#的Web窗体应用程序中使用Web API - 有些页面将使用带有JQuery的Web API调用,其他页面将使用Web表单回发

需要执行以下操作:

  • 让用户使用用户名/密码登录
  • 使用SQL Server DB验证凭据
  • 将令牌生成回客户端
  • 让客户端使用令牌对未来的API请求进行身份验证
  • 维护用户会话,无论是使用Web API还是Web表单回发

我不清楚的是:

  • 如何使用Web API生成令牌
  • 如何在每次调用时验证令牌服务器端(在SQL Server中存储?)
  • 如何使用混合的Web API / Web表单回发维护用户会话

1 个答案:

答案 0 :(得分:1)

我使用了来自http://thinktecture.github.io/的Thinktecture IdentityModel。 它是一个很棒的库,包括令牌生成。

这是我在实施时提到的原始文章

http://ben.onfabrik.com/posts/dog-fooding-our-api-authentication

如果您有兴趣,我也会在我的博客上写一些文章

http://sunilrav.com/post/Enable-Basic-Authetication-in-Aspnet-webapi-using-ThinktectureIdentityModel

http://sunilrav.com/post/Enable-CORS-in-Aspnet-webapi-using-ThinktectureIdentityModel

这篇文章在我做研究时帮助了我

REST service authentication