所以基本上,我正在尝试在 Symfony 中使用 FOSUserBundle 实现 FOSFacebookBundle。我遵循了 FOSFacebookBundle 2.0 分支的自述文件,但现在我遇到了这个错误。任何想法 ?
错误 :
Catchable Fatal Error: Argument 2 passed to FOS\FacebookBundle\Security\Authentication\Provider\FacebookProvider::__construct()
must implement interface Symfony\Component\Security\Core\User\UserProviderInterface,
instance of FOS\FacebookBundle\Security\Authentication\Provider\FacebookProvider given,
called in /var/www/Symfony/app/cache/dev/appDevDebugProjectContainer.php on line 2434
and defined in /var/www/Symfony/vendor/bundles/FOS/FacebookBundle/Security/Authentication/Provider/FacebookProvider.php line 37
security.yml(安全部分):
factories:
- "%kernel.root_dir%/../vendor/bundles/FOS/FacebookBundle/Resources/config/security_factories.xml"
providers:
chain_provider:
providers: [fos_userbundle, fos_facebook]
fos_userbundle:
id: fos_user.user_manager
fos_facebook:
id: fos_facebook.auth
encoders:
"FOS\UserBundle\Model\UserInterface": sha512
firewalls:
main:
pattern: .*
fos_facebook:
provider: fos_facebook
app_url: "to_do"
server_url: "to_do"
default_target_path: /
form_login:
provider: fos_userbundle
login_path: /login
use_forward: false
check_path: /login_check
failure_path: null
default_target_path: /
logout:
path: /logout
target: /
anonymous: true
access_control:
- { path: /admin/.*, role: ROLE_ADMIN }
- { path: /video/.*, role: ROLE_USER }
- { path: /$, role: IS_AUTHENTICATED_ANONYMOUSLY }
config.yml 的相关部分:
fos_user:
db_driver: orm
firewall_name: main
use_listener: false
user_class: Projectname\UserBundle\Entity\User
registration:
form:
type: projectname_user_registration
service:
user_manager: projectname_user.my_user_manager
fos_facebook:
file: %kernel.root_dir%/../vendor/facebook/src/base_facebook.php
alias: facebook
app_id: %projectname_bundle.facebook.app_id%
secret: %projectname_bundle.facebook.secret%
cookie: true
permissions: %projectname_bundle.facebook.perms%
MyUserManager.php(已修改,因此我可以使用电子邮件地址作为 FOSUserbundle 的用户名。不知道它是否真的相关,但错误告诉我传递给 FacebookProvider 构造函数的第二个参数有问题,并且这个参数应该是成为用户管理器):
<?php
namespace ProjectName\UserBundle\Model;
use FOS\UserBundle\Entity\UserManager;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
class MyUserManager extends UserManager
{
public function loadUserByUsername($username)
{
$user = $this->findUserByUsernameOrEmail($username);
if (!$user) {
throw new UsernameNotFoundException(sprintf('No user with email "%s" was found.', $username));
}
return $user;
}
}