class FacebookAuthManager in Open Social 8.9
Same name and namespace in other branches
- 8 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager
- 8.2 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager
- 8.3 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager
- 8.4 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager
- 8.5 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager
- 8.6 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager
- 8.7 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager
- 8.8 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager
Class FacebookAuthManager.
@package Drupal\social_auth_facebook
Hierarchy
- class \Drupal\social_auth_extra\AuthManager implements AuthManagerInterface
- class \Drupal\social_auth_facebook\FacebookAuthManager
Expanded class hierarchy of FacebookAuthManager
2 files declare their use of FacebookAuthManager
- FacebookAuthController.php in modules/
custom/ social_auth_facebook/ src/ Controller/ FacebookAuthController.php - FacebookLinkController.php in modules/
custom/ social_auth_facebook/ src/ Controller/ FacebookLinkController.php
1 string reference to 'FacebookAuthManager'
- social_auth_facebook.services.yml in modules/
custom/ social_auth_facebook/ social_auth_facebook.services.yml - modules/custom/social_auth_facebook/social_auth_facebook.services.yml
1 service uses FacebookAuthManager
- social_auth_facebook.auth_manager in modules/
custom/ social_auth_facebook/ social_auth_facebook.services.yml - \Drupal\social_auth_facebook\FacebookAuthManager
File
- modules/
custom/ social_auth_facebook/ src/ FacebookAuthManager.php, line 17
Namespace
Drupal\social_auth_facebookView source
class FacebookAuthManager extends AuthManager {
/**
* {@inheritdoc}
*/
public function getSocialNetworkKey() {
return FacebookAuthSettings::getSocialNetworkKey();
}
/**
* {@inheritdoc}
*/
public function setSdk($sdk) {
if (!$sdk instanceof Facebook) {
throw new InvalidArgumentException('SDK object should be instance of \\Facebook\\Facebook class');
}
$this->sdk = $sdk;
}
/**
* {@inheritdoc}
*/
public function getAuthenticationUrl($type, array $scope = [
'public_profile',
'email',
]) {
$helper = $this->sdk
->getRedirectLoginHelper();
return $helper
->getLoginUrl($this
->getRedirectUrl($type), $scope);
}
/**
* {@inheritdoc}
*/
public function getAccessToken($type) {
$helper = $this->sdk
->getRedirectLoginHelper();
$redirect_url = $this
->getRedirectUrl($type);
try {
$access_token = $helper
->getAccessToken($redirect_url);
} catch (FacebookResponseException $e) {
$this->loggerFactory
->get('social_auth_facebook')
->error('Could not get Facebook access token. FacebookResponseException: @message', [
'@message' => $e
->getMessage(),
]);
return NULL;
} catch (FacebookSDKException $e) {
$this->loggerFactory
->get('social_auth_facebook')
->error('Could not get Facebook access token. FacebookSDKException: @message', [
'@message' => $e
->getMessage(),
]);
return NULL;
}
if ($access_token) {
$this->sdk
->setDefaultAccessToken($access_token);
return $access_token;
}
$this->loggerFactory
->get('social_auth_facebook')
->error('Could not get Facebook access token. User cancelled the dialog in Facebook or return URL was not valid.');
return NULL;
}
/**
* {@inheritdoc}
*/
public function getProfile() {
try {
$this->profile = $this->sdk
->get('/me?fields=id,name,email,first_name,last_name')
->getGraphNode();
} catch (FacebookResponseException $e) {
$this->loggerFactory
->get('social_auth_facebook')
->error('Could not load Facebook user profile: FacebookResponseException: @message', [
'@message' => $e
->getMessage(),
]);
return NULL;
} catch (FacebookSDKException $e) {
$this->loggerFactory
->get('social_auth_facebook')
->error('Could not load Facebook user profile: FacebookSDKException: @message', [
'@message' => $e
->getMessage(),
]);
return NULL;
}
return $this->profile;
}
/**
* {@inheritdoc}
*/
public function getProfilePicture() {
$resolution = $this
->getPreferredResolution();
$query = [
'redirect' => 'false',
];
if (is_array($resolution)) {
$query += $resolution;
}
try {
$graph_node = $this->sdk
->get('/me/picture?' . http_build_query($query))
->getGraphNode();
$is_silhouette = (bool) $graph_node
->getField('is_silhouette');
if ($is_silhouette) {
return FALSE;
}
return $graph_node
->getField('url');
} catch (FacebookResponseException $e) {
$this->loggerFactory
->get('social_auth_facebook')
->error('Could not load Facebook profile picture: FacebookResponseException: @message', [
'@message' => $e
->getMessage(),
]);
return NULL;
} catch (FacebookSDKException $e) {
$this->loggerFactory
->get('social_auth_facebook')
->error('Could not load Facebook profile picture: FacebookSDKException: @message', [
'@message' => $e
->getMessage(),
]);
return NULL;
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function setAccessToken($access_token) {
$this->sdk
->setDefaultAccessToken($access_token);
}
/**
* {@inheritdoc}
*/
public function getAccountId() {
if ($profile = $this
->getProfile()) {
return $profile
->getField('id');
}
}
/**
* {@inheritdoc}
*/
public function getFirstName() {
if ($profile = $this
->getProfile()) {
return $profile
->getField('first_name');
}
}
/**
* {@inheritdoc}
*/
public function getLastName() {
if ($profile = $this
->getProfile()) {
return $profile
->getField('last_name');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AuthManager:: |
protected | property | ||
AuthManager:: |
protected | property | Contains the field definition with a profile picture. | |
AuthManager:: |
protected | property | ||
AuthManager:: |
protected | property | Contains object of a profile received from a social network. | |
AuthManager:: |
protected | property | Object of SDK to work with API of social network. | |
AuthManager:: |
protected | property | ||
AuthManager:: |
public | function |
Determines preferred profile pic resolution from account settings. Overrides AuthManagerInterface:: |
|
AuthManager:: |
public | function |
Returns URL to authorize/registration depending on type. Overrides AuthManagerInterface:: |
|
AuthManager:: |
public | function |
Returns user on a social network if it possible. Overrides AuthManagerInterface:: |
1 |
AuthManager:: |
public | function |
Set an instance of a field definition that contains picture. Overrides AuthManagerInterface:: |
|
AuthManager:: |
public | function | AuthManager constructor. | |
FacebookAuthManager:: |
public | function |
Reads user's access token from social network. Overrides AuthManagerInterface:: |
|
FacebookAuthManager:: |
public | function |
Returns an account ID on a social network. Overrides AuthManagerInterface:: |
|
FacebookAuthManager:: |
public | function |
Returns the login URL where user will be redirected for authentication. Overrides AuthManagerInterface:: |
|
FacebookAuthManager:: |
public | function |
Returns first name on a social network if it possible. Overrides AuthManagerInterface:: |
|
FacebookAuthManager:: |
public | function |
Returns last name on a social network if it possible. Overrides AuthManagerInterface:: |
|
FacebookAuthManager:: |
public | function |
Returns object of a user profile. Overrides AuthManagerInterface:: |
|
FacebookAuthManager:: |
public | function |
Returns URL of a profile picture. Overrides AuthManagerInterface:: |
|
FacebookAuthManager:: |
public | function |
Returns key-name of a social network. Overrides AuthManagerInterface:: |
|
FacebookAuthManager:: |
public | function |
Set access token to AuthManager to use it for API calls. Overrides AuthManagerInterface:: |
|
FacebookAuthManager:: |
public | function |
Set instance of SDK. Overrides AuthManagerInterface:: |