我正在将用Symfony 2.8.5编写的应用程序升级到Symfony 3.4
我想使用hwi / oauth-bundle来保持omuth Facebook / Google登录Symfony 3.4。 (我的oauth登录正在使用Symfony 2.8.5 FOSUserBundle) 现在我收到了这个错误:
Cannot autowire service "App\Security\Core\User\OAuthUserProvider": argument "$properties" of method "__construct()" must have a type-hint or be given a value explicitly.
这是我的UserProviderClass,扩展了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;
}
这是我的services.yaml:
app.provider.oauth:
class: App\Security\Core\User\OAuthUserProvider
arguments: ['@fos_user.user_manager',{facebook: 'myFacebookId', google: 'myGoogleId'},'@mailer','@service_container']
这是我的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
我真的不明白,因为在我的services.yaml中我将所有参数定义为甚至属性作为数组... 我想在Symfony 3.4中不再支持hwi / oauth-bundle和fos / user-bundle。
答案 0 :(得分:1)
在您的Security
值中添加exclude
:
# config/services.yaml
services:
_defaults:
# ...
App\:
resource: '../src/*'
exclude: '../src/{Entity,Security,Migrations,Tests}'
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
...