I'm upgrading an application written in Symfony 2.8.5 to Symfony 3.4
I would like to use hwi/oauth-bundle to keep the oauth Facebook / Google login in Symfony 3.4. (My oauth login was working on Symfony 2.8.5 with FOSUserBundle ) Now I get this error:
Cannot autowire service "App\Security\Core\User\OAuthUserProvider": argument "$properties" of method "__construct()" must have a type-hint or be given a value explicitly.
This is my UserProviderClass extending FOSUSBUserProvider :
namespace App\Security\Core\User;
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
use HWI\Bundle\OAuthBundle\Security\Core\User\FOSUBUserProvider as BaseClass;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\UserChecker;
use Symfony\Component\Security\Core\User\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
/**
* Class OAuthUserProvider
* @package AppBundle\Security\Core\User
*/
class OAuthUserProvider extends BaseClass {
private $mailer;
private $container;
public function __construct(UserManagerInterface $userManager,array $properties, $mailer, $container) {
parent::__construct($userManager, $properties);
$this->mailer = $mailer;
$this->container = $container;
}
This is my services.yaml:
app.provider.oauth:
class: App\Security\Core\User\OAuthUserProvider
arguments: ['@fos_user.user_manager',{facebook: 'myFacebookId', google: 'myGoogleId'},'@mailer','@service_container']
This is my security.yaml:
security:
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
in_memory: { memory: ~ }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: true
oauth:
resource_owners:
facebook: "/login/check-facebook"
google: "/login/check-google"
failure_path: /login
use_forward: false
login_path: /login
check_path: /connect_check
#provider: fos_userbundle # is oauth:provider is supported in symfony 3.4 ???
success_handler: redirect.after.login
oauth_user_provider:
service: app.provider.oauth
encoders:
App\Entity\User\User:
algorithm: bcrypt
I really don't understand because in my services.yaml I'm defining all arguments required even properties as an array ... I guess hwi/oauth-bundle and fos/user-bundle are both not anymore officialy supported in Symfony 3.4.
Add Security
in your exclude
value:
# config/services.yaml
services:
_defaults:
# ...
App\:
resource: '../src/*'
exclude: '../src/{Entity,Security,Migrations,Tests}'
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
...