You are here

public function FacebookAuthController::getProfile in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/custom/social_auth_facebook/src/Controller/FacebookAuthController.php \Drupal\social_auth_facebook\Controller\FacebookAuthController::getProfile()
  2. 8.2 modules/custom/social_auth_facebook/src/Controller/FacebookAuthController.php \Drupal\social_auth_facebook\Controller\FacebookAuthController::getProfile()
  3. 8.3 modules/custom/social_auth_facebook/src/Controller/FacebookAuthController.php \Drupal\social_auth_facebook\Controller\FacebookAuthController::getProfile()
  4. 8.4 modules/custom/social_auth_facebook/src/Controller/FacebookAuthController.php \Drupal\social_auth_facebook\Controller\FacebookAuthController::getProfile()
  5. 8.5 modules/custom/social_auth_facebook/src/Controller/FacebookAuthController.php \Drupal\social_auth_facebook\Controller\FacebookAuthController::getProfile()
  6. 8.6 modules/custom/social_auth_facebook/src/Controller/FacebookAuthController.php \Drupal\social_auth_facebook\Controller\FacebookAuthController::getProfile()
  7. 8.7 modules/custom/social_auth_facebook/src/Controller/FacebookAuthController.php \Drupal\social_auth_facebook\Controller\FacebookAuthController::getProfile()
  8. 8.8 modules/custom/social_auth_facebook/src/Controller/FacebookAuthController.php \Drupal\social_auth_facebook\Controller\FacebookAuthController::getProfile()

Loads access token, then loads profile.

Parameters

string $type: The type.

Return value

object Returns an object.

2 calls to FacebookAuthController::getProfile()
FacebookAuthController::userLoginCallback in modules/custom/social_auth_facebook/src/Controller/FacebookAuthController.php
Authorizes the user after redirect from Facebook.
FacebookAuthController::userRegisterCallback in modules/custom/social_auth_facebook/src/Controller/FacebookAuthController.php
Registers the new account after redirect from Facebook.

File

modules/custom/social_auth_facebook/src/Controller/FacebookAuthController.php, line 232

Class

FacebookAuthController
Class FacebookAuthController.

Namespace

Drupal\social_auth_facebook\Controller

Code

public function getProfile($type) {

  // Get the OAuth token from Facebook.
  if (!($access_token = $this->authManager
    ->getAccessToken($type))) {
    drupal_set_message($this
      ->t('@network login failed. Token is not valid.', [
      '@network' => $this
        ->t('Facebook'),
    ]), 'error');
    return $this
      ->redirect('user.' . $type);
  }

  // Get user's Facebook profile from Facebook API.
  if (!($profile = $this->authManager
    ->getProfile()) || !$profile
    ->getField('id')) {
    drupal_set_message($this
      ->t('@network login failed, could not load @network profile. Contact the site administrator.', [
      '@network' => $this
        ->t('Facebook'),
    ]), 'error');
    return $this
      ->redirect('user.' . $type);
  }
  $this->accessToken = $access_token;
  return $profile;
}