12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace AuthBundle\Security\Authentication\Provider;
- use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
- 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) {
- $authenticatedToken = new UsernamePasswordToken($user, null, "api", $user->getRoles());
- $authenticatedToken->setUser($user);
-
- return $authenticatedToken;
- }
- throw new AuthenticationException('The OAuth authentication failed.');
- }
- /**
- * @param TokenInterface $token
- *
- * @return boolean
- */
- public function supports(TokenInterface $token)
- {
- return $token instanceof UsernamePasswordToken;
- }
- }
|