Facebook身份验证响应参数错误 - >无限请求循环

时间:2012-01-08 16:35:35

标签: asp.net facebook authentication sdk

我是facebook API的新手,经过一些工作我遇到了一个问题。 首先,我使用the facebook SDK与facebook API进行通信。

在我的应用设置中,我选择OAuth对话框的响应应该是查询字符串而不是URI片段。

enter image description here

在我的服务器上,我收到了以下代码:

void Page_Load()
{
    string url = Request.Url.AbsoluteUri;
    Facebook.FacebookOAuthResult result = null;        
    if (!Facebook.FacebookOAuthResult.TryParse(url, out result))
    {
        string redirectUrl = PivotServer.Helpers.GetFacebookOAuthUrl();
        Response.Redirect(redirectUrl);
    }
}

那就是我的助手方法:

    public static string GetFacebookOAuthUrl()
    {
        FacebookOAuthClient oauth = new FacebookOAuthClient
        {
            AppId = "149637255147166",
            AppSecret = "xxx",
            RedirectUri = new Uri("http://mydomain.com/")
        };

        var param = new Dictionary<string, object>
        {
            { "response_type", "token" },
            { "display", "popup" }
        };

        Uri url = oauth.GetLoginUrl(param);

        return url.AbsoluteUri;
    }

我在网络服务器(IIS)上运行了我的页面。当我第一次打开页面时,我被要求登录到Facebook,这没关系,但后来我遇到了无限循环,因为Auth Token Parameter(来自facebook)是一个URI片段而不是查询字符串(其中)我想要(见上图))。 响应URI看起来像

http://mydomain.com/#access_token=AAACIGCNwLp4BAMccSoliF5EMGJm0NPldv5GpmBPIm9z7rRuSkiia7BM0uhEn1V88c8uOlWOfGc3C8sFC9tq90Ma0OwIm0tWLNU5BBAZDZD&expires_in=0&base_domain=mydomain.com

而不是

http://mydomain.com/?code=AAACIGCNwLp4BAMccSoliF5EMGJm0NPldv5GpmBPIm9z7rRuSkiia7BM0uhEn1V88c8uOlWOfGc3C8sFC9tq90Ma0OwIm0tWLNU5BBAZDZD&expires_in=0&base_domain=mydomain.com

这是来自OAuth API的错误,还是我在这里做错了什么?

2 个答案:

答案 0 :(得分:1)

这是IE的一个问题。请务必在服务器的每个响应中都有一个p3p标头。

答案 1 :(得分:1)

太容易了:

var param = new Dictionary<string, object>
{
    { "response_type", "code" }, // <--- "code" instead of "token"
    { "display", "popup" }
};