class GoogleAuthManager in Social Auth Google 8.2
Same name and namespace in other branches
- 8 src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager
- 3.x src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager
Contains all the logic for Google OAuth2 authentication.
Hierarchy
- class \Drupal\social_auth_google\GoogleAuthManager extends \Drupal\social_auth\AuthManager\OAuth2Manager
Expanded class hierarchy of GoogleAuthManager
1 file declares its use of GoogleAuthManager
- GoogleAuthController.php in src/
Controller/ GoogleAuthController.php
1 string reference to 'GoogleAuthManager'
1 service uses GoogleAuthManager
File
- src/
GoogleAuthManager.php, line 14
Namespace
Drupal\social_auth_googleView source
class GoogleAuthManager extends OAuth2Manager {
/**
* Constructor.
*
* @param \Drupal\Core\Config\ConfigFactory $configFactory
* Used for accessing configuration object factory.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
* The logger factory.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* Used to get the authorization code from the callback request.
*/
public function __construct(ConfigFactory $configFactory, LoggerChannelFactoryInterface $logger_factory, RequestStack $request_stack) {
parent::__construct($configFactory
->get('social_auth_google.settings'), $logger_factory, $request_stack
->getCurrentRequest());
}
/**
* {@inheritdoc}
*/
public function authenticate() {
try {
$this
->setAccessToken($this->client
->getAccessToken('authorization_code', [
'code' => $this->request->query
->get('code'),
]));
} catch (IdentityProviderException $e) {
$this->loggerFactory
->get('social_auth_google')
->error('There was an error during authentication. Exception: ' . $e
->getMessage());
}
}
/**
* {@inheritdoc}
*/
public function getUserInfo() {
if (!$this->user) {
$this->user = $this->client
->getResourceOwner($this
->getAccessToken());
}
return $this->user;
}
/**
* {@inheritdoc}
*/
public function getAuthorizationUrl() {
$scopes = [
'email',
'profile',
];
$extra_scopes = $this
->getScopes();
if ($extra_scopes) {
$scopes = array_merge($scopes, explode(',', $extra_scopes));
}
// Returns the URL where user will be redirected.
return $this->client
->getAuthorizationUrl([
'scope' => $scopes,
]);
}
/**
* {@inheritdoc}
*/
public function requestEndPoint($method, $path, $domain = NULL, array $options = []) {
if (!$domain) {
$domain = 'https://www.googleapis.com';
}
$url = $domain . $path;
$request = $this->client
->getAuthenticatedRequest($method, $url, $this
->getAccessToken(), $options);
try {
return $this->client
->getParsedResponse($request);
} catch (IdentityProviderException $e) {
$this->loggerFactory
->get('social_auth_google')
->error('There was an error when requesting ' . $url . '. Exception: ' . $e
->getMessage());
}
return NULL;
}
/**
* {@inheritdoc}
*/
public function getState() {
return $this->client
->getState();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GoogleAuthManager:: |
public | function | ||
GoogleAuthManager:: |
public | function | ||
GoogleAuthManager:: |
public | function | ||
GoogleAuthManager:: |
public | function | ||
GoogleAuthManager:: |
public | function | ||
GoogleAuthManager:: |
public | function | Constructor. |