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

I started implementing HWIOAuthBundle and want to create my own custom resource. However, I do not know about the structure of the file / directory.

Where do I need to place my files to use the package?

+6
source share
3 answers

I redefined the owner of the HWIOAuthBundle linkedin resource because I needed to handle connection exceptions. You can use the compiler pass for 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 kit:

 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 package redefinition: http://symfony.com/doc/current/cookbook/bundles/override.html

+4
source

It seems that the Bundle does not support its own resource owners without directly editing the package (this is at first glance, I never used this package).

The oauth.xml file ( https://github.com/hwi/HWIOAuthBundle/blob/master/Resources/config/oauth.xml ) refers to each of the existing resource owners, so I think you can take a look at one of those which are linked here, which would be a good starting point.

0
source

According to the package documentation you can do this.

I believe I am using the GenericOauth2ResourceOwner class located in the package providers directory HWI \ Bundle \ OAuthBundle \ OAuth \ ResourceOwner.

0
source

Source: https://habr.com/ru/post/947089/


All Articles