6

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?

j0k
  • 22,600
  • 28
  • 79
  • 90
n00b
  • 16,088
  • 21
  • 56
  • 72

3 Answers3

4

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

jimconte
  • 127
  • 4
0

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.

james_tookey
  • 885
  • 6
  • 12
0

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.

mirk
  • 442
  • 4
  • 13