From ccf9b536c29dcd778bac0ffef2de6ebff400fb80 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Fri, 15 Feb 2019 15:31:00 -0800 Subject: [PATCH] Pass additional user data with all PBS fields. --- src/Controller/PbsAuthController.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Controller/PbsAuthController.php b/src/Controller/PbsAuthController.php index c4d90e3..2bb4654 100644 --- a/src/Controller/PbsAuthController.php +++ b/src/Controller/PbsAuthController.php @@ -2,6 +2,7 @@ namespace Drupal\social_auth_pbs\Controller; +use Drupal\Component\Serialization\Json; use Drupal\Core\Messenger\MessengerInterface; use Drupal\social_api\Plugin\NetworkManager; use Drupal\social_auth\Controller\OAuth2ControllerBase; @@ -16,6 +17,13 @@ */ class PbsAuthController extends OAuth2ControllerBase { + /** + * The JSON Serialize servicer. + * + * @var \Drupal\Component\Serialization\Json + */ + protected $jsonSerializer; + /** * PbsAuthController constructor. * @@ -31,13 +39,16 @@ class PbsAuthController extends OAuth2ControllerBase { * Used to access GET parameters. * @param \Drupal\social_auth\SocialAuthDataHandler $data_handler * SocialAuthDataHandler object. + * @param \Drupal\Component\Serialization\Json $json_serializer + * Used to serialize additional data. */ public function __construct(MessengerInterface $messenger, NetworkManager $network_manager, UserAuthenticator $user_authenticator, PbsAuthManager $pbs_auth_manager, RequestStack $request, - SocialAuthDataHandler $data_handler) { + SocialAuthDataHandler $data_handler, + Json $json_serializer) { parent::__construct( 'Social Auth PBS', @@ -49,6 +60,7 @@ public function __construct(MessengerInterface $messenger, $request, $data_handler ); + $this->jsonSerializer = $json_serializer; } /** @@ -61,7 +73,8 @@ public static function create(ContainerInterface $container) { $container->get('social_auth.user_authenticator'), $container->get('social_auth_pbs.manager'), $container->get('request_stack'), - $container->get('social_auth.data_handler') + $container->get('social_auth.data_handler'), + $container->get('serialization.json') ); } @@ -84,7 +97,8 @@ public function callback() { $profile->getEmail(), $profile->getId(), $this->providerManager->getAccessToken(), - $profile->getThumbnailUrl() + $profile->getThumbnailUrl(), + $this->jsonSerializer->encode($profile->toArray()) ); }