Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Resources/config/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<services>
<service id="fos_twitter.auth" class="FOS\TwitterBundle\Security\Authentication\Provider\TwitterProvider" public="false">
<argument type="service" id="fos_twitter.service"/>
<argument type="service" id="validator"/>
</service>

<service id="fos_twitter.anywhere_auth" class="FOS\TwitterBundle\Security\Authentication\Provider\TwitterAnywhereProvider" public="false">
Expand Down
15 changes: 13 additions & 2 deletions Security/Authentication/Provider/TwitterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@
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
{
private $twitter;
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.');
Expand All @@ -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)
Expand Down Expand Up @@ -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());
}
}
}
6 changes: 4 additions & 2 deletions Services/Twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -108,7 +110,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;
Expand Down