I cannot tell you what your session is deleting, but you can try this (works for me)
use the Javascript SDK to display login buttons that open a popup to connect to FB
add the js SDK to your page as follows:
<div id="fb-root"></div> <script> window.fbAsyncInit = function() { FB.init({appId: '<?php echo FB_API_ID; ?>', status: true, cookie: true, xfbml: true}); FB.Event.subscribe('auth.login', function() { new Request({ 'method': 'get', 'url': '<?php echo $this->Html->url(array('controller'=>'users','action'=>'login_fb'));?>', 'onSuccess': function(result){ window.location.reload(); } }).send(); }); }; (function() { var e = document.createElement('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; document.getElementById('fb-root').appendChild(e); }()); </script>
In the auth.login
event auth.login
I use the ajax call / users / login_fb, which will use the SDK to check Facebook in a facebook session:
App::import('Lib', 'facebook_sdk/facebook'); // "MyAuth" is a custom Auth Component that extends the normal Auth component $this->MyAuth->facebook = new Facebook(array( 'appId' => FB_API_ID, 'secret' => FB_SECRET, 'cookie' => true, )); $me = null; $session = $this->MyAuth->facebook->getSession(); if ($session) { try { $uid = $this->MyAuth->facebook->getUser(); $me = $this->MyAuth->facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); } } if ($me) { $this->Session->write('FbLogin.session',$session); $this->Session->write('FbLogin.user',$me); $UserModel = ClassRegistry::init('User'); $user = $UserModel->findByUid($me['id']); if(!$user){ $UserModel->create(); $user_data = array( 'username'=>$me['username'], 'name'=>$me['first_name'], 'lastname'=>$me['last_name'], 'email'=>$me['email'], 'group_id'=>GROUP_VISITOR, 'uid'=>$me['id'] ); $UserModel->save($user_data); $user['User']['id'] = $UserModel->id; } $this->Session->write($this->MyAuth->sessionKey, $user['User']); $this->MyAuth->_loggedIn = true; } }
The basic idea is that in js, I call ajax to check the fb session and then save it in the cake session and js will refresh the page
source share