开发者

Facebook oauth opens in the new window instead of popup

I am using C# to get FB tokens. So once I redirect user to this link:

https://graph.facebook.com/oauth/autho开发者_运维技巧rize?........

it opens a new page instead a popup (FB javascript SDK, which I am trying to avoid).

There is 'display=popup' in that query, which doesnt work. I also tried to 'window.open(...),

but some browsers block such popups with blockers...

Is there a way to open an original Facebook popup, and then go back to C# code behind to do all the magic..?


Have a separate page for managing Facebook login. Open the same from a main page with something like this

window.open(""../Helper/FBLoginMgr.aspx?login=fb", "_blank","height=900,width=800,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0");

in FBLoginMgr.aspx in Page load event you could do this:

        if (Request["login"] != null)
        {
            //First time
            url = "https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope=offline_access,read_stream,user_activities";
            Response.Redirect(string.Format(url, app_id, redirect_url));
        }

        if (Request["code"] != null)
        {
            //Second time
            url = "https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}";

..

The initial querystring parameter login=fb is just to indicate to the Login mgr that it has just been launched and need to initiate Facebook authorization. The second Request["code"] is a parameter posted by Facebook upon authorization by the user.

Once the access token is retrieved, set a hidden variable to indicate that the job is done. Then in the aspx page you could have something like this:


    $(document).ready(function () {
        alert("Time to say good bye");
        if (document.getElementById('<%=amidone.ClientID %>').value == "yes") {
            window.parent.opener.doneWithLogin();//Indicate to the parent page
            window.close();
        }
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜