You are here

public function LinkedInAuthController::getProfile in Open Social 8.7

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

Loads access token, then loads profile.

Parameters

string $type: The type.

Return value

object Returns an object.

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

File

modules/custom/social_auth_linkedin/src/Controller/LinkedInAuthController.php, line 230

Class

LinkedInAuthController
Class LinkedInAuthController.

Namespace

Drupal\social_auth_linkedin\Controller

Code

public function getProfile($type) {

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

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