Azure ACS凭据混淆

时间:2013-08-30 19:09:27

标签: c# asp.net-mvc-4 azure acs

我下载了此项目http://code.msdn.microsoft.com/windowsazure/MVC4-Web-API-With-SWT-232d69da#content的源代码,因为我正在尝试了解ACS身份验证以及如何将其应用到我的MVC Web API中。

代码有:

// USE CONFIGURATION FILE, WEB.CONFIG, TO MANAGE THIS DATA
static string serviceNamespace = "<YOUR SERVICE NAMESPACE>";
static string acsHostUrl = "accesscontrol.windows.net";
static string realm = "<REALM>";
static string uid = "USERNAME";
static string pwd = "PASSWORD";
static string serviceUrl = "http://localhost:51388/api";
static string serviceAction = @"/values";

请求我使用的USERNAME和PASSWORD是什么?它是否要我创建“服务标识”并使用“密码”选项?

1 个答案:

答案 0 :(得分:2)

您需要阅读在http://blogs.msdn.com/b/alikl/archive/2011/06/05/how-to-request-swt-token-from-acs-and-how-to-validate-it-at-the-rest-wcf-service-hosted-in-windows-azure.aspx找到的相关文章,然后按照配置ACS以发出SWT令牌的步骤进行操作。您在完成“为REST Web服务配置服务标识”部分时输入的信息就在这里。

如果您使用对称密钥作为密码,那么您需要客户端以与示例不同的方式从ACS请求令牌。以下代码是该请求的示例,它来自http://msdn.microsoft.com/en-us/library/hh674475.aspx。请参阅“SWT令牌请求”部分。

WebClient client = new WebClient();
client.BaseAddress = string.Format("https://mysnservice.accesscontrol.windows.net");

NameValueCollection values = new NameValueCollection();
// add the wrap_scope
values.Add("wrap_scope", "http://mysnservice.com/services");
// add the format
values.Add("wrap_assertion_format", "SWT");
// add the SWT
values.Add("wrap_assertion", "Issuer=mysncustomer1&HMACSHA256=b%2f%2bJFwbngGdufECFjQb8qhb9YH0e32Cf9ABMDZFiPPA%3d");
// WebClient takes care of the remaining URL Encoding
byte[] responseBytes = client.UploadValues("WRAPv0.9", "POST", values);

// the raw response from ACS
string response = Encoding.UTF8.GetString(responseBytes);