我一直在按照以下步骤使 Windows 8 Store 应用程序获取 ACS 令牌,如下所述: WebAuthenticationBroker 是否在 Windows 8 Metro App post Release Candidate 中工作
但是,我的 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 应用程序时,我可以从 Internet 访问该应用程序主持人。
这个想法是让 Windows 8 商店应用程序通过 Facebook 登录从 ACS 获取令牌。当我启动 win8 客户端时,应用程序显示一个 Facebook 登录页面。我使用我的凭据成功登录。但是,当我查看 webauthenticationresult.responsedata 属性时,我只看到回调 uri。此外,我没有在我的防火墙中看到任何 ACS 尝试将某些内容发布到我的回调 uri 的日志。