Hwi oauth bundle 和 Symfony 3.4 无法自动装配服务:How to use hwi/oauth-bundle in symfony 3.4 + FOSUserBundle
Hwi oauth bundle and Symfony 3.4 Cannot autowire service : How to use hwi/oauth-bundle in symfony 3.4 + FOSUserBundle
我正在将一个用 Symfony 2.8.5 编写的应用程序升级到 Symfony 3.4
我想使用 hwi/oauth-bundle 在 Symfony 3.4 中保留 oauth Facebook / Google 登录。 (我的 oauth 登录在 Symfony 2.8.5 上工作
FOS用户包)
现在我得到这个错误:
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 中,我将所有需要的参数甚至属性定义为一个数组...
我想 hwi/oauth-bundle 和 fos/user-bundle 都不再被 Symfony 3.4 正式支持。
在您的 exclude
值中添加 Security
:
# config/services.yaml
services:
_defaults:
# ...
App\:
resource: '../src/*'
exclude: '../src/{Entity,Security,Migrations,Tests}'
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
...
我正在将一个用 Symfony 2.8.5 编写的应用程序升级到 Symfony 3.4
我想使用 hwi/oauth-bundle 在 Symfony 3.4 中保留 oauth Facebook / Google 登录。 (我的 oauth 登录在 Symfony 2.8.5 上工作 FOS用户包) 现在我得到这个错误:
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 中,我将所有需要的参数甚至属性定义为一个数组... 我想 hwi/oauth-bundle 和 fos/user-bundle 都不再被 Symfony 3.4 正式支持。
在您的 exclude
值中添加 Security
:
# config/services.yaml
services:
_defaults:
# ...
App\:
resource: '../src/*'
exclude: '../src/{Entity,Security,Migrations,Tests}'
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
...