2013-08-30 84 views
0

我下載了該項目的源代碼http://code.msdn.microsoft.com/windowsazure/MVC4-Web-API-With-SWT-232d69da#content,因爲我想了解ACS身份驗證以及如何將其應用到我的MVC Web API中。Azure ACS證書混淆

的代碼有這樣的:

// 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"; 

什麼用戶名和密碼是請求我使用?它是否要我創建「服務標識」並使用「密碼」選項?

回答

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); 
+0

謝謝所以答案就是「服務標識」。對於對稱密鑰,它說:「請注意,如果您在步驟2中爲對稱密鑰配置了服務身份憑證,則需要按照[從AC請求令牌]中的簽名令牌請求部分中列出的步驟進行操作(http:// msdn.microsoft.com/en-us/library/ee706734.aspx)主題。「但是,鏈接不起作用,你可以看到如果你自己嘗試。你可能會建議如何改變代碼以使用對稱密鑰而不是密碼? – user1477388

+1

我爲我的答案添加了對稱密鑰請求的示例。 – Jez