Loading README.md +23 −6 Original line number Diff line number Diff line Loading @@ -68,17 +68,34 @@ In [Twitter Developer Portal](https://developer.twitter.com/portal): 8. Click App settings. 9. Under User authentication settings click Set up. 9. Ensure the app has [Elevated Access](https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#item0). 10. Toggle "OAuth 1.0a" (to enable it). 1. Click Apply next to the message "Do you need Elevated access for your Project?" if it appears. 11. Optionally toggle "Request email from users" (to enable it). 2. Fill in all required basic info fields and click Next. 12. Paste the URL copied from Step 2 in the Callback URI / Redirect URL field. 3. Fill in all required intended use fields and click Next. 13. Fill in other required and optional fields as desired. 4. Review the settings and click Next. 14. Click Save. 5. Carefully read the Developer Agreement, tick the acknowledgement box and click Submit. 6. Approval should be immediate. Navigate back to Projects & Apps and click the app name to return to the app settings page. 10. Under User authentication settings click Set up. 11. Toggle "OAuth 1.0a" (to enable it). 12. Optionally toggle "Request email from users" (to enable it). 13. Paste the URL copied from Step 2 in the Callback URI / Redirect URL field. 14. Fill in other required and optional fields as desired. 15. Click Save. In Drupal: Loading src/Controller/TwitterAuthController.php +22 −5 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\social_auth_twitter\Controller; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Logger\LoggerChannelFactory; use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\RendererInterface; Loading @@ -13,6 +14,7 @@ use Drupal\social_api\Plugin\NetworkManager; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; /** * Manages requests to Twitter API. Loading Loading @@ -83,7 +85,9 @@ class TwitterAuthController extends ControllerBase { * SocialAuthDataHandler object. * @param \Drupal\Core\Messenger\MessengerInterface $messenger * The messenger service. * @param \Drupal\Core\Render\RendererInterface $renderer * @param \Drupal\Core\Logger\LoggerChannelFactory $logger_factory * Logger factory. * @param \Drupal\Core\Render\RendererInterface|null $renderer * Used to handle metadata for redirection to authentication URL. */ public function __construct(NetworkManager $network_manager, Loading @@ -92,6 +96,7 @@ public function __construct(NetworkManager $network_manager, RequestStack $request, SocialAuthDataHandler $data_handler, MessengerInterface $messenger, LoggerChannelFactory $logger_factory, RendererInterface $renderer = NULL) { $this->networkManager = $network_manager; $this->userAuthenticator = $user_authenticator; Loading @@ -101,6 +106,8 @@ public function __construct(NetworkManager $network_manager, $this->messenger = $messenger; $this->renderer = $renderer; $this->setLoggerFactory($logger_factory); // Sets the plugin id. $this->userAuthenticator->setPluginId('social_auth_twitter'); Loading @@ -123,6 +130,7 @@ public static function create(ContainerInterface $container) { $container->get('request_stack'), $container->get('social_auth.data_handler'), $container->get('messenger'), $container->get('logger.factory'), $container->get('renderer') ); } Loading Loading @@ -221,17 +229,26 @@ public function callback() { // Gets user information. $user = $connection->get("account/verify_credentials", $params); // If user information could be retrieved. if ($user) { if ($connection->getLastHttpCode() === Response::HTTP_OK) { // Remove _normal from url to get a bigger profile picture. $picture = str_replace('_normal', '', $user->profile_image_url_https); $picture = $user->profile_image_url_https ?? NULL; if (!empty($picture)) { $picture = str_replace('_normal', '', $picture); } $name = $user->screen_name ?? $user->name ?? $user->id; $email = $user->email ?? ''; $data = json_decode(json_encode($user), TRUE); return $this->userAuthenticator->authenticateUser($name, $email, $user->id, json_encode($access_token), $picture, $data); } else { $this->getLogger('social_auth_twitter')->critical("Twitter account credentials verification failed with status code {$connection->getLastHttpCode()}."); $errors = $user->errors ?? []; foreach ($errors as $error) { $this->getLogger('social_auth_twitter')->critical("Error $error->code: $error->message"); } } $this->messenger->addError($this->t('You could not be authenticated, please contact the administrator.')); $this->messenger->addError($this->t('Authentication failed. Please contact a website administrator.')); return $this->redirect('user.login'); } Loading Loading
README.md +23 −6 Original line number Diff line number Diff line Loading @@ -68,17 +68,34 @@ In [Twitter Developer Portal](https://developer.twitter.com/portal): 8. Click App settings. 9. Under User authentication settings click Set up. 9. Ensure the app has [Elevated Access](https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#item0). 10. Toggle "OAuth 1.0a" (to enable it). 1. Click Apply next to the message "Do you need Elevated access for your Project?" if it appears. 11. Optionally toggle "Request email from users" (to enable it). 2. Fill in all required basic info fields and click Next. 12. Paste the URL copied from Step 2 in the Callback URI / Redirect URL field. 3. Fill in all required intended use fields and click Next. 13. Fill in other required and optional fields as desired. 4. Review the settings and click Next. 14. Click Save. 5. Carefully read the Developer Agreement, tick the acknowledgement box and click Submit. 6. Approval should be immediate. Navigate back to Projects & Apps and click the app name to return to the app settings page. 10. Under User authentication settings click Set up. 11. Toggle "OAuth 1.0a" (to enable it). 12. Optionally toggle "Request email from users" (to enable it). 13. Paste the URL copied from Step 2 in the Callback URI / Redirect URL field. 14. Fill in other required and optional fields as desired. 15. Click Save. In Drupal: Loading
src/Controller/TwitterAuthController.php +22 −5 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\social_auth_twitter\Controller; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Logger\LoggerChannelFactory; use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\RendererInterface; Loading @@ -13,6 +14,7 @@ use Drupal\social_api\Plugin\NetworkManager; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; /** * Manages requests to Twitter API. Loading Loading @@ -83,7 +85,9 @@ class TwitterAuthController extends ControllerBase { * SocialAuthDataHandler object. * @param \Drupal\Core\Messenger\MessengerInterface $messenger * The messenger service. * @param \Drupal\Core\Render\RendererInterface $renderer * @param \Drupal\Core\Logger\LoggerChannelFactory $logger_factory * Logger factory. * @param \Drupal\Core\Render\RendererInterface|null $renderer * Used to handle metadata for redirection to authentication URL. */ public function __construct(NetworkManager $network_manager, Loading @@ -92,6 +96,7 @@ public function __construct(NetworkManager $network_manager, RequestStack $request, SocialAuthDataHandler $data_handler, MessengerInterface $messenger, LoggerChannelFactory $logger_factory, RendererInterface $renderer = NULL) { $this->networkManager = $network_manager; $this->userAuthenticator = $user_authenticator; Loading @@ -101,6 +106,8 @@ public function __construct(NetworkManager $network_manager, $this->messenger = $messenger; $this->renderer = $renderer; $this->setLoggerFactory($logger_factory); // Sets the plugin id. $this->userAuthenticator->setPluginId('social_auth_twitter'); Loading @@ -123,6 +130,7 @@ public static function create(ContainerInterface $container) { $container->get('request_stack'), $container->get('social_auth.data_handler'), $container->get('messenger'), $container->get('logger.factory'), $container->get('renderer') ); } Loading Loading @@ -221,17 +229,26 @@ public function callback() { // Gets user information. $user = $connection->get("account/verify_credentials", $params); // If user information could be retrieved. if ($user) { if ($connection->getLastHttpCode() === Response::HTTP_OK) { // Remove _normal from url to get a bigger profile picture. $picture = str_replace('_normal', '', $user->profile_image_url_https); $picture = $user->profile_image_url_https ?? NULL; if (!empty($picture)) { $picture = str_replace('_normal', '', $picture); } $name = $user->screen_name ?? $user->name ?? $user->id; $email = $user->email ?? ''; $data = json_decode(json_encode($user), TRUE); return $this->userAuthenticator->authenticateUser($name, $email, $user->id, json_encode($access_token), $picture, $data); } else { $this->getLogger('social_auth_twitter')->critical("Twitter account credentials verification failed with status code {$connection->getLastHttpCode()}."); $errors = $user->errors ?? []; foreach ($errors as $error) { $this->getLogger('social_auth_twitter')->critical("Error $error->code: $error->message"); } } $this->messenger->addError($this->t('You could not be authenticated, please contact the administrator.')); $this->messenger->addError($this->t('Authentication failed. Please contact a website administrator.')); return $this->redirect('user.login'); } Loading