【问题标题】:Getting ACS token on windows store app using callback Uri使用回调 Uri 在 Windows 商店应用程序上获取 ACS 令牌
【发布时间】:2012-12-18 06:55:04
【问题描述】:

我一直按照以下步骤使 Windows 8 应用商店应用获取 ACS 令牌,如下所述: Does the WebAuthenticationBroker work in 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

我在网络应用程序上的控制器编程如下:

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 尝试将某些内容发布到我的回调 uri 的日志。

【问题讨论】:

  • 您是如何配置您的 ASP.NET Web API 项目以使 ExtractBootstrapToken() 工作的?我使用 VS2012 的“身份和访问”向导添加了 ACS,然后添加了 wif.swt nugget 包,但不断出现错误。

标签: wcf windows-store-apps acs


【解决方案1】:

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

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

不是

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

【讨论】:

  • 安德鲁,你的建议确实被证明是我问题的解决方案。感谢您的贡献。
猜你喜欢
  • 2015-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多