Jump to content

Facebook OAuth 2.0 Problems


schivo

Recommended Posts

Hi,

 

I'm trying to integrate my web based application with facebook.

 

First of all, I created page login/facebook which redirects user to the URL:

 https://www.facebook.com/dialog/oauth?client_id=MY_ID&redirect_uri=https://www.domain.com/connect/facebook&scope=email,user_about_me,user_location

 

So far so good. Have no problems at this stage.

 

If user authorize my application, he gets redirected to the www.domain.com/connect/facebook page. On this page I create user in my database using data returned by FB or just authorize user and create session. On this step I have issues. When I use code from the examples from Facebook Developers Help Page everything works:

 

$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
    . $this->app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret="
    . $this->secret . "&code=" . $code;
$access_token = file_get_contents($token_url);
$graph_url = "https://graph.facebook.com/me?" . $access_token;
$user_object = json_decode(file_get_contents($graph_url));

 

 

When I use following snippet everything works perfectly. However I prefer to use PHP-SDK and having problems. When I use following snippet:

$session = $this->facebook->getSession();
var_dump($session);
            if( $session )
            {
                try
                {
                    $uid = $this->facebook->getUser();
                    $me = $this->facebook->api('/me');

                    var_dump('me');
                }
                catch (FacebookApiException $e)
                {
                    error_log($e);
                }
            }

session is null.

 

After having some fun with PHP-SDK I noticed some funny stuff: When I use SDK getLoginUrl() method to generate redirect URL, it seems to be partially working.

$login_url = $this->facebook->getLoginUrl(
        array(
            'api_key' => $this->api_key,
            'req_perms' => 'email,user_work_history,user_about_me,user_location',
            'next' => 'https://www.domain.com/connect/facebook'
        )
    );

 

Now when users authorizes my app, he's being redirected to correct page with some params, URL looks like:

https://www.domain.com/connect/facebook?session={"session_key"%3A"11111111111-111111111"%2C"uid"%3A"11111111"%2C"expires"%3A0%2C"secret"%3A"111111111"%2C"base_domain"%3A"domain.com"%2C"access_token"%3A"1111111|222222.0-33333|sdvsdvsdvsdvsdv"%2C"sig"%3A"gsdbsdbsdbsdbsdbsdbsdb"}

 

Anyone has any idea why it's not hashes or it shouldn't? Or should I leave php-sdk and use the way with file_get_contents()?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.