34

I'm trying to authenticate my users via facebook or userbundle on symfony2

Here's what I did so far (and it works, although not as I want):

firewalls:
    main:
        pattern: .*
        fos_facebook:
            app_url: "http://apps.facebook.com/appName/"
            server_url: "http://localhost/facebookApp/"
            login_path: /fblogin
            check_path: /fblogin_check
            default_target_path: /
            provider: my_fos_facebook_provider
        form_login:
            check_path: /login_check
        anonymous: true
        logout:
            handlers: ["fos_facebook.logout_handler"]

The problem with that config is that when the user is not logged in, he's redirected to /login (form_login), while I'd like him to be redirected to Facebook authentication by default

I already tried simply removing the form_login, but then if I access /login (which is how I want users to login outside facebook), it doesn't know the /login_check route to submit the login form

Maybe chain_provider would be a solution? I didn't get it working either

2
  • +1. I've had this issue as well; would love to see a good solution to it. Commented Sep 24, 2011 at 22:00
  • 1
    Does this solution assist in any way -> stackoverflow.com/questions/7257183/… Commented Oct 11, 2011 at 16:29

4 Answers 4

1

An easy and mabye more usable option would be to show all the login options in the login page (including facebook, twitter, open id, or whatever you'd like to use)

Sign up to request clarification or add additional context in comments.

Comments

1

Chain providers is indeed the solution to this problem. Here is what you security.yml config shoud look like:

providers:
  my_project.chain_provider:
    chain:
      providers: [fos_userbundle, my_project.facebook_provider]
  fos_userbundle:
    id: fos_user.user_provider.username_email
  my_project.facebook_provider:
    id: my_project.user_provider.facebook

And, of course, you need to define your own facebook provider as stated here

Comments

0

You should add the fos_userbundle provider for the form_login (and keep the rest of the configuration):

form_login:
    provider: fos_userbundle

I didn't dig too much, but I think Symfony2 is automatically creating a chained provider in this case.

Comments

0

Also you can write your event listener where you will be looking whether a user goes to /login form directly or by redirecting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.