Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This uses a twig helper and render a template with '' notation using facebook sdk js.</p> <p>If you need to redirect to the login-page, use an html link, call the method 'getLoginUrl' from the php facebook sdk</p> <p>You can access to it via the service <code>'fos_facebook.api'</code> register through FOSFacebookBundle</p> <p><strong>Updated with code examples</strong></p> <p>Here is the javascript code i use to login with facebook 'frictionless'</p> <pre><code>&lt;script&gt; //scopes string stored as container parameter var fb_scope='{{ facebook_scope }}'; //connected in sf2 app ? {% if app.user %} var isLogged=true; {% else %} var isLogged=false; {% endif %} //var to store fb status var fb_connected = false; function onFbInit() { if (typeof(FB) != 'undefined' &amp;&amp; FB != null ) { // fetch the status on load FB.getLoginStatus(handleSessionResponse); //my facebook connect link $('a.facebook_connect').on('click', function(e) { FB.login(function(response) { if (response.authResponse) { checkAccount(); } else { onAuthRefusal(); } }, {scope: fb_scope}); e.preventDefault(); }); //my logout link $('#logout').on('click', function(e) { FB.logout(null); }); //want to distinguish three status states FB.Event.subscribe('auth.statusChange', handleSessionResponse); } } function handleSessionResponse(response) { if (response.status === 'connected') { // the user is logged in and has authenticated your // app, and response.authResponse supplies // the user's ID, a valid access token, a signed // request, and the time the access token // and signed request each expire var uid = response.authResponse.userID; var accessToken = response.authResponse.accessToken; var expiresIn = response.authResponse.expiresIn; //already logged in sf2 app if(!isLogged){ checkAccount(); } fb_connected = true; } else if (response.status === 'not_authorized') { // the user is logged in to Facebook, // but has not authenticated your app fb_connected = false; } else { // the user isn't logged in to Facebook. fb_connected = false; } } function checkAccount(){ //route defined in your security.yml ( check_path value in your fos_facebook firewall ) top.location.href = '{{ path('_security_check_facebook' ) }}'; } function onAuthRefusal(){ //message, special page ? console.log('refused authentification, message to display ?'); } &lt;/script&gt; {{ facebook_initialize({'xfbml': true, 'fbAsyncInit': 'onFbInit();', 'frictionlessRequests' : 'true'} ) }} </code></pre> <p>I have also defined a route ( /login/facebook ) that redirects to facebook auth </p> <pre><code>//controller action for /login/facebook pattern function loginFacebookAction() { //get facebook api service registered by FacebookBundle $api = $this-&gt;container-&gt;get('fos_facebook.api'); //get scope provided in url or default $scope = $this-&gt;container-&gt;get('request')-&gt;get('scope', 'publish_stream'); //generate call url that use facebook check_path (used by FacebookBundle for authentification) $callback = $this-&gt;container-&gt;get('router')-&gt;generate('_security_check_facebook',array(), true); $redirect_url = $api-&gt;getLoginUrl(array('scope' =&gt; $scope, 'redirect_uri' =&gt; $callback)); return new RedirectResponse($redirect_url); } </code></pre> <p>And this is it !</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload