symfony - Hwi oauth bundle 和 Symfony 3.4 无法自动装配服务:如何在 symfony 3.4 + FOSUserBundle 中使用 hwi/oauth-bundle
问题描述
我正在将用 Symfony 2.8.5 编写的应用程序升级到 Symfony 3.4
我想使用 hwi/oauth-bundle 在 Symfony 3.4 中保持 oauth Facebook / Google 登录。(我的 oauth 登录正在使用 FOSUserBundle 在 Symfony 2.8.5 上工作)现在我收到此错误:
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 中都不再受到官方支持。
解决方案
添加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']
...
推荐阅读
- angular - Angular,Promises:在批处理完成之前不要返回承诺
- android - E/LoadedApk:无法仅在 Android Q (API 29) 上实例化 appComponentFactory
- spinnaker - Spinnaker halyard 部署 - 覆盖 readinessprobe 配置
- javascript - 在 webgl 中旋转旋转轴
- amazon-web-services - 想使用 terraform 在一个 vpc 下创建两个 ec2 实例
- angular - RouterLink在第一次点击后不更新目标组件
- python - 使列表中每个 DataFrame 的每一列成为一个大列表中的自己的列表
- javascript - 如何访问对象内部数组中的值
- vue.js - 如何从 Vue.js 中另一个组件的方法渲染组件
- jquery - 如何使用 jquery 循环遍历多个分支 json 数组而不将结果限制为单个数组?