【问题标题】:Azure ACS Credential ConfusionAzure ACS 凭据混淆
【发布时间】:2013-08-30 19:09:26
【问题描述】:

我下载了这个项目的源代码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";

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

【问题讨论】:

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


    【解决方案1】:

    您需要阅读相关文章: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);
    

    【讨论】:

    • 谢谢,所以答案是“服务标识”。对于对称密钥,它说:“请注意,如果您在第 2 步中为对称密钥配置了服务身份凭证,则需要按照 Requesting a Token from AC 主题的签名令牌请求部分中概述的步骤进行操作。”但是,该链接不起作用,您可以自己尝试一下。您能否建议使用对称密钥而不是密码应该如何更改代码?
    • 我在答案中添加了一个对称密钥请求的示例。
    猜你喜欢
    • 2013-06-28
    • 2021-09-08
    • 1970-01-01
    • 2017-11-25
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 2016-04-13
    • 1970-01-01
    相关资源
    最近更新 更多