n00b
n00b

Reputation: 16536

Symfony 2 | HWIOAuthBundle - How to create custom resource owner?

I started to implement HWIOAuthBundle and want to create my own custom resource owner. However I'm unclear about the file/directory structure.

Where would I need to place my files to take advantage of the bundle?

Upvotes: 6

Views: 2088

Answers (3)

jimconte
jimconte

Reputation: 145

I overrode the HWIOAuthBundle linkedin resource owner, because I needed to handle connection exceptions. You can use a compiler pass to do this:

namespace UserAccountBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class OverrideServiceCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        $definition = $container->getDefinition('hwi_oauth.resource_owner.linkedin');
        $definition->setClass('UserAccountBundle\OAuth\MyLinkedInResourceOwner');
    }
}

Then in your bundle:

namespace UserAccountBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use UserAccountBundle\DependencyInjection\Compiler\OverrideServiceCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class UserAccountBundle extends Bundle
{

    public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new OverrideServiceCompilerPass());
    }
}

More on bundle overrides: http://symfony.com/doc/current/cookbook/bundles/override.html

Upvotes: 4

mirk
mirk

Reputation: 432

According to the bundle documentation you can do that.

I believe that is using the GenericOauth2ResourceOwner class located in vendor bundle directory HWI\Bundle\OAuthBundle\OAuth\ResourceOwner.

Upvotes: 0

james_tookey
james_tookey

Reputation: 905

It looks like the Bundle doesn't support custom resource owners without editing the bundle directly (this is just at first glance, I've never actually used this bundle).

The oauth.xml file (https://github.com/hwi/HWIOAuthBundle/blob/master/Resources/config/oauth.xml) links to each of the existing resource owners, so I guess you could take a look at one of the ones linked in here that would be a good starting point.

Upvotes: 0

Related Questions