【问题标题】:Hwi oauth bundle and Symfony 3.4 Cannot autowire service : How to use hwi/oauth-bundle in symfony 3.4 + FOSUserBundleHwi oauth bundle 和 Symfony 3.4 无法自动装配服务:如何在 symfony 3.4 + FOSUserBundle 中使用 hwi/oauth-bundle
【发布时间】:2018-10-10 13:00:43
【问题描述】:

我正在将一个用 Symfony 2.8.5 编写的应用程序升级到 Symfony 3.4

我想使用 hwi/oauth-bundle 在 Symfony 3.4 中保持 oauth Facebook / Google 登录。 (我的 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 中,我将所有需要的参数甚至属性定义为一个数组...... 我猜 hwi/oauth-bundle 和 fos/user-bundle 在 Symfony 3.4 中都不再被官方支持了。

【问题讨论】:

    标签: symfony dependency-injection fosuserbundle type-hinting hwioauthbundle


    【解决方案1】:

    在您的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']
    ...

    【讨论】:

      猜你喜欢
      • 2019-06-02
      • 2018-11-02
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      • 1970-01-01
      • 2019-09-10
      • 2018-08-05
      • 1970-01-01
      相关资源
      最近更新 更多