You are here

public function SimpleFbConnectFbManager::startFbSession in Simple FB Connect 8.2

Starts FacebookSession after FB has returned the user back to our site.

Saves the user access token to Drupal session. This function must only be called from route simple_fb_connect.return_from_fb because login helper will use the URL parameters set by Facebook to start Facebook session.

Parameters

\Facebook\FacebookRedirectLoginHelper $login_helper: FacebookRedirectLoginHelper object.

Return value

bool True if we have a valid FB Session False otherwise

File

src/SimpleFbConnectFbManager.php, line 142
Contains \Drupal\simple_fb_connect\SimpleFbConnectFbManager.

Class

SimpleFbConnectFbManager
Contains all Simple FB Connect logic that is related to Facebook interaction.

Namespace

Drupal\simple_fb_connect

Code

public function startFbSession(FacebookRedirectLoginHelper $login_helper) {
  try {
    $fb_session = $login_helper
      ->getSessionFromRedirect();
    if ($fb_session) {
      $this->session
        ->set('simple_fb_connect_user_token', $fb_session
        ->getToken());
      return TRUE;
    }
    else {

      // If the user cancels the dialog or return URL is invalid,
      // Facebook will not throw an exception but will return NULL.
      $this->loggerFactory
        ->get('simple_fb_connect')
        ->error('Could not start Facebook session. User cancelled the dialog in Facebook or return URL was not valid.');
      return FALSE;
    }
  } catch (FacebookRequestException $ex) {
    $this->loggerFactory
      ->get('simple_fb_connect')
      ->error('Could not start Facebook session. FacebookRequestException: @message', array(
      '@message' => json_encode($ex
        ->getResponse()),
    ));
  } catch (\Exception $ex) {
    $this->loggerFactory
      ->get('simple_fb_connect')
      ->error('Could not start Facebook session. Exception: @message', array(
      '@message' => $ex
        ->getMessage(),
    ));
  }
  return FALSE;
}