123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace AuthBundle\Security\Authentication\Provider;
- use HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken;
- use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
- use Symfony\Component\Security\Core\User\UserProviderInterface;
- use Symfony\Component\Security\Core\Exception\AuthenticationException;
- use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
- class OAuthProxyProvider implements AuthenticationProviderInterface
- {
- /**
- * @var UserProviderInterface
- */
- private $userProvider;
- /**
- * @param UserProviderInterface $userProvider
- */
- public function __construct(UserProviderInterface $userProvider)
- {
- $this->userProvider = $userProvider;
- }
- /**
- * @param TokenInterface $token
- *
- * @return OAuthToken
- *
- * @throws AuthenticationException
- */
- public function authenticate(TokenInterface $token)
- {
- $user = $token->getUser();
- if ($user) {
- $token->setAuthenticated(true);
-
- return $token;
- }
- throw new AuthenticationException('The OAuth authentication failed.');
- }
- /**
- * @param TokenInterface $token
- *
- * @return boolean
- */
- public function supports(TokenInterface $token)
- {
- return $token instanceof OAuthToken;
- }
- }
|