You are here

class GoogleAuthManager in Open Social 8.2

Same name and namespace in other branches
  1. 8.9 modules/custom/social_auth_google/src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager
  2. 8 modules/custom/social_auth_google/src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager
  3. 8.3 modules/custom/social_auth_google/src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager
  4. 8.4 modules/custom/social_auth_google/src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager
  5. 8.5 modules/custom/social_auth_google/src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager
  6. 8.6 modules/custom/social_auth_google/src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager
  7. 8.7 modules/custom/social_auth_google/src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager
  8. 8.8 modules/custom/social_auth_google/src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager

Class GoogleAuthManager.

@package Drupal\social_auth_google

Hierarchy

Expanded class hierarchy of GoogleAuthManager

2 files declare their use of GoogleAuthManager
GoogleAuthController.php in modules/custom/social_auth_google/src/Controller/GoogleAuthController.php
GoogleLinkController.php in modules/custom/social_auth_google/src/Controller/GoogleLinkController.php
1 string reference to 'GoogleAuthManager'
social_auth_google.services.yml in modules/custom/social_auth_google/social_auth_google.services.yml
modules/custom/social_auth_google/social_auth_google.services.yml
1 service uses GoogleAuthManager
social_auth_google.auth_manager in modules/custom/social_auth_google/social_auth_google.services.yml
\Drupal\social_auth_google\GoogleAuthManager

File

modules/custom/social_auth_google/src/GoogleAuthManager.php, line 14

Namespace

Drupal\social_auth_google
View source
class GoogleAuthManager extends AuthManager {

  /**
   * Holds the Google Service.
   *
   * @var \Google_Service_Oauth2
   */
  private $googleService;

  /**
   * {@inheritdoc}
   */
  public function getSocialNetworkKey() {
    return GoogleAuthSettings::getSocialNetworkKey();
  }

  /**
   * {@inheritdoc}
   */
  public function setSdk($sdk) {
    if (!$sdk instanceof \Google_Client) {
      throw new InvalidArgumentException('SDK object should be instance of \\Google_Client class');
    }
    $this->sdk = $sdk;
  }

  /**
   * {@inheritdoc}
   */
  public function getAuthenticationUrl($type, array $scope = [
    'profile',
    'email',
  ]) {
    $redirect_url = $this
      ->getRedirectUrl($type);
    $this->sdk
      ->setRedirectUri($redirect_url);
    return $this->sdk
      ->createAuthUrl($scope);
  }

  /**
   * {@inheritdoc}
   */
  public function getProfilePicture() {
    return $this->profile
      ->getPicture();
  }

  /**
   * {@inheritdoc}
   */
  public function getAccessToken($type) {
    $redirect_url = $this
      ->getRedirectUrl($type);
    $this->sdk
      ->setRedirectUri($redirect_url);
    return $this->sdk
      ->authenticate(\Drupal::request()
      ->get('code'));
  }

  /**
   * {@inheritdoc}
   */
  public function getProfile() {
    if (empty($this->googleService)) {
      $this->googleService = new \Google_Service_Oauth2($this->sdk);
    }
    $this->profile = $this->googleService->userinfo
      ->get();
    return $this->profile;
  }

  /**
   * {@inheritdoc}
   */
  public function setAccessToken($access_token) {
    $this->sdk
      ->setAccessToken($access_token);
  }

  /**
   * {@inheritdoc}
   */
  public function getAccountId() {
    return $this->profile
      ->getId();
  }

  /**
   * {@inheritdoc}
   */
  public function getFirstName() {
    return $this->profile
      ->getGivenName();
  }

  /**
   * {@inheritdoc}
   */
  public function getLastName() {
    return $this->profile
      ->getFamilyName();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AuthManager::$entityFieldManager protected property
AuthManager::$fieldPicture protected property Contains the field definition with a profile picture.
AuthManager::$loggerFactory protected property
AuthManager::$profile protected property Contains object of a profile received from a social network.
AuthManager::$sdk protected property Object of SDK to work with API of social network.
AuthManager::$urlGenerator protected property
AuthManager::getPreferredResolution public function Determines preferred profile pic resolution from account settings. Overrides AuthManagerInterface::getPreferredResolution
AuthManager::getRedirectUrl public function Returns URL to authorize/registration depending on type. Overrides AuthManagerInterface::getRedirectUrl
AuthManager::getUsername public function Returns user on a social network if it possible. Overrides AuthManagerInterface::getUsername 1
AuthManager::setFieldPicture public function Set an instance of a field definition that contains picture. Overrides AuthManagerInterface::setFieldPicture
AuthManager::__construct public function AuthManager constructor.
GoogleAuthManager::$googleService private property Holds the Google Service.
GoogleAuthManager::getAccessToken public function Reads user's access token from social network. Overrides AuthManagerInterface::getAccessToken
GoogleAuthManager::getAccountId public function Returns an account ID on a social network. Overrides AuthManagerInterface::getAccountId
GoogleAuthManager::getAuthenticationUrl public function Returns the login URL where user will be redirected for authentication. Overrides AuthManagerInterface::getAuthenticationUrl
GoogleAuthManager::getFirstName public function Returns first name on a social network if it possible. Overrides AuthManagerInterface::getFirstName
GoogleAuthManager::getLastName public function Returns last name on a social network if it possible. Overrides AuthManagerInterface::getLastName
GoogleAuthManager::getProfile public function Returns object of a user profile. Overrides AuthManagerInterface::getProfile
GoogleAuthManager::getProfilePicture public function Returns URL of a profile picture. Overrides AuthManagerInterface::getProfilePicture
GoogleAuthManager::getSocialNetworkKey public function Returns key-name of a social network. Overrides AuthManagerInterface::getSocialNetworkKey
GoogleAuthManager::setAccessToken public function Set access token to AuthManager to use it for API calls. Overrides AuthManagerInterface::setAccessToken
GoogleAuthManager::setSdk public function Set instance of SDK. Overrides AuthManagerInterface::setSdk