我想使用 FOSFacebookBundle 和 FOSUserBundle 来管理:
- 带有 facebook 连接的前台
- 具有经典登录名/密码的管理员用户的后台(此处没有 facebook 连接!)
我使用 Propel 作为 ORM 和 AdminGeneratorGeneratorBundle 来管理后台。我已经覆盖了 FOSUserBundle 的推进器 schema.yml 文件以添加特定的“facebook 字段”。
该过程在前面工作正常,但是当我尝试访问“/admin”网址时,它无法正常工作。我有“登录”页面,但是当我输入登录名/密码时,我正在重定向到 facebook 连接页面......
只是配置文件配置错误,还是我以错误的方式满足了我的需求?
这是我的配置文件:
安全.yml
security:
providers:
fos_userbundle:
id: fos_user.user_provider.username
fos_facebook_provider:
id: my.facebook.user
encoders:
FOS\UserBundle\Model\UserInterface: sha512
firewalls:
# Firewall public / FB Connect
public:
# since anonymous is allowed users will not be forced to login
pattern: ^/.*
fos_facebook:
provider: fos_facebook_provider
app_url: "http://apps.facebook.com/fb-localhost-testing/"
server_url: "http://localhost/fb-localhost-testing/"
anonymous: true
# Firewall zone admin
admin_area:
pattern: ^/admin
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
login_path: /admin/login
check_path: /admin/login_check
default_target_path: /admin/
logout:
path: /admin/logout
target: /admin/login
anonymous: true
access_control:
- { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
- { path: ^/connected/.*, role: [ROLE_FACEBOOK] }
- { path: ^/.*, role: [IS_AUTHENTICATED_ANONYMOUSLY] }
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
配置.yml
# FOSUser Configuration
fos_user:
user_class: FOS\UserBundle\Propel\User
db_driver: propel
firewall_name: main
# FOSFacebook Configuration
fos_facebook:
alias: fb-localhost-testing
app_id: mmyid
secret: mysecret
cookie: true
permissions: [email, user_birthday, user_location]
services:
my.facebook.user:
class: MyProject\Security\User\Provider\FacebookProvider
arguments:
facebook: "@fos_facebook.api"
userManager: "@fos_user.user_manager"
validator: "@validator"