如何使用 Azure ACS 开发用户验证的 REST 服务

发布于 2024-12-08 09:39:05 字数 1112 浏览 2 评论 0原文

我正在开发一个使用 MS Azure 访问控制服务进行身份验证的 REST 服务。如果这些示例有任何指示的话,那么以这种方式保护 REST 服务的典型方法是为受保护的服务提供全局用户名和密码、私钥或 X.509 证书。但是,我想在移动设备上使用被动用户登录机制,其流程如下所示:

  1. 未经身份验证的用户尝试从应用程序访问受保护的服务
  2. 移动应用程序重定向到浏览器应用程序(或嵌入式浏览器)
  3. 用户从 ACS 登录页面选择用于登录的身份提供商(facebook、google 等)
  4. 用户输入身份提供商的凭据
  5. 浏览器重定向回应用程序 应用
  6. 程序以某种方式获取 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.aspxhttp://connect.microsoft.com/site116​​8/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:

  1. Unauthenticated user attempts to access protected service from app
  2. Mobile app redirects to browser app (or embedded browser)
  3. User selects identity provider to use for login (facebook, google, etc.) from ACS login page
  4. User enters credentials for identity provider
  5. Browser redirects back to app
  6. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感受沵的脚步 2024-12-15 09:39:05

您应该查看 ACS Windows Phone 示例:

http://msdn.microsoft.com /en-us/library/gg983271.aspx

这里您将使用 WPF,而不是 Silverlight。大多数代码应该是可重用的。请注意,由于您使用的是 WPF,因此您需要注册自己的脚本对象,例如:

[ComVisibleAttribute(true)]
public class NotifyHandler
{
    public void Notify(string notifyString)
    {
        // Here I have the token.
    }
}

this.webBrowser1.ObjectForScripting = new NotifyHandler();

更新:

上面的示例使用 OAuth Wrap 来联系安全服务。如果您想使用 OAuth2,您应该更改“授权”标头设置的方式:

OAuth WRAP 案例:

 WebClient client = new WebClient();
 client.Headers["Authorization"] = "OAuth " + _rstrStore.SecurityToken;

OAuth2 案例:

 WebClient client = new WebClient();
 client.Headers["Authorization"] = string.Format("OAuth2 access_token=\"{0}\"", token);

您可以使用“简单服务”示例作为在 REST 服务中实现令牌验证的指南:

http://msdn.microsoft.com/en-us/library/gg185911.aspx

但是,如果您想实现更完整的示例,您可以查看 CustomerInformationService 在CTP 版本 1.4:

https://connect.microsoft.com/site116​​8/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:

[ComVisibleAttribute(true)]
public class NotifyHandler
{
    public void Notify(string notifyString)
    {
        // Here I have the token.
    }
}

this.webBrowser1.ObjectForScripting = new NotifyHandler();

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:

 WebClient client = new WebClient();
 client.Headers["Authorization"] = "OAuth " + _rstrStore.SecurityToken;

OAuth2 case:

 WebClient client = new WebClient();
 client.Headers["Authorization"] = string.Format("OAuth2 access_token=\"{0}\"", token);

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

開玄 2024-12-15 09:39:05

看看这个:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文