LinkedInAuthController.php in Social Auth LinkedIn 8.2
File
src/Controller/LinkedInAuthController.php
View source
<?php
namespace Drupal\social_auth_linkedin\Controller;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\social_api\Plugin\NetworkManager;
use Drupal\social_auth\Controller\OAuth2ControllerBase;
use Drupal\social_auth\SocialAuthDataHandler;
use Drupal\social_auth\User\UserAuthenticator;
use Drupal\social_auth_linkedin\LinkedInAuthManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class LinkedInAuthController extends OAuth2ControllerBase {
protected $providerManager;
public function __construct(MessengerInterface $messenger, NetworkManager $network_manager, UserAuthenticator $user_authenticator, LinkedInAuthManager $linkedIn_manager, RequestStack $request, SocialAuthDataHandler $data_handler, RendererInterface $renderer) {
parent::__construct('Social Auth LinkedIn', 'social_auth_linkedin', $messenger, $network_manager, $user_authenticator, $linkedIn_manager, $request, $data_handler, $renderer);
}
public static function create(ContainerInterface $container) {
return new static($container
->get('messenger'), $container
->get('plugin.network.manager'), $container
->get('social_auth.user_authenticator'), $container
->get('social_auth_linkedin.manager'), $container
->get('request_stack'), $container
->get('social_auth.data_handler'), $container
->get('renderer'));
}
public function callback() {
$redirect = $this
->checkAuthError();
if ($redirect) {
return $redirect;
}
$profile = $this
->processCallback();
if ($profile !== NULL) {
$data = $this->userAuthenticator
->checkProviderIsAssociated($profile
->getId()) ? NULL : $this->providerManager
->getExtraDetails();
$name = $profile
->getFirstName() . ' ' . $profile
->getLastName();
$email = $this->providerManager
->getEmail();
return $this->userAuthenticator
->authenticateUser($name, $email, $profile
->getId(), $this->providerManager
->getAccessToken(), $profile
->getImageUrl(), $data);
}
return $this
->redirect('user.login');
}
}