【问题标题】:Windows Store app with enterpriseAuthentication and Impersonation具有企业身份验证和模拟的 Windows 应用商店应用
【发布时间】:2012-11-19 18:57:00
【问题描述】:

短版:为什么当我模拟 Windows 应用商店应用发出的网络请求时,我得到了具有正确用户名的 WindowsIdentity 对象,但其 IsAuthenticated 属性返回 False?从浏览器(包括 Metro IE10)发出相同的请求会得到 IsAuthenticated==true。

加长版
我正在制作一个内部企业解决方案的原型,它由 WCF 服务和 WinJS 应用程序组成。 WCF 服务基于 webHttpBinding(即简单的 GET/POST 请求)。

需要代表用户发出请求来处理某些操作,因此服务被配置为模拟其调用者。这是示例配置:

<system.serviceModel>
  <bindings>
    <webHttpBinding>
      <binding name="CustomizedWebBinding">
        <security mode="TransportCredentialOnly">
          <transport clientCredentialType="Windows" />
        </security>
      </binding>
    </webHttpBinding>
  </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="Web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
        <serviceBehaviors>
            <behavior name="">
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service name="WcfService">
            <endpoint address="" binding="webHttpBinding" bindingConfiguration="CustomizedWebBinding" contract="IWcfService" behaviorConfiguration="Web">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:8787/" />
                </baseAddresses>
            </host>
        </service>
    </services>
</system.serviceModel>

...和代码:

public class WcfService : IWcfService
{
    [OperationBehavior(Impersonation=ImpersonationOption.Required)]
    public UserInfo GetUserInfo()
    {
        UserInfo ui = new UserInfo();
        WindowsIdentity identity = ServiceSecurityContext.Current.WindowsIdentity;

        ui.UserName = identity.Name;
        ui.IsAuthenticated = identity.IsAuthenticated;
        ui.ImpersonationLevel = identity.ImpersonationLevel.ToString();
        ui.IsAnonymous = identity.IsAnonymous;
        ui.IsGuest = identity.IsGuest;
        ui.IsSystem = identity.IsSystem;
        ui.AuthenticationType = identity.AuthenticationType;

        return ui;
    }
}

因此,此操作只是收集有关调用者的信息并将其发送回 json 字符串。

转移到客户端。为了启用自动身份验证,我在 Windows Store 应用的清单文件中选中了“企业身份验证”、“Internet(客户端)”和“私有网络”。

在 Windows Store 应用程序中,我使用 WinJS.xhr 函数发送请求:

    var options = {
        url: "http://localhost:8787/getuserinfo"
    };

    WinJS.xhr(options).then(function (xhrResponse) {
        var userInfoBlock = document.getElementById("userInfoBlock");
        var data = JSON.parse(xhrResponse.response);

        userInfoBlock.innerHTML += "<ul>"

        for (var p in data) {
            if (data.hasOwnProperty(p)) {
                userInfoBlock.innerHTML += "<li>" + p + ": " + data[p] + "</li>";
            }
        }

        userInfoBlock.innerHTML += "</ul>";
    });

现在,当我执行 Windows Store 应用程序并发送请求时,我得到的响应是:

AuthenticationType: "NTLM"
ImpersonationLevel: "Impersonation"
IsAnonymous: false
IsAuthenticated: false
IsGuest: false
IsSystem: false
UserName: "TESTBOX\dev"

如果我使用浏览器的地址栏发送请求,我会得到相同的响应,唯一的区别是“IsAuthenticated: true”。

我还注意到,如果我禁用“企业身份验证”,它会导致凭据选择器弹出,并且在提供正确的凭据后,我会得到“IsAuthenticated: true”。

我是否遗漏了某些东西或对企业身份验证功能期望过高?

【问题讨论】:

    标签: wcf windows-8 microsoft-metro impersonation windows-store-apps


    【解决方案1】:

    我想我偶然发现了同样的问题 (Calling a WCF service using Windows Auth from a Windows Store App),看起来带有企业身份验证的 Windows 应用商店应用程序会阻止使用模拟调用本地主机上的服务。

    当我在域中的另一台服务器上托管我的服务时,它工作得很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-31
      • 2014-09-14
      • 1970-01-01
      相关资源
      最近更新 更多