You are here

class LinkedinAuthManager in Social Auth LinkedIn 8

Same name and namespace in other branches
  1. 8.2 src/LinkedInAuthManager.php \Drupal\social_auth_linkedin\LinkedInAuthManager
  2. 3.x src/LinkedInAuthManager.php \Drupal\social_auth_linkedin\LinkedInAuthManager

Manages the authentication requests.

Hierarchy

  • class \Drupal\social_auth_linkedin\LinkedinAuthManager extends \Drupal\social_auth\AuthManager\OAuth2Manager

Expanded class hierarchy of LinkedinAuthManager

2 files declare their use of LinkedinAuthManager
LinkedinAuthController.php in src/Controller/LinkedinAuthController.php
LinkedinAuthManagerTest.php in tests/src/Unit/LinkedinAuthManagerTest.php
1 string reference to 'LinkedinAuthManager'
social_auth_linkedin.services.yml in ./social_auth_linkedin.services.yml
social_auth_linkedin.services.yml
1 service uses LinkedinAuthManager
social_auth_linkedin.manager in ./social_auth_linkedin.services.yml
Drupal\social_auth_linkedin\LinkedinAuthManager

File

src/LinkedinAuthManager.php, line 11

Namespace

Drupal\social_auth_linkedin
View source
class LinkedinAuthManager extends OAuth2Manager {

  /**
   * The request object.
   *
   * @var \Symfony\Component\HttpFoundation\Request
   */
  protected $request;

  /**
   * The Linkedin service client.
   *
   * @var \LinkedIn\LinkedIn
   */
  protected $client;

  /**
   * Code returned by Linkedin for authentication.
   *
   * @var string
   */
  protected $code;

  /**
   * LinkedinLoginManager constructor.
   *
   * @param \Symfony\Component\HttpFoundation\RequestStack $request
   *   Used to get the parameter code returned by Linkedin.
   */
  public function __construct(RequestStack $request) {
    $this->request = $request
      ->getCurrentRequest();
  }

  /**
   * {@inheritdoc}
   */
  public function authenticate() {
    $this->client
      ->setAccessToken($this
      ->getAccessToken());
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getAccessToken() {
    if (!$this->accessToken) {
      $this->accessToken = $this->client
        ->getAccessToken($this
        ->getCode());
    }
    return $this->accessToken;
  }

  /**
   * {@inheritdoc}
   */
  public function getUserInfo() {
    return $this->client
      ->get('/people/~:(id,first-name,last-name,email-address,picture-urls::(original))');
  }

  /**
   * Gets the code returned by Linkedin to authenticate.
   *
   * @return string
   *   The code string returned by Linkedin.
   */
  protected function getCode() {
    if (!$this->code) {
      $this->code = $this->request->query
        ->get('code');
    }
    return $this->code;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LinkedinAuthManager::$client protected property The Linkedin service client.
LinkedinAuthManager::$code protected property Code returned by Linkedin for authentication.
LinkedinAuthManager::$request protected property The request object.
LinkedinAuthManager::authenticate public function
LinkedinAuthManager::getAccessToken public function
LinkedinAuthManager::getCode protected function Gets the code returned by Linkedin to authenticate.
LinkedinAuthManager::getUserInfo public function
LinkedinAuthManager::__construct public function LinkedinLoginManager constructor.