class FacebookAuthManager in Social Auth Facebook 8.2
Same name and namespace in other branches
- 8 src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager
- 3.x src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager
Contains all the logic for Facebook OAuth2 authentication.
Hierarchy
- class \Drupal\social_auth_facebook\FacebookAuthManager extends \Drupal\social_auth\AuthManager\OAuth2Manager
Expanded class hierarchy of FacebookAuthManager
1 file declares its use of FacebookAuthManager
- FacebookAuthController.php in src/
Controller/ FacebookAuthController.php
1 string reference to 'FacebookAuthManager'
1 service uses FacebookAuthManager
File
- src/
FacebookAuthManager.php, line 13
Namespace
Drupal\social_auth_facebookView source
class FacebookAuthManager extends OAuth2Manager {
/**
* The Facebook client.
*
* @var \League\OAuth2\Client\Provider\Facebook
*/
protected $client;
/**
* Constructor.
*
* @param \Drupal\Core\Config\ConfigFactory $configFactory
* Used for accessing configuration object factory.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
* The logger factory.
*/
public function __construct(ConfigFactory $configFactory, LoggerChannelFactoryInterface $logger_factory) {
parent::__construct($configFactory
->get('social_auth_facebook.settings'), $logger_factory);
}
/**
* {@inheritdoc}
*/
public function authenticate() {
try {
$this
->setAccessToken($this->client
->getLongLivedAccessToken($this->client
->getAccessToken('authorization_code', [
'code' => $_GET['code'],
])));
} catch (\Exception $e) {
$this->loggerFactory
->get('social_auth_facebook')
->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',
'public_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://graph.facebook.com';
}
$url = $domain . '/v' . $this->settings
->get('graph_version') . $path;
$url .= '&access_token=' . $this
->getAccessToken();
$request = $this->client
->getAuthenticatedRequest($method, $url, $this
->getAccessToken(), $options);
try {
return $this->client
->getParsedResponse($request);
} catch (IdentityProviderException $e) {
$this->loggerFactory
->get('social_auth_facebook')
->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 |
---|---|---|---|---|
FacebookAuthManager:: |
protected | property | The Facebook client. | |
FacebookAuthManager:: |
public | function | ||
FacebookAuthManager:: |
public | function | ||
FacebookAuthManager:: |
public | function | ||
FacebookAuthManager:: |
public | function | ||
FacebookAuthManager:: |
public | function | ||
FacebookAuthManager:: |
public | function | Constructor. |