Skip to main content

Facebook + UserBundle authentication with symfony2


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



thanks


Source: Tips4allCCNA FINAL EXAM

Comments

  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)

    ReplyDelete
  2. 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.

    ReplyDelete
  3. find where the redirect to login is and change the appropriate route. i've not used symphony2 but im guessing it defaults to login is a user isn't logged in. you could maybe switch the routes around so /login calls the facebook login api etc.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.