You are here

public function LinkedInAuthController::callback in Social Auth LinkedIn 8.2

Same name and namespace in other branches
  1. 8 src/Controller/LinkedinAuthController.php \Drupal\social_auth_linkedin\Controller\LinkedinAuthController::callback()
  2. 3.x src/Controller/LinkedInAuthController.php \Drupal\social_auth_linkedin\Controller\LinkedInAuthController::callback()

Response for path 'user/login/linkedin/callback'.

LinkedIn returns the user here after user has authenticated.

1 string reference to 'LinkedInAuthController::callback'
social_auth_linkedin.routing.yml in ./social_auth_linkedin.routing.yml
social_auth_linkedin.routing.yml

File

src/Controller/LinkedInAuthController.php, line 78

Class

LinkedInAuthController
Returns responses for Social Auth LinkedIn routes.

Namespace

Drupal\social_auth_linkedin\Controller

Code

public function callback() {

  // Checks if there was an authentication error.
  $redirect = $this
    ->checkAuthError();
  if ($redirect) {
    return $redirect;
  }

  /* @var \League\OAuth2\Client\Provider\LinkedInResourceOwner|null $profile */
  $profile = $this
    ->processCallback();

  // If authentication was successful.
  if ($profile !== NULL) {

    // Gets (or not) extra initial data.
    $data = $this->userAuthenticator
      ->checkProviderIsAssociated($profile
      ->getId()) ? NULL : $this->providerManager
      ->getExtraDetails();
    $name = $profile
      ->getFirstName() . ' ' . $profile
      ->getLastName();
    $email = $this->providerManager
      ->getEmail();

    // If user information could be retrieved.
    return $this->userAuthenticator
      ->authenticateUser($name, $email, $profile
      ->getId(), $this->providerManager
      ->getAccessToken(), $profile
      ->getImageUrl(), $data);
  }
  return $this
    ->redirect('user.login');
}