2

I have a problem with FOSUserBundle and HWIOauthBundle. I use custom UserChecker to check whether user is banned (custom table in database as I need a ban history). When I use Facebook to log-in my CustomChecker is not used. It does work when I'm using login and password as authentication.

Issue on GitHub: https://github.com/hwi/HWIOAuthBundle/issues/1358

Anyone has an idea how to fix that?

nass
  • 382
  • 1
  • 6
  • 19

2 Answers2

1

from the docs

Services & Configuration

If you want to modify service definitions of another bundle, you can use a compiler pass to change the class of the service or to modify method calls. In the following example, the implementing class for the original-service-id is changed to App\YourService:

// src/Kernel.php
namespace App;

// ...
+ use App\Service\YourService;
+ use Symfony\Component\DependencyInjection\ContainerBuilder;
+ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

class Kernel extends BaseKernel implements CompilerPassInterface
{
+     public function process(ContainerBuilder $container)
+     {
+         $definition = $container->findDefinition('original-service-id');
+         $definition->setClass(YourService::class);
+     }
}
Denis Alimov
  • 2,861
  • 1
  • 18
  • 38
  • 1
    There is no need to do this in your Kernel. You can override the service within `services.yml` or any other format you use. @simivar If you think overriding HWIO user checker / security checker might help, you can override it by defining your *Checker class as a service. I would guess this is the id of the checker `security.authorization_checker` – domagoj Mar 27 '18 at 18:41
  • @domagoj03 I am not sure that you can override bundle service in `services.yml` – Denis Alimov Mar 28 '18 at 02:46
  • I am sure you can :) Despite the fact that half of my code is run this way, I tried it again to make sure and yeah, you can override (any, probably) service with your own simply by giving it the same Id - the lowercase, snakecase definition, within `services.yml`, within any registered bundle. – domagoj Mar 28 '18 at 06:36
0

I confirm, the solution of @Domagoj work for Symfony 3.4.

# app/config/services.yml
services:
...
    security.user_checker:
        class: AppBundle\Service\YourUserChecker

With this code, the hwi.user_checker is override by your UserChecker.

Thanks.

Alexdu98
  • 35
  • 5