如何使用 Azure ACS 开发用户验证的 REST 服务
我正在开发一个使用 MS Azure 访问控制服务进行身份验证的 REST 服务。如果这些示例有任何指示的话,那么以这种方式保护 REST 服务的典型方法是为受保护的服务提供全局用户名和密码、私钥或 X.509 证书。但是,我想在移动设备上使用被动用户登录机制,其流程如下所示:
- 未经身份验证的用户尝试从应用程序访问受保护的服务
- 移动应用程序重定向到浏览器应用程序(或嵌入式浏览器)
- 用户从 ACS 登录页面选择用于登录的身份提供商(facebook、google 等)
- 用户输入身份提供商的凭据
- 浏览器重定向回应用程序 应用
- 程序以某种方式获取 SWT 令牌以与后续 REST 请求一起使用。
我陷入了第 5 步——获取 SWT 令牌,而我发现的现有示例似乎无法解决这种情况。此外,我实际上正在尝试使用 WPF 中的桌面客户端构建概念验证,这可能会使事情变得复杂。任何人都可以建议使用每用户身份验证与每服务身份验证的具体教程或路径吗?谢谢。
编辑: 当我深入研究这个问题时,我意识到下面发布的示例(以及大多数其他示例)都是基于 OAuth WRAP,该示例已被弃用,取而代之的是 OAuth 2.0。谁能建议一个更新的参考资料?谷歌搜索出现了http://blogs.msdn.com/b/adventurousidentity/archive/2011/09/18/acs-v2-oauth-2-0-delegation-support-explained.aspx 和http://connect.microsoft.com/site1168/Downloads/DownloadDetails.aspx?DownloadID=32719 但它们并不是最直观的。
I'm developing a REST service that uses MS Azure Access Control Service for authentication. If the examples are any indication, the typical way to secure a REST service this way would be to provide a global username and pw, private key, or X.509 cert for the protected service. However, I want to use the passive user login mechanism on a mobile device with a flow more like the following:
- Unauthenticated user attempts to access protected service from app
- Mobile app redirects to browser app (or embedded browser)
- User selects identity provider to use for login (facebook, google, etc.) from ACS login page
- User enters credentials for identity provider
- Browser redirects back to app
- App somehow gets the SWT token to use with subsequent REST requests.
I'm stuck at about step 5--getting the SWT token, and the existing examples I've found don't seem to address this scenario. In addition, I'm actually trying to build a proof of concept with a desktop client in WPF, which may complicate things. Can anyone suggest a specific tutorial or a path to pursue that uses the per-user authentication vs. per-service? Thanks.
EDIT:
As I'm digging into this deeper, I've realized that the examples posted below (and most others) are based on OAuth WRAP, which has been deprecated in favor of OAuth 2.0. Can anyone suggest a more up to date reference? Googling has turned up http://blogs.msdn.com/b/adventurousidentity/archive/2011/09/18/acs-v2-oauth-2-0-delegation-support-explained.aspx and http://connect.microsoft.com/site1168/Downloads/DownloadDetails.aspx?DownloadID=32719 but they're not the most intuitive.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该查看 ACS Windows Phone 示例:
http://msdn.microsoft.com /en-us/library/gg983271.aspx
这里您将使用 WPF,而不是 Silverlight。大多数代码应该是可重用的。请注意,由于您使用的是 WPF,因此您需要注册自己的脚本对象,例如:
更新:
上面的示例使用 OAuth Wrap 来联系安全服务。如果您想使用 OAuth2,您应该更改“授权”标头设置的方式:
OAuth WRAP 案例:
OAuth2 案例:
您可以使用“简单服务”示例作为在 REST 服务中实现令牌验证的指南:
http://msdn.microsoft.com/en-us/library/gg185911.aspx
但是,如果您想实现更完整的示例,您可以查看 CustomerInformationService 在CTP 版本 1.4:
https://connect.microsoft.com/site1168/Downloads/DownloadDetails.aspx?DownloadID=35417
You should look into the ACS Windows Phone sample:
http://msdn.microsoft.com/en-us/library/gg983271.aspx
Here instead of using Silverlight you will be using WPF. Most of the code should be re-usable. Note that since you are using WPF you will need to register your own object for scripting e.g:
Update:
The sample above uses OAuth Wrap to contact the secured service. If you would like to use OAuth2 you should change the way the "Authorization" header set:
OAuth WRAP case:
OAuth2 case:
You can use the "Simple Service" sample as a guide to implement your token validation in your REST service:
http://msdn.microsoft.com/en-us/library/gg185911.aspx
Yet if you would like to implement a more complete sample you can look at how CustomerInformationService is protected in the CTP version 1.4:
https://connect.microsoft.com/site1168/Downloads/DownloadDetails.aspx?DownloadID=35417
看看这个:
WPF Application With Live ID、Facebook、Google、Yahoo!、Open ID
http://social.technet.microsoft.com/wiki/contents/articles /4656.aspx
Take a look at this one:
WPF Application With Live ID, Facebook, Google, Yahoo!, Open ID
http://social.technet.microsoft.com/wiki/contents/articles/4656.aspx