我下载了这个项目http://code.msdn.microsoft.com/windowsazure/MVC4-Web-API-With-SWT-232d69da#content的源代码,因为我正在尝试理解ACS身份验证以及如何在我的MVC中应用它。
该守则的内容如下:
// 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";它要求我使用什么用户名和密码?它希望我创建一个“服务标识”并使用“密码”选项吗?
发布于 2013-08-30 20:48:05
您需要阅读在: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服务配置服务标识”部分时输入的信息就是这里的内容。
如果您的密码使用对称密钥,则需要客户端以与示例不同的方式从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);https://stackoverflow.com/questions/18539943
复制相似问题