Facebook iframe application authentication?

I developed a Facebook application that runs inside an iframe in a Facebook canvas. For proper operation, I ask the user for extended permissions. If the user does not allow the application, I will send it to the login page using the getLoginUrl () method in the PHP SDK.

It works, but it doesn’t. The method sends the user to the landing page in front of the authentication page. It looks like this:

Facebook Landing Page

When I click Go to Facebook.com, I see the actual page for permission requests (I also get permission to the permission page if I print the URL, copy it and enter it in a new browser window). How to make Facebook skip this step when I do a redirect from an iframe?

My code looks like this (using CodeIgniter and the PHP PHP SDK):

$this->facebook = new Facebook(array( 'appId' => '{MY_APP_ID}', 'secret' => '{MY_SECRET}', 'cookie' => TRUE, 'domain' => $_SERVER['SERVER_NAME'] )); $this->facebook->getSession(); try { $this->me = $this->facebook->api('/me'); } catch (FacebookApiException $e) { $this->me = NULL; } if ( is_null($this->me) ) { redirect($this->facebook->getLoginUrl(array( 'req_perms' => 'offline_access,read_stream,publish_stream,user_photos,user_videos,read_friendlists', 'next' => $this->config->item('base_url').'fblogin.php?redirect_uri='.$this->uri->uri_string() ))); } 
+4
source share
2 answers

I think you need to redirect the parent frame (i.e. _top) and not the iFrame itself?

+4
source

How do I do this, the INDEX.PHP file is created with the following

  //if user is logged in and session is valid. if ($fbme){ //fql query example using legacy method call and passing 

parameter try {$ fql = "select name, hometown_location, sex, pic_square from user, where uid =". $ UID $ param = array ('method' => 'fql.query', 'query' => $ fql, 'callback' => 'http://apps.facebook.com/yoursite/'); $ fqlResult = $ facebook-> api ($ param); } catch (Exception $ o) {q ($ o); }}

Then enter your canvas URL at http://yoursite.com/INDEX.php

The callback URL in the above code, which will be in the INDEX.PHP sets, where permission is granted for access.

FBMain.php is as follows:

 //set application urls here $fbconfig['http://www.yoursite.com/iframeapp/YOURMAINPAGE.php/'] 

= "http://www.tyoursite.com/YOURMAINPAGE.php/";

 $fbconfig['http://apps.facebook.com/CANVASBASEURL'] 

= "http://apps.facebook.com/CANVASBASEURL";

 $uid = null; //facebook user id try{ include_once "facebook.php"; } catch(Exception $o){ echo '<pre>'; print_r($o); echo '</pre>'; } // Create our Application instance. $facebook = new Facebook(array( 'appId' => $fbconfig['APPID'], 'secret' => $fbconfig['SECRET'], 'cookie' => true, )); //Facebook Authentication part $session = $facebook->getSession(); $loginUrl = $facebook->getLoginUrl( array( 'canvas' => 1, 'fbconnect' => 0, 'req_perms'=>'email,publish_stream,status_update,user_birthday,user_location' ) ); $fbme = null; if (!$session) { echo "<script type='text/javascript'>top.location.href 

= '$ loginUrl'; "; Exit;} else {try {$ uid = $ facebook-> getUser (); $ fbme = $ facebook-> api ('/ me');

  } catch (FacebookApiException $e) { echo "<script type='text/javascript'>top.location.href 

= '$ loginUrl'; "; Output; } }

 function d($d){ echo '<pre>'; print_r($d); echo '</pre>'; } ?> 

Hope this is a little clearer. It took me a while to figure this out, but I got there, I thought I'd help.

0
source

Source: https://habr.com/ru/post/1335373/


All Articles