Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Fix session init issue #79 #112

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Facebook/FacebookInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace FOS\FacebookBundle\Facebook;

interface FacebookInterface
{
function getUser();
function getAppId();
function setAppId($appId);
function getAppSecret();
function setAppSecret($secret);
function getApiSecret();
function setApiSecret($secret);
function setFileUploadSupport($supported);
function getFileUploadSupport();
function getAccessToken();
function setAccessToken($token);
function getSignedRequest();
function getLoginUrl($params = array());
function getLogoutUrl($params = array());
function getLoginStatusUrl($params = array());
function api();
function destroySession();
}
4 changes: 2 additions & 2 deletions Facebook/FacebookSessionPersistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class FacebookSessionPersistence extends \BaseFacebook
class FacebookSessionPersistence extends \BaseFacebook implements FacebookInterface
{
const PREFIX = '_fos_facebook_';

Expand Down Expand Up @@ -63,7 +63,7 @@ protected function getPersistentData($key, $default = false)
self::errorLog('Unsupported key passed to getPersistentData.');
return $default;
}

$sessionVariableName = $this->constructSessionVariableName($key);
if ($this->session->has($sessionVariableName)) {
return $this->session->get($sessionVariableName);
Expand Down
160 changes: 160 additions & 0 deletions Facebook/FacebookSessionPersistenceProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php

namespace FOS\FacebookBundle\Facebook;

use Symfony\Component\HttpFoundation\Session;

/**
* @author Leszek Prabucki <leszek.prabucki@gmail.com>
*/
class FacebookSessionPersistenceProxy implements FacebookInterface
{
/**
* @var Symfony\Component\HttpFoundation\Session
*/
protected $session = null;

/**
* @var string
*/
protected $prefix = '';

/**
* @var array
*/
protected $config = array();

/**
* @var FOS\FacebookBundle\Facebook\FacebookSessionPersistence
*/
private $sessionPersistence = null;

/**
* @param array $config the application configuration.
* @param Symfony\Component\HttpFoundation\Session
* @param string
*/
public function __construct($config, Session $session, $prefix = null)
{
$this->config = $config;
$this->session = $session;
$this->prefix = $prefix;
}

public function getUser()
{
return $this->getSessionPersistence()->getUser();
}

public function getAppId()
{
return $this->getSessionPersistence()->getAppId();
}

public function setAppId($appId)
{
return $this->getSessionPersistence()->setAppId($appId);
}

public function getAppSecret()
{
return $this->getSessionPersistence()->getAppSecret();
}

public function setAppSecret($secret)
{
return $this->getSessionPersistence()->setAppSecret($secret);
}

public function getApiSecret()
{
return $this->getSessionPersistence()->getApiSecret();
}

public function setApiSecret($secret)
{
return $this->getSessionPersistence()->setApiSecret($secret);
}

public function setFileUploadSupport($supported)
{
return $this->getSessionPersistence()->setFileUploadSupport($supported);
}

public function getFileUploadSupport()
{
return $this->getSessionPersistence()->getFileUploadSupport();
}

public function useFileUploadSupport()
{
return $this->getSessionPersistence()->useFileUploadSupport();
}

public function getAccessToken()
{
return $this->getSessionPersistence()->getAccessToken();
}

public function setAccessToken($token)
{
return $this->getSessionPersistence()->setAccessToken($token);
}

public function getSignedRequest()
{
return $this->getSessionPersistence()->getSignedRequest();
}

public function getLoginUrl($params = array())
{
return $this->getSessionPersistence()->getLoginUrl($params);
}

public function getLogoutUrl($params = array())
{
return $this->getSessionPersistence()->getLogoutUrl($params);
}

public function getLoginStatusUrl($params = array())
{
return $this->getSessionPersistence()->getLoginStatusUrl($params);
}

public function api()
{
$args = func_get_args();

return call_user_func_array(array($this->getSessionPersistence(), 'api'), $args);
}

public function destroySession()
{
return $this->getSessionPersistence()->destroySession();
}

public function setSessionPersistence(FacebookInterface $sessionPersistence)
{
$this->sessionPersistence = $sessionPersistence;
}

/**
* @return FOS\FacebookBundle\Facebook\FacebookSessionPersistence
*/
protected function getSessionPersistence()
{
if (!$this->sessionPersistence) {
$this->sessionPersistence = $this->createSessionPersistence();
}

return $this->sessionPersistence;
}

/**
* @return FOS\FacebookBundle\Facebook\FacebookSessionPersistence
*/
protected function createSessionPersistence()
{
return new FacebookSessionPersistence($this->config, $this->session, $this->prefix);
}
}
2 changes: 1 addition & 1 deletion Resources/config/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<service id="fos_facebook.auth" class="FOS\FacebookBundle\Security\Authentication\Provider\FacebookProvider" public="false">
<argument type="service" id="fos_facebook.api" />
</service>

<service id="fos_facebook.logout_handler" class="FOS\FacebookBundle\Security\Logout\FacebookHandler" public="false">
<argument type="service" id="fos_facebook.api" />
</service>
Expand Down
5 changes: 3 additions & 2 deletions Security/Authentication/Provider/FacebookProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;

use FOS\FacebookBundle\Security\Authentication\Token\FacebookUserToken;
use FOS\FacebookBundle\Facebook\FacebookInterface;

class FacebookProvider implements AuthenticationProviderInterface
{
/**
* @var \BaseFacebook
* @var FOS\FacebookBundle\Facebook\FacebookInterface
*/
protected $facebook;
protected $userProvider;
protected $userChecker;
protected $createIfNotExists;

public function __construct(\BaseFacebook $facebook, UserProviderInterface $userProvider = null, UserCheckerInterface $userChecker = null, $createIfNotExists = false)
public function __construct(FacebookInterface $facebook, UserProviderInterface $userProvider = null, UserCheckerInterface $userChecker = null, $createIfNotExists = false)
{
if (null !== $userProvider && null === $userChecker) {
throw new \InvalidArgumentException('$userChecker cannot be null, if $userProvider is not null.');
Expand Down
6 changes: 4 additions & 2 deletions Security/EntryPoint/FacebookAuthenticationEntryPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;

use FOS\FacebookBundle\Facebook\FacebookInterface;

/**
* FacebookAuthenticationEntryPoint starts an authentication via Facebook.
*
Expand All @@ -32,10 +34,10 @@ class FacebookAuthenticationEntryPoint implements AuthenticationEntryPointInterf
/**
* Constructor
*
* @param BaseFacebook $facebook
* @param FOS\FacebookBundle\Facebook\FacebookInterface $facebook
* @param array $options
*/
public function __construct(\BaseFacebook $facebook, array $options = array(), array $permissions = array())
public function __construct(FacebookInterface $facebook, array $options = array(), array $permissions = array())
{
$this->facebook = $facebook;
$this->permissions = $permissions;
Expand Down
4 changes: 3 additions & 1 deletion Security/Logout/FacebookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;

use FOS\FacebookBundle\Facebook\FacebookInterface;

/**
* Listener for the logout action
*
Expand All @@ -25,7 +27,7 @@ class FacebookHandler implements LogoutHandlerInterface
{
private $facebook;

public function __construct(\BaseFacebook $facebook)
public function __construct(FacebookInterface $facebook)
{
$this->facebook = $facebook;
}
Expand Down
4 changes: 3 additions & 1 deletion Templating/Helper/FacebookHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Symfony\Component\Templating\Helper\Helper;
use Symfony\Component\Templating\EngineInterface;

use FOS\FacebookBundle\Facebook\FacebookInterface;

class FacebookHelper extends Helper
{
protected $templating;
Expand All @@ -22,7 +24,7 @@ class FacebookHelper extends Helper
protected $scope;
protected $facebook;

public function __construct(EngineInterface $templating, \BaseFacebook $facebook, $logging = true, $culture = 'en_US', array $scope = array())
public function __construct(EngineInterface $templating, FacebookInterface $facebook, $logging = true, $culture = 'en_US', array $scope = array())
{
$this->templating = $templating;
$this->logging = $logging;
Expand Down
Loading