From ac1cd4f5ad63fd0b1d47d0962a43830c2a1f0d4f Mon Sep 17 00:00:00 2001 From: Lee McDermott Date: Wed, 17 Oct 2012 12:50:44 +0100 Subject: [PATCH 1/2] Can now specify route params in setCallbackRoute --- Services/Twitter.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Services/Twitter.php b/Services/Twitter.php index 16f3a48..1de26c7 100644 --- a/Services/Twitter.php +++ b/Services/Twitter.php @@ -24,6 +24,7 @@ class Twitter private $session; private $router; private $callbackRoute; + private $callbackRouteParams; private $callbackURL; public function __construct(TwitterOAuth $twitter, Session $session, $callbackURL = null) @@ -33,10 +34,11 @@ public function __construct(TwitterOAuth $twitter, Session $session, $callbackUR $this->callbackURL = $callbackURL; } - public function setCallbackRoute(RouterInterface $router, $routeName) + public function setCallbackRoute(RouterInterface $router, $routeName, $routeParams = array()) { $this->router = $router; $this->callbackRoute = $routeName; + $this->callbackRouteParams = $routeParams; } public function getLoginUrl() @@ -104,7 +106,7 @@ private function getCallbackUrl() } if (!empty($this->callbackRoute)) { - return $this->router->generate($this->callbackRoute, array(), true); + return $this->router->generate($this->callbackRoute, $this->callbackRouteParams, true); } return null; From a3f17a285825045704593958af083c48b43ecb1c Mon Sep 17 00:00:00 2001 From: Lee McDermott Date: Tue, 5 Feb 2013 02:19:57 +0000 Subject: [PATCH 2/2] Issue IncompleteUserToken if user profile fails validation --- Resources/config/security.xml | 1 + .../Authentication/Provider/TwitterProvider.php | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Resources/config/security.xml b/Resources/config/security.xml index 3e10800..5b01775 100644 --- a/Resources/config/security.xml +++ b/Resources/config/security.xml @@ -7,6 +7,7 @@ + diff --git a/Security/Authentication/Provider/TwitterProvider.php b/Security/Authentication/Provider/TwitterProvider.php index 0412944..b8343ca 100644 --- a/Security/Authentication/Provider/TwitterProvider.php +++ b/Security/Authentication/Provider/TwitterProvider.php @@ -22,9 +22,11 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface; use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\Validator\ValidatorInterface; use FOS\TwitterBundle\Security\Authentication\Token\TwitterUserToken; use FOS\TwitterBundle\Services\Twitter; +use FOS\UserBundle\Security\Authentication\Token\IncompleteUserToken; class TwitterProvider implements AuthenticationProviderInterface { @@ -32,8 +34,9 @@ class TwitterProvider implements AuthenticationProviderInterface private $userProvider; private $userChecker; private $createUserIfNotExists; + private $validator; - public function __construct(Twitter $twitter, UserProviderInterface $userProvider = null, UserCheckerInterface $userChecker = null, $createUserIfNotExists = false) + public function __construct(Twitter $twitter, ValidatorInterface $validator, UserProviderInterface $userProvider = null, UserCheckerInterface $userChecker = null, $createUserIfNotExists = false) { if (null !== $userProvider && null === $userChecker) { throw new \InvalidArgumentException('$userChecker cannot be null, if $userProvider is not null.'); @@ -47,6 +50,7 @@ public function __construct(Twitter $twitter, UserProviderInterface $userProvide $this->userProvider = $userProvider; $this->userChecker = $userChecker; $this->createUserIfNotExists = $createUserIfNotExists; + $this->validator = $validator; } public function authenticate(TokenInterface $token) @@ -106,6 +110,13 @@ private function createAuthenticatedToken(array $accessToken) throw new \RuntimeException('User provider did not return an implementation of user interface.'); } - return new TwitterUserToken($user, null, $user->getRoles()); + $errors = $this->validator->validate($user, array('Profile')); + + if (count($errors) > 0) { + $user->setIncomplete(true); + return new IncompleteUserToken('', $user, $user->getRoles()); + } else { + return new TwitterUserToken($user, null, $user->getRoles()); + } } }