我观看并浏览了很多有关保护 ASP.NET Web API 的页面 - 包括:http://weblogs.asp.net/jgalloway/archive/2012/03/23/asp-net-web-api-screencast-series-part-6-authorization.aspx http://weblogs.asp.net/jgalloway/archive/2012/03/23/asp-net-web-api-screencast-series-part-6-authorization.aspx and http://weblogs.asp.net/jgalloway/archive/2012/05/04/asp-net-mvc-authentication-customizing-authentication-and-authorization-the-right-way.aspx http://weblogs.asp.net/jgalloway/archive/2012/05/04/asp-net-mvc-authentication-customizing-authentication-and-authorization-the-right-way.aspx- 但是,我还没有看到 KISS 类型的例子。
例如,如果我有一个 Web api,它返回汽车列表 - 并且我正在与想要查询(获取)和插入(发布)汽车列表的第三方(即不是我自己的网站或服务器/域)合作将汽车按类型存储到我的数据库中,如何对它们进行身份验证(通过 https)?
他们是否只是添加(到他们的 JSON GET/Post 中)类似的东西:
[
{"username":"someusername","password":"somepassword",
{
"carTypeID":12345,
"carTypeID":9876}
"carTypeID":2468}
}
}
]
然后我可以获取用户名和密码,并检查 .net 中的会员数据库,然后“IfUserAuthenticated”继续处理 JSON 的其余部分?
或者有更好的方法吗?我听说过向标题等添加详细信息 - 但我不确定这是否有原因,或者是否过于复杂。我还听说过设置发送回第 3 方的令牌 - 如果这是最好的方法,我应该给他们什么指示来构建他们将使用我的 API 的应用程序?
感谢您的任何建议/指示,
Mark
如果您想保持简单,可以使用基本身份验证。通过 SSL 是相当安全的。它只涉及向请求添加标头:
Authorization: Basic <username:password encoded as base64>
你可以找到一种方法来实现它here http://sixgun.wordpress.com/2012/02/29/asp-net-web-api-basic-authentication/.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)