2012-12-16 140 views
1

我一直在下面的步骤,以使Windows 8商店应用得到一个ACS令牌如下所述: Does the WebAuthenticationBroker work in Windows 8 Metro App post Release Candidate获取ACS令牌

但是,我WebAuthenticationResult对象的ResponseData属性只包含ACS中指定的回调URI,并且不包含令牌信息。在我的代码下面。 Windows 8的客户端的

验证方法

private async void Authenticate() 
    { 
     WebAuthenticationResult webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(
      WebAuthenticationOptions.None, 
      new Uri("https://myACSnamespace.accesscontrol.windows.net:443/v2/wsfederation?wa=wsignin1.0&wtrealm=http://localhost:12714/"), 
      new Uri("http://mypublicIPaddress:80/WebAppMVCAPI/api/federation/end")); 

信赖方应用程序返回URL设置为http://mypublicIPaddress:80/WebAppMVCAPI/api/federation/en

我的web应用控制器编程如下:

public class FederationController : ApiController 
{ 
    protected virtual string ExtractBootstrapToken() 
    { 
     return "Hello World"; 
     //return HttpContext.Current.User.BootstrapToken(); 
    } 

    [HttpGet] 
    public string Get() 
    { 
     return "Hello Get World"; 
    } 

    [HttpPost] 
    public HttpResponseMessage Post() 
    { 
     var response = this.Request.CreateResponse(HttpStatusCode.Redirect); 
     response.Headers.Add("Location", "/WebAppMVCAPI/api/federation/end?acsToken=" + ExtractBootstrapToken()); 
     return response; 
    } 
} 

}

您可以想象,Web应用程序正在IIS服务器上运行并侦听端口80.我的路由器配置为根据需要转发传入请求,并且当我在Visual Studio中启动我的Web应用程序时,我可以访问来自互联网主机的申请。

这个想法是让Windows 8商店应用程序通过Facebook登录从ACS获取令牌。当我启动win8客户端时,应用程序会显示一个Facebook登录页面。我成功登录我的凭证。但是,当我查看webauthenticationresult.responsedata属性时,我只能看到回调函数uri。另外,我没有看到我的防火墙上有任何日志,ACS试图在我的回调函数中发布一些内容。

+0

你如何配置你的ASP.NET Web API项目,使得ExtractBootstrapToken()的作品?我使用VS2012的“身份和访问”向导添加了ACS,然后添加了wif.swt块块包,但不断收到错误。 – markti

回答

1

您的回复第三方应用程序返回的URL应该是

http://mypublicIPaddress:80/WebAppMVCAPI/api/federation 

http://mypublicIPaddress:80/WebAppMVCAPI/api/federation/end 
+0

安德鲁,事实证明你的建议是解决我的问题。感谢您的贡献。 –