Facebook Connect & HTTP Cookies - How Can I Overcome This "Race State"

If you are interested in what the "Race Condition" is, then there is a flaw in the system, whereas it is highly dependent on time. See the wiki here for more information.

Therefore, the condition I am connected with Facebook Connect and the implementation of single sign-on service with the ASP.NET 4.0 web application (forms-based authentication - IIS7).

The process itself (including Logout) works well, but .....

Here's a scenario where it doesn't quite work 100%:

  • The user is registered on Facebook.
  • The user goes to my site.
  • The user is not logged in automatically (should be, though).
  • The user refreshes the page and automatically registers.

When I break the code in step 3 - Facebook cookies do not yet exist (in HttpContext.Current.Request.Cookies).

But when the page reloads (step 4) - there are Facebook Cookies there.

For me, this can be a few things:

I’m not sure that only in the case of Facebook, access to my cookie access application (delay in cross-domain handshakes - xd_receiver.htm) or a problem with cross-domain cookies themselves and the ASP.NET page life cycle has not yet been granted access.

Has anyone else dealt with this problem?

This is not all-all-and-all-all, but it is annoying (and not very different from the user's perspective).

EDIT:

- . Facebook ( Facebook) , 20 , , STILL . , , . , , - 2 , ?

- Facebook cookie ( Facebook), cookie.

( , )

protected void Page_PreRender(object sender, EventArgs eventArgs)
{
   if (FacebookUser.IsAuthenticated) // static property, checks HttpContext.Request.Cookies
   {
        // log them into my website
   }
}

, - HttpContext.Request.Cookies .

.

, , FB.Init . , cookie. , ( Facebook), ( cookie) .

, , ( cookie, ​​ ).

2:

(run on window.load):

FB.init('myapikey', 'xd_receiver.htm', null);

- :

FB.init('myapikey', 'xd_receiver.htm', null);
FB.getLoginStatus(function(response) {
  if (!response.session) {
      return false;
  }
  else {
    window.location.reload();
  }
});

JavaScript - "FB.getLoginStatus" . = (

, JavaScript: http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US

, : http://connect.facebook.net/en_US/all.js

doco API JS.

, , doco "" JS API: http://developers.facebook.com/docs/reference/oldjavascript/

, FB.Connect.get_status() , .

.

"" , - :

window.onload = function() { 
                FB.init('{0}', 'xd_receiver.htm');
                FB.ensureInit(function() {
                   FB.Connect.ifUserConnected(onUserConnected, onUserNotConnected); 
                });
            };

            function onUserConnected() {
                alert('connected!');
                window.location.reload();
            }

            function onUserNotConnected() {
                alert('not connected');
            }

, cookie Forms Authentication, window.location.reload(), . =)

+3
4

" ", . "":

  • Facebook

, Facebook . , , Facebook, , Facebook . .

, , JavaScript . JavaScript SDK Facebook , IFrame ( status: true ) User Facebook ( ). , (.. , ), JavaScript SDK cookie ( , cookie: true).

, , cookie. Cookies JavaScript Events, . - cookie . - Ajax - , .

, , . :)

. , ​​, ( , JavaScript SDK), . SDK JavaScript, , , . , .

+1

( facebook), , :

  • nr 3 ( , Facebook , ). : "" , .

  • 3, THEN (, ), . , .

  • (), / . :

    a) facebook
    b) (cookie )
    c) ( cookie). , 100 , b) ( ).
    d)

0

. ? , , localhost ( /etc/host, localhost peta.edu - , )

. , URL "enter", .

,

Nithin.

0

. , FB.init() (, , , cookie).

, . , . , , , , ...


FB.getLoginStatus(function(response) {
    if (response.session) {
       window.location.href = '/connect/cb/fb'; 
    }
    else{
       FB.login( function(resp){FBResponse(resp);},perms);
    }
});

var FBResponse = function(response,stop){ if (response.session){ window.location.href = '/connect/cb/fb'; } else{ if (stop) return; FB.init({appId:FBappId, status:true, cookie:true, xfbml:true}); FB.getLoginStatus(function(resp){FBResponse(resp,'stop');}); }; }

0

Source: https://habr.com/ru/post/1755246/


All Articles