我根据互联网上的文档和资源做了。但它没有将用户重定向到default_target_path
指定的
这是我的security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
secured_area:
pattern: ^/user
anonymous: ~
oauth:
remember_me: true
resource_owners:
facebook: "/user/login/check-facebook"
# google: "/login/check-google"
# my_custom_provider: "/login/check-custom"
login_path: /user/login
check_path: /user/connect
use_forward: false
failure_path: /user/login
default_target_path: /user/like
provider: fos_userbundle
oauth_user_provider:
# oauth: ~
service: hwi_oauth.user.provider.fosub_bridge
logout: true
access_control:
- { path: ^/user/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/connect, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user(.*), roles: ROLE_USER }
和config.yml
是
hwi_oauth:
# name of the firewall in which this bundle is active, this setting MUST be set
firewall_name: secured_area
connect:
confirmation: true
resource_owners:
facebook:
type: facebook
client_id: id
client_secret: secret
scope: "email user_birthday"
paths:
email: email
birthday: user_birthday
fosub:
# try 30 times to check if a username is available (foo, foo1, foo2 etc)
username_iterations: 30
# mapping between resource owners (see below) and properties
properties:
facebook: fbID
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Auth\UserBundle\Entity\User
最后它将我重定向到,
http://myurl/user/connect/service/facebook?key=1415715954
并将输出文字显示为 header.success
我该怎么办?
答案 0 :(得分:0)
那里有错字,简单的错误。正如@StivenLlup在评论中建议的那样,
我改变了
access_control:
- { path: ^/user/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/connect, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user(.*), roles: ROLE_USER } # changed this
到
access_control:
- { path: ^/user/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/connect, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/, roles: ROLE_USER } # to this
如果HWIOauthBundle服务找不到像/user/like
那样重定向的正确路径,则会出现此问题
如果指定路径的控制器中存在错误,那么正确的重定向也不起作用
在access_control
中添加正确的路径解决了它。