我可以根据danvbe的文档集成fosuserbundle和hwioauthbundle . 我可以通过用户名/密码,脸书和推特登录 . 我也可以将用户名连接到他的facebook / twitter帐户 . 例如,在用户 Profiles 页面,我尝试将我的用户名与我的Facebook帐户相关联 . 连接后,我卡在页面上(网址:http://localhost/Projects/symfony/web/app_dev.php/connect/service/facebook?key=12345678),页面上显示一条消息'Successfully connected the account '我的帐号'!' . 没有按钮可以重定向到任何地方 . 如何重定向到用户 Profiles 页面?以下是我的设置:security.yml:
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
login_path: /login
csrf_provider: form.csrf_provider
logout: true
anonymous: true
oauth:
resource_owners:
facebook: "/login/check-facebook"
twitter: "/login/check-twitter"
login_path: /login
use_forward: false
failure_path: /login
default_target_path: /profile
oauth_user_provider:
service: tf_user_provider
routing.yml中:
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
hwi_oauth_redirect:
resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
prefix: /connect
hwi_oauth_login:
resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
prefix: /login
hwi_oauth_connect:
resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
prefix: /connect
hwi_oauth_facebook_login:
pattern: /connect/facebook
facebook_login:
pattern: /login/check-facebook
twitter_login:
pattern: /login/check-twitter
config.yml:
fos_user:
db_driver: orm
firewall_name: main
user_class: Acme\UserBundle\Entity\User
registration:
form:
type: tf_user_registration
profile:
form:
type: tf_user_registration
hwi_oauth:
firewall_name: main
resource_owners:
facebook:
type: facebook
client_id: "id"
client_secret: "secret"
scope: ""
twitter:
type: twitter
client_id: "id"
client_secret: "secret"
fosub:
# try 30 times to check if a username is available
username_iterations: 30
#mapping between resource owners and properties
properties:
facebook: facebookId
twitter: twitterId
# if you want to use 'connect' and do not use the FOSUB integration, configure these separately
connect:
account_connector: tf_user_provider
confirmation: true # should show confirmation page or not
# optional HTTP Client configuration
http_client:
timeout: 100
verify_peer: true
ignore_errors: true
max_redirects: 5
3 回答
HWIOAuthBundle没有这样的功能 .
最简单的解决方案是在vendor / hwi / oauth-bundle / HWI / Bundle / OAuthBundle / Resources / views / Connect / connect_success.html.twig模板中进行javascript重定向 .
或者这个解决方案(不是最好的解决方案,但对我来说很好)
Generate new empty OAuthBundle
php app/console generate:bundle
Override HWIOAuthBundle
Override ConnectController
class ConnectController extends \HWI\Bundle\OAuthBundle\Controller\ConnectController
Override connectServiceAction. Rewrite part where the success connection handled and return RedirectResponse
最好的解决方案是fork并将事件逻辑贡献给HWIOAuthBundle存储库;)
只需复制
内容到
并编辑文件 . 例如 . 我的layout.html.twig看起来像这样
无需添加“继续”按钮或任何您需要的按钮
看看this:
所以我把
target_path_parameter: _destination
,使用了一些JS
将这个参数添加到URL,它运作了!