class TwitterAuthManager in Open Social 8.9
Same name and namespace in other branches
- 8 modules/custom/social_auth_twitter/src/TwitterAuthManager.php \Drupal\social_auth_twitter\TwitterAuthManager
- 8.2 modules/custom/social_auth_twitter/src/TwitterAuthManager.php \Drupal\social_auth_twitter\TwitterAuthManager
- 8.3 modules/custom/social_auth_twitter/src/TwitterAuthManager.php \Drupal\social_auth_twitter\TwitterAuthManager
- 8.4 modules/custom/social_auth_twitter/src/TwitterAuthManager.php \Drupal\social_auth_twitter\TwitterAuthManager
- 8.5 modules/custom/social_auth_twitter/src/TwitterAuthManager.php \Drupal\social_auth_twitter\TwitterAuthManager
- 8.6 modules/custom/social_auth_twitter/src/TwitterAuthManager.php \Drupal\social_auth_twitter\TwitterAuthManager
- 8.7 modules/custom/social_auth_twitter/src/TwitterAuthManager.php \Drupal\social_auth_twitter\TwitterAuthManager
- 8.8 modules/custom/social_auth_twitter/src/TwitterAuthManager.php \Drupal\social_auth_twitter\TwitterAuthManager
Manages the authorization process before getting a long lived access token.
Hierarchy
- class \Drupal\social_auth_extra\AuthManager implements AuthManagerInterface
- class \Drupal\social_auth_twitter\TwitterAuthManager
Expanded class hierarchy of TwitterAuthManager
2 files declare their use of TwitterAuthManager
- TwitterAuthController.php in modules/
custom/ social_auth_twitter/ src/ Controller/ TwitterAuthController.php - TwitterLinkController.php in modules/
custom/ social_auth_twitter/ src/ Controller/ TwitterLinkController.php
1 string reference to 'TwitterAuthManager'
- social_auth_twitter.services.yml in modules/
custom/ social_auth_twitter/ social_auth_twitter.services.yml - modules/custom/social_auth_twitter/social_auth_twitter.services.yml
1 service uses TwitterAuthManager
- social_auth_twitter.auth_manager in modules/
custom/ social_auth_twitter/ social_auth_twitter.services.yml - \Drupal\social_auth_twitter\TwitterAuthManager
File
- modules/
custom/ social_auth_twitter/ src/ TwitterAuthManager.php, line 14
Namespace
Drupal\social_auth_twitterView source
class TwitterAuthManager extends AuthManager {
/**
* {@inheritdoc}
*/
public function getSocialNetworkKey() {
return TwitterAuthSettings::getSocialNetworkKey();
}
/**
* {@inheritdoc}
*/
public function setSdk($sdk) {
if (!$sdk instanceof TwitterOAuth) {
throw new InvalidArgumentException('SDK object should be instance of \\Abraham\\TwitterOAuth\\TwitterOAuth class');
}
$this->sdk = $sdk;
}
/**
* {@inheritdoc}
*/
public function getAuthenticationUrl($type, array $scope = [
'read',
]) {
$request_token = $this->sdk
->oauth('oauth/request_token', [
'oauth_callback' => $this
->getRedirectUrl($type),
'x_auth_access_type' => current($scope),
]);
$data_handler = \Drupal::service('plugin.network.manager')
->createInstance('social_auth_twitter')
->getDataHandler();
$data_handler
->set('oauth_token', $request_token['oauth_token']);
$data_handler
->set('oauth_token_secret', $request_token['oauth_token_secret']);
return $this->sdk
->url('oauth/authorize', [
'oauth_token' => $request_token['oauth_token'],
]);
}
/**
* {@inheritdoc}
*/
public function getAccessToken($type) {
// This method should not used for Twitter.
return NULL;
}
/**
* {@inheritdoc}
*/
public function getProfile() {
try {
$this->profile = $this->sdk
->get('account/verify_credentials', [
'include_email' => 'true',
'include_entities' => 'false',
'skip_status' => 'true',
]);
return $this->profile;
} catch (TwitterOAuthException $e) {
$this->loggerFactory
->get('social_auth_twitter')
->error('Could not load Twitter user profile: TwitterOAuthException: @message', [
'@message' => $e
->getMessage(),
]);
return NULL;
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getProfilePicture() {
if (($profile = $this
->getProfile()) && isset($profile->screen_name) && empty($profile->default_profile_image)) {
return "https://twitter.com/{$profile->screen_name}/profile_image?size=original";
}
}
/**
* {@inheritdoc}
*/
public function setAccessToken($access_token) {
$this->sdk
->setOauthToken($access_token['oauth_token'], $access_token['oauth_token_secret']);
}
/**
* {@inheritdoc}
*/
public function getAccountId() {
if (($profile = $this
->getProfile()) && isset($profile->id)) {
return $profile->id;
}
}
/**
* {@inheritdoc}
*/
public function getFirstName() {
// Twitter doesn't contain first name.
return NULL;
}
/**
* {@inheritdoc}
*/
public function getLastName() {
// Twitter doesn't contain last name.
return NULL;
}
/**
* {@inheritdoc}
*/
public function getUsername() {
if (($profile = $this
->getProfile()) && isset($profile->screen_name)) {
return $profile->screen_name;
}
return parent::getUsername();
}
}
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 |
Set an instance of a field definition that contains picture. Overrides AuthManagerInterface:: |
|
AuthManager:: |
public | function | AuthManager constructor. | |
TwitterAuthManager:: |
public | function |
Reads user's access token from social network. Overrides AuthManagerInterface:: |
|
TwitterAuthManager:: |
public | function |
Returns an account ID on a social network. Overrides AuthManagerInterface:: |
|
TwitterAuthManager:: |
public | function |
Returns the login URL where user will be redirected for authentication. Overrides AuthManagerInterface:: |
|
TwitterAuthManager:: |
public | function |
Returns first name on a social network if it possible. Overrides AuthManagerInterface:: |
|
TwitterAuthManager:: |
public | function |
Returns last name on a social network if it possible. Overrides AuthManagerInterface:: |
|
TwitterAuthManager:: |
public | function |
Returns object of a user profile. Overrides AuthManagerInterface:: |
|
TwitterAuthManager:: |
public | function |
Returns URL of a profile picture. Overrides AuthManagerInterface:: |
|
TwitterAuthManager:: |
public | function |
Returns key-name of a social network. Overrides AuthManagerInterface:: |
|
TwitterAuthManager:: |
public | function |
Returns user on a social network if it possible. Overrides AuthManager:: |
|
TwitterAuthManager:: |
public | function |
Set access token to AuthManager to use it for API calls. Overrides AuthManagerInterface:: |
|
TwitterAuthManager:: |
public | function |
Set instance of SDK. Overrides AuthManagerInterface:: |