You are here

public function LinkedInAuthManager::getAccessToken in Open Social 8.9

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

Reads user's access token from social network.

Parameters

string $type: Type of action. "login" or "register".

Return value

object User's access token, if it could be read from social network. Null, otherwise.

Overrides AuthManagerInterface::getAccessToken

File

modules/custom/social_auth_linkedin/src/LinkedInAuthManager.php, line 53

Class

LinkedInAuthManager
Class LinkedInAuthManager.

Namespace

Drupal\social_auth_linkedin

Code

public function getAccessToken($type = '') {
  try {

    // Set the RedirectUrl before retrieving the access token.
    $redirect_url = $this
      ->getRedirectUrl($type);
    $this->sdk
      ->setRedirectUrl($redirect_url);
    $access_token = $this->sdk
      ->getAccessToken($_GET['code']);
    return $access_token;
  } catch (LinkedInException $e) {
    $this->loggerFactory
      ->get('social_auth_linkedin')
      ->error('Could not get LinkedIn access token. LinkedInException: @message', [
      '@message' => $e
        ->getMessage(),
    ]);
    return NULL;
  }
  if ($access_token) {
    $this->sdk
      ->setAccessToken($access_token);
    return $access_token;
  }
  $this->loggerFactory
    ->get('social_auth_linkedin')
    ->error('Could not get LinkedIn access token. User cancelled the dialog in LinkedIn or return URL was not valid.');
  return NULL;
}