. */ namespace vierbergenlars\AuthserverOAuthAccountBundle\ExternalAccount; use HWI\Bundle\OAuthBundle\Security\OAuthUtils; use Symfony\Component\HttpFoundation\Request; use vierbergenlars\AuthserverExternalAccountBundle\ExternalAccount\ExternalAccountProviderInterface; use vierbergenlars\AuthserverExternalAccountBundle\ValueObject\Button; use vierbergenlars\AuthserverOAuthAccountBundle\ResourceOwner\ResourceOwnerConfig; use vierbergenlars\AuthserverOAuthAccountBundle\ResourceOwner\ResourceOwnerMap; class OAuthExternalAccountProvider implements ExternalAccountProviderInterface { /** * * @var ResourceOwnerConfig */ private $resourceOwnerConfig; /** * * @var */ private $name; /** * * @var OAuthUtils */ private $OAuthUtils; public function __construct($name, ResourceOwnerMap $resourceOwnerMap, OAuthUtils $OAuthUtils) { $this->resourceOwnerConfig = $resourceOwnerMap[$name]; $this->name = $name; $this->OAuthUtils = $OAuthUtils; } public function getName() { return 'oauth_' . $this->name; } public function getServiceName() { return $this->resourceOwnerConfig->getServiceName(); } public function getIcon() { return $this->resourceOwnerConfig->getIcon(); } public function getLoginButton() { return new Button($this->resourceOwnerConfig->getLoginButton() + [ 'url' => $this->OAuthUtils->getLoginUrl(new Request(), $this->name) ]); } public function getConnectButton() { return new Button($this->resourceOwnerConfig->getConnectButton() + [ 'url' => $this->OAuthUtils->getLoginUrl(new Request(), $this->name) ]); } public function hasConnect() { return true; } public function hasDisconnect() { return true; } public function supports($externalProviderData) { return true; } }