class GoogleAuthManager in Social Auth Google 3.x
Same name and namespace in other branches
- 8.2 src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager
- 8 src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager
Contains all the logic for Google OAuth2 authentication.
Hierarchy
- class \Drupal\social_api\AuthManager\OAuth2Manager implements OAuth2ManagerInterface
- class \Drupal\social_auth\AuthManager\OAuth2Manager implements OAuth2ManagerInterface
- class \Drupal\social_auth_google\GoogleAuthManager
- class \Drupal\social_auth\AuthManager\OAuth2Manager implements OAuth2ManagerInterface
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() {
$access_token = $this
->getAccessToken();
if (!$this->user && $access_token != NULL) {
$this->user = $this->client
->getResourceOwner($this
->getAccessToken());
}
else {
$this->loggerFactory
->get('social_auth_google')
->error('There was an error fetching the access token for user.');
}
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 |
Authenticates the user. Overrides OAuth2ManagerInterface:: |
|
GoogleAuthManager:: |
public | function |
Returns the authorization URL where user will be redirected. Overrides OAuth2ManagerInterface:: |
|
GoogleAuthManager:: |
public | function |
Returns OAuth2 state. Overrides OAuth2ManagerInterface:: |
|
GoogleAuthManager:: |
public | function |
Gets data about the user. Overrides OAuth2ManagerInterface:: |
|
GoogleAuthManager:: |
public | function |
Request and end point. Overrides OAuth2ManagerInterface:: |
|
GoogleAuthManager:: |
public | function |
Constructor. Overrides OAuth2Manager:: |
|
OAuth2Manager:: |
protected | property | Access token for OAuth2 authentication. | |
OAuth2Manager:: |
protected | property | The service client. | |
OAuth2Manager:: |
protected | property | The end points to be requested. | |
OAuth2Manager:: |
protected | property | The logger factory. | |
OAuth2Manager:: |
protected | property | The current request. | |
OAuth2Manager:: |
protected | property | The scopes to be requested. | |
OAuth2Manager:: |
protected | property | Social Auth implementer settings. | |
OAuth2Manager:: |
protected | property |
The user returned by the provider. Overrides OAuth2Manager:: |
|
OAuth2Manager:: |
public | function |
Gets the access token after authentication. Overrides OAuth2ManagerInterface:: |
|
OAuth2Manager:: |
public | function |
Gets the service client object. Overrides OAuth2ManagerInterface:: |
|
OAuth2Manager:: |
public | function |
Gets the API endpoints to be requested. Overrides OAuth2ManagerInterface:: |
|
OAuth2Manager:: |
public | function |
Request data from the declared endpoints. Overrides OAuth2ManagerInterface:: |
|
OAuth2Manager:: |
public | function |
Gets the scopes defined in the settings form. Overrides OAuth2ManagerInterface:: |
|
OAuth2Manager:: |
public | function |
Sets the access token. Overrides OAuth2ManagerInterface:: |
|
OAuth2Manager:: |
public | function |
Sets the provider client. Overrides OAuth2ManagerInterface:: |