├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── DependencyInjection
├── Configuration.php
├── FOSTwitterExtension.php
└── Security
│ └── Factory
│ └── TwitterFactory.php
├── FOSTwitterBundle.php
├── README.md
├── Resources
├── config
│ ├── schema
│ │ └── twitter-1.0.xsd
│ ├── security.xml
│ └── twitter.xml
├── meta
│ └── LICENSE
└── views
│ ├── initialize.html.php
│ ├── initialize.html.twig
│ ├── setup.html.php
│ └── setup.html.twig
├── Security
├── Authentication
│ ├── Provider
│ │ ├── TwitterAnywhereProvider.php
│ │ └── TwitterProvider.php
│ └── Token
│ │ ├── TwitterAnywhereToken.php
│ │ └── TwitterUserToken.php
├── EntryPoint
│ └── TwitterAuthenticationEntryPoint.php
├── Exception
│ └── ConnectionException.php
├── Firewall
│ └── TwitterListener.php
└── User
│ └── UserManagerInterface.php
├── Services
└── Twitter.php
├── Templating
└── Helper
│ └── TwitterAnywhereHelper.php
├── Tests
├── DependencyInjection
│ └── FOSTwitterExtensionTest.php
├── autoload.php.dist
└── bootstrap.php
├── Twig
└── Extension
│ └── TwitterAnywhereExtension.php
├── composer.json
├── phpunit.xml.dist
└── vendor
└── vendors.php
/.gitignore:
--------------------------------------------------------------------------------
1 | phpunit.xml
2 | coverage
3 | vendor/symfony
4 | vendor/twig
5 | vendor/twitteroauth
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - 5.3
5 | - 5.4
6 |
7 | env:
8 | - SYMFONY_VERSION=v2.0.7
9 | - SYMFONY_VERSION=origin/2.0
10 |
11 | before_script: php vendor/vendors.php
12 |
13 | notifications:
14 | email:
15 | - friendsofsymfony-dev@googlegroups.com
16 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | This document details all changes between different versions of FOSTwitterBundle:
2 |
3 | 1.1
4 | ---
5 |
6 | - made user creation explicit by introducing a UserManagerInterface (this allows
7 | to create a user object if someone logs in through Twitter for the first time)
8 |
9 | 1.0
10 | ---
11 |
12 | Initial release
13 |
--------------------------------------------------------------------------------
/DependencyInjection/Configuration.php:
--------------------------------------------------------------------------------
1 |
7 | *
8 | * For the full copyright and license information, please view the LICENSE
9 | * file that was distributed with this source code.
10 | */
11 |
12 | namespace FOS\TwitterBundle\DependencyInjection;
13 |
14 | use Symfony\Component\Config\Definition\Builder\TreeBuilder,
15 | Symfony\Component\Config\Definition\ConfigurationInterface;
16 |
17 | /**
18 | * Configuration for the bundle
19 | */
20 | class Configuration implements ConfigurationInterface
21 | {
22 | /**
23 | * Generates the configuration tree.
24 | *
25 | * @return TreeBuilder
26 | */
27 | public function getConfigTreeBuilder()
28 | {
29 | $treeBuilder = new TreeBuilder();
30 | $rootNode = $treeBuilder->root('fos_twitter');
31 |
32 | $rootNode
33 | ->validate()
34 | ->always(function($v) {
35 | if (!empty($v['callback_url']) && !empty($v['callback_route'])) {
36 | throw new \Exception('You cannot configure a "callback_url", and a "callback_route" at the same time.');
37 | }
38 |
39 | return $v;
40 | })
41 | ->end()
42 | ->children()
43 | ->scalarNode('file')->defaultValue('%kernel.root_dir%/../vendor/twitteroauth/twitteroauth/twitteroauth.php')->end()
44 | ->scalarNode('consumer_key')->isRequired()->cannotBeEmpty()->end()
45 | ->scalarNode('consumer_secret')->isRequired()->cannotBeEmpty()->end()
46 | ->scalarNode('access_token')->defaultNull()->end()
47 | ->scalarNode('access_token_secret')->defaultNull()->end()
48 | ->scalarNode('callback_url')->defaultNull()->end()
49 | ->scalarNode('callback_route')->defaultNull()->end()
50 | ->scalarNode('anywhere_version')->defaultValue('1')->end()
51 | ->scalarNode('alias')->defaultNull()->end()
52 | ->end()
53 | ;
54 |
55 | return $treeBuilder;
56 | }
57 |
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/DependencyInjection/FOSTwitterExtension.php:
--------------------------------------------------------------------------------
1 |
7 | *
8 | * For the full copyright and license information, please view the LICENSE
9 | * file that was distributed with this source code.
10 | */
11 |
12 | namespace FOS\TwitterBundle\DependencyInjection;
13 |
14 | use Symfony\Component\DependencyInjection\Reference;
15 |
16 | use Symfony\Component\Config\Definition\Processor;
17 | use Symfony\Component\HttpKernel\DependencyInjection\Extension;
18 | use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
19 | use Symfony\Component\DependencyInjection\ContainerBuilder;
20 | use Symfony\Component\Config\FileLocator;
21 |
22 | class FOSTwitterExtension extends Extension
23 | {
24 | protected $resources = array(
25 | 'twitter' => 'twitter.xml',
26 | 'security' => 'security.xml',
27 | );
28 |
29 | public function load(array $configs, ContainerBuilder $container)
30 | {
31 | $processor = new Processor();
32 | $configuration = new Configuration();
33 | $config = $processor->processConfiguration($configuration, $configs);
34 |
35 | $this->loadDefaults($container);
36 |
37 | if (isset($config['alias'])) {
38 | $container->setAlias($config['alias'], 'fos_twitter.service');
39 | }
40 |
41 | foreach (array('file', 'consumer_key', 'consumer_secret', 'callback_url', 'access_token', 'access_token_secret', 'anywhere_version') as $attribute) {
42 | if (isset($config[$attribute])) {
43 | $container->setParameter('fos_twitter.'.$attribute, $config[$attribute]);
44 | }
45 | }
46 |
47 | if (!empty($config['callback_route'])) {
48 | $container
49 | ->getDefinition('fos_twitter.service')
50 | ->addMethodCall('setCallbackRoute', array(
51 | new Reference('router'),
52 | $config['callback_route'],
53 | ))
54 | ;
55 | }
56 | }
57 |
58 | /**
59 | * @codeCoverageIgnore
60 | */
61 | public function getXsdValidationBasePath()
62 | {
63 | return __DIR__.'/../Resources/config/schema';
64 | }
65 |
66 | /**
67 | * @codeCoverageIgnore
68 | */
69 | public function getNamespace()
70 | {
71 | return 'http://friendsofsymfony.github.com/schema/dic/twitter';
72 | }
73 |
74 | /**
75 | * @codeCoverageIgnore
76 | */
77 | protected function loadDefaults($container)
78 | {
79 | $loader = new XmlFileLoader($container, new FileLocator(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config')));
80 |
81 | foreach ($this->resources as $resource) {
82 | $loader->load($resource);
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/DependencyInjection/Security/Factory/TwitterFactory.php:
--------------------------------------------------------------------------------
1 |
7 | *
8 | * For the full copyright and license information, please view the LICENSE
9 | * file that was distributed with this source code.
10 | */
11 |
12 | namespace FOS\TwitterBundle\DependencyInjection\Security\Factory;
13 |
14 | use Symfony\Component\DependencyInjection\ContainerBuilder;
15 | use Symfony\Component\DependencyInjection\Reference;
16 | use Symfony\Component\DependencyInjection\DefinitionDecorator;
17 | use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory;
18 |
19 | class TwitterFactory extends AbstractFactory
20 | {
21 | public function __construct()
22 | {
23 | $this->addOption('use_twitter_anywhere', false);
24 | $this->addOption('create_user_if_not_exists', false);
25 | }
26 |
27 | public function getPosition()
28 | {
29 | return 'pre_auth';
30 | }
31 |
32 | public function getKey()
33 | {
34 | return 'fos_twitter';
35 | }
36 |
37 | protected function getListenerId()
38 | {
39 | return 'fos_twitter.security.authentication.listener';
40 | }
41 |
42 | protected function createAuthProvider(ContainerBuilder $container, $id, $config, $userProviderId)
43 | {
44 | // configure auth with Twitter Anywhere
45 | if (true === $config['use_twitter_anywhere']) {
46 | if (isset($config['provider'])) {
47 | $authProviderId = 'fos_twitter.anywhere_auth.'.$id;
48 |
49 | $container
50 | ->setDefinition($authProviderId, new DefinitionDecorator('fos_twitter.anywhere_auth'))
51 | ->addArgument(new Reference($userProviderId))
52 | ->addArgument(new Reference('security.user_checker'))
53 | ->addArgument($config['create_user_if_not_exists'])
54 | ;
55 |
56 | return $authProviderId;
57 | }
58 |
59 | // no user provider
60 | return 'fos_twitter.anywhere_auth';
61 | }
62 |
63 | // configure auth for standard Twitter API
64 | // with user provider
65 | if (isset($config['provider'])) {
66 | $authProviderId = 'fos_twitter.auth.'.$id;
67 |
68 | $container
69 | ->setDefinition($authProviderId, new DefinitionDecorator('fos_twitter.auth'))
70 | ->addArgument(new Reference($userProviderId))
71 | ->addArgument(new Reference('security.user_checker'))
72 | ->addArgument($config['create_user_if_not_exists'])
73 | ;
74 |
75 | return $authProviderId;
76 | }
77 |
78 | // without user provider
79 | return 'fos_twitter.auth';
80 | }
81 |
82 | protected function createListener($container, $id, $config, $userProvider)
83 | {
84 | $listenerId = parent::createListener($container, $id, $config, $userProvider);
85 |
86 | if ($config['use_twitter_anywhere']) {
87 | $container
88 | ->getDefinition($listenerId)
89 | ->addMethodCall('setUseTwitterAnywhere', array(true))
90 | ;
91 | }
92 |
93 | return $listenerId;
94 | }
95 |
96 | protected function createEntryPoint($container, $id, $config, $defaultEntryPointId)
97 | {
98 | $entryPointId = 'fos_twitter.security.authentication.entry_point.'.$id;
99 | $container
100 | ->setDefinition($entryPointId, new DefinitionDecorator('fos_twitter.security.authentication.entry_point'))
101 | ;
102 |
103 | return $entryPointId;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/FOSTwitterBundle.php:
--------------------------------------------------------------------------------
1 |
7 | *
8 | * For the full copyright and license information, please view the LICENSE
9 | * file that was distributed with this source code.
10 | */
11 |
12 | namespace FOS\TwitterBundle;
13 |
14 | use FOS\TwitterBundle\DependencyInjection\Security\Factory\TwitterFactory;
15 | use Symfony\Component\DependencyInjection\ContainerBuilder;
16 | use Symfony\Component\HttpKernel\Bundle\Bundle;
17 |
18 | class FOSTwitterBundle extends Bundle
19 | {
20 | public function build(ContainerBuilder $container)
21 | {
22 | parent::build($container);
23 |
24 | $extension = $container->getExtension('security');
25 | $extension->addSecurityListenerFactory(new TwitterFactory());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | DEPRECATED
2 | ==========
3 |
4 | See [HWIOAuthBundle](https://github.com/hwi/HWIOAuthBundle) instead
5 | -------------------------------------------------------------------
6 |
7 | Introduction
8 | ============
9 |
10 | This Bundle enables integration with Twitter PHP. Furthermore it
11 | also provides a Symfony2 authentication provider so that users can login to a
12 | Symfony2 application via Twitter. Furthermore via custom user provider support
13 | the Twitter login can also be integrated with other data sources like the
14 | database based solution provided by FOSUserBundle.
15 |
16 | ``If you are using Symfony 2.0 switch to the branch v1.0 of TwitterBundle or use the tag 1.0.0``
17 |
18 | [](http://travis-ci.org/FriendsOfSymfony/FOSTwitterBundle)
19 |
20 | Installation
21 | ============
22 |
23 | 1. Add this bundle and Abraham Williams' Twitter library to your project as Git submodules:
24 |
25 | $ git submodule add git://github.com/FriendsOfSymfony/FOSTwitterBundle.git vendor/bundles/FOS/TwitterBundle
26 | $ git submodule add git://github.com/kertz/twitteroauth.git vendor/twitteroauth
27 |
28 | >**Note:** The kertz/twitteroauth is patched to be compatible with FOSTwitterBundle
29 |
30 | 2. Register the namespace `FOS` to your project's autoloader bootstrap script:
31 |
32 | //app/autoload.php
33 | $loader->registerNamespaces(array(
34 | // ...
35 | 'FOS' => __DIR__.'/../vendor/bundles',
36 | // ...
37 | ));
38 |
39 | 3. Add this bundle to your application's kernel:
40 |
41 | //app/AppKernel.php
42 | public function registerBundles()
43 | {
44 | return array(
45 | // ...
46 | new FOS\TwitterBundle\FOSTwitterBundle(),
47 | // ...
48 | );
49 | }
50 |
51 | 4. Configure the `twitter` service in your YAML configuration:
52 |
53 | #app/config/config.yml
54 | fos_twitter:
55 | file: %kernel.root_dir%/../vendor/twitteroauth/twitteroauth/twitteroauth.php
56 | consumer_key: xxxxxx
57 | consumer_secret: xxxxxx
58 | callback_url: http://www.example.com/login_check
59 |
60 | 5. Add the following configuration to use the security component:
61 |
62 | #app/config/security.yml
63 | security:
64 | providers:
65 | fos_twitter:
66 | id: fos_twitter.auth
67 | firewalls:
68 | secured:
69 | pattern: /secured/.*
70 | fos_twitter: true
71 | public:
72 | pattern: /.*
73 | anonymous: true
74 | fos_twitter: true
75 | logout: true
76 | access_control:
77 | - { path: /.*, role: [IS_AUTHENTICATED_ANONYMOUSLY] }
78 |
79 | Using Twitter @Anywhere
80 | -----------------------
81 |
82 | >**Note:** If you want the Security Component to work with Twitter @Anywhere, you need to send a request to the configured check path upon successful client authentication (see https://gist.github.com/1021384 for a sample configuration).
83 |
84 | A templating helper is included for using Twitter @Anywhere. To use it, first
85 | call the `->setup()` method toward the top of your DOM:
86 |
87 |
88 | setup() ?>
89 |
90 |
91 |
92 | {{ twitter_anywhere_setup() }}
93 |
94 |
95 | Once that's done, you can queue up JavaScript to be run once the library is
96 | actually loaded:
97 |
98 |
99 |
100 | setConfig('callbackURL', 'http://www.example.com/login_check') ?>
101 | queue('T("#twitter_connect").connectButton()') ?>
102 |
103 |
104 |
105 | {{ twitter_anywhere_setConfig('callbackURL', 'http://www.example.com/login_check') }}
106 | {{ twitter_anywhere_queue('T("#twitter_connect").connectButton()') }}
107 |
108 | Finally, call the `->initialize()` method toward the bottom of the DOM:
109 |
110 |
111 | initialize() ?>
112 |