class GoogleAuthManager in Social Auth Google 8
Same name and namespace in other branches
- 8.2 src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager
- 3.x src/GoogleAuthManager.php \Drupal\social_auth_google\GoogleAuthManager
Manages the authentication requests.
Hierarchy
- class \Drupal\social_auth_google\GoogleAuthManager extends \Drupal\social_auth\AuthManager\OAuth2Manager
Expanded class hierarchy of GoogleAuthManager
2 files declare their use of GoogleAuthManager
- GoogleAuthController.php in src/
Controller/ GoogleAuthController.php - GoogleAuthManagerTest.php in tests/
src/ Unit/ GoogleAuthManagerTest.php
1 string reference to 'GoogleAuthManager'
1 service uses GoogleAuthManager
File
- src/
GoogleAuthManager.php, line 12
Namespace
Drupal\social_auth_googleView source
class GoogleAuthManager extends OAuth2Manager {
/**
* The request object.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* The Google service client.
*
* @var \Google_Client
*/
protected $client;
/**
* Code returned by Google for authentication.
*
* @var string
*/
protected $code;
/**
* GoogleLoginManager constructor.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request
* Used to get the parameter code returned by Google.
*/
public function __construct(RequestStack $request) {
$this->request = $request
->getCurrentRequest();
}
/**
* {@inheritdoc}
*/
public function authenticate() {
$this->client
->setAccessToken($this
->getAccessToken());
return $this;
}
/**
* {@inheritdoc}
*/
public function getAccessToken() {
if (!$this->accessToken) {
$this->accessToken = $this->client
->fetchAccessTokenWithAuthCode($this
->getCode());
}
return $this->accessToken;
}
/**
* {@inheritdoc}
*/
public function getUserInfo() {
return $this
->getOauth2Service()->userinfo
->get();
}
/**
* Gets Google Oauth2 Service.
*
* @return \Google_Service_Oauth2
* The Google Oauth2 service.
*/
protected function getOauth2Service() {
return new Google_Service_Oauth2($this
->getClient());
}
/**
* Gets the code returned by Google to authenticate.
*
* @return string
* The code string returned by Google.
*/
protected function getCode() {
if (!$this->code) {
$this->code = $this->request->query
->get('code');
}
return $this->code;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GoogleAuthManager:: |
protected | property | The Google service client. | |
GoogleAuthManager:: |
protected | property | Code returned by Google for authentication. | |
GoogleAuthManager:: |
protected | property | The request object. | |
GoogleAuthManager:: |
public | function | ||
GoogleAuthManager:: |
public | function | ||
GoogleAuthManager:: |
protected | function | Gets the code returned by Google to authenticate. | |
GoogleAuthManager:: |
protected | function | Gets Google Oauth2 Service. | |
GoogleAuthManager:: |
public | function | ||
GoogleAuthManager:: |
public | function | GoogleLoginManager constructor. |