Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access token failed issue #1

Closed
battika opened this issue Nov 29, 2011 · 4 comments
Closed

Access token failed issue #1

battika opened this issue Nov 29, 2011 · 4 comments

Comments

@battika
Copy link

battika commented Nov 29, 2011

Hello ElWardi,

Thanks for putting sfMelodyDemo example symfony project together. I'm wondering if you could give me some sort of direction as I cannot get the demo work.

Downloaded the code and followed your instructions to set it up. I'm using WAMP on Windows 7 and created a virtual host of sfmelodydemo.dev to match your setup and changed my Windows hosts file sfmelodydemo.dev pointing to 127.0.0.1. Created a developer app on Facebook, set the Site URL field to sfmelodydemo.dev and finally ran symfony doctrine:build --all --and-load command to create the database backend. I think it should be all set.

When I open http://sfmelodydemo.dev/frontend_dev.php in my web browser it gives me two options to log on with, Facebook and Twitter. I choose Facebook which will redirect to my Facebook app page where I successfully log on with my Facebook account. When I get redirected to sfmelodydemo.dev/frontend_dev.php it throws an internal server error 500 message, Doctrine_Table_Exception, saying that You must specify the value to findOneBy. It occurs as inside the executeFacebookSignup action where we attempt to find out whether the email address is already present:

$dbUser = UserTable::getInstance()->findOneByEmailAddress($this->user->getEmailAddress());

Since user->getEmailAddress() returns null, findOneByEmailAddress function will fail.

The reason why it fails is we are unable to get a valid access token from Facebook. Here are some excerpts from the log file...

Initial authorize request seems fine. URL looks Okay.

Nov 29 21:06:25 symfony [info] {sfMelodyActions} Call "sfMelodyActions->executeFacebookConnect()"
Nov 29 21:06:25 symfony [info] {OAuth} "facebook" call url "https://graph.facebook.com/oauth/authorize" with params "array (
  'scope' => 'email,user_birthday',
  'client_id' => '280217605XXXXXX',
  'redirect_uri' => 'http://sfmelodydemo.dev/frontend_dev.php/access/facebook',
)"
Nov 29 21:06:25 symfony [info] {sfFrontWebController} Redirect to "https://graph.facebook.com/oauth/authorize?scope=email%2Cuser_birthday&client_id=280217605XXXXXX&redirect_uri=http%3A%2F%2Fsfmelodydemo.dev%2Ffrontend_dev.php%2Faccess%2Ffacebook"
Nov 29 21:06:25 symfony [info] {sfWebResponse} Send status "HTTP/1.1 302 Found"
Nov 29 21:06:25 symfony [info] {sfWebResponse} Send header "Location: https://graph.facebook.com/oauth/authorize?scope=email%2Cuser_birthday&client_id=280217605XXXXXX&redirect_uri=http%3A%2F%2Fsfmelodydemo.dev%2Ffrontend_dev.php%2Faccess%2Ffacebook"

Then I get this issue of access token failed and a zero-sized array is returned:

Nov 29 21:06:27 symfony [info] {sfMelodyActions} Call "sfMelodyActions->executeAccess()"
Nov 29 21:06:27 symfony [info] {OAuth} call https://graph.facebook.com/oauth/access_token?client_id=280217605XXXXXX&client_secret=4ba259f0f6acfb44dfbe55XXXXXXXXXX&redirect_uri=http%3A%2F%2Fsfmelodydemo.dev%2Ffrontend_dev.php%2Faccess%2Ffacebook&code=AQAvrMn9h2jdZL9jqKS5m_FlFSqXqNlDdF7maQ2gaZFQz7zXqGkerD-nBHf4kZSBx0iWe3Qhyf-HxpxMQhfs20SBCFQwo7e965sdVEiWika4IzZzyMX2ai0EtXvaeccYE5OCbyc08y3m-dGwm_Uks13jnaAUliy2tqIqYYPFZqrzwcChuJwv39qL2Cl_n11Nkmity1UeO1EGcrS8sorxP26m with params client_id=280217605XXXXXX&client_secret=4ba259f0f6acfb44dfbe55XXXXXXXXXX&redirect_uri=http%3A%2F%2Fsfmelodydemo.dev%2Ffrontend_dev.php%2Faccess%2Ffacebook&code=AQAvrMn9h2jdZL9jqKS5m_FlFSqXqNlDdF7maQ2gaZFQz7zXqGkerD-nBHf4kZSBx0iWe3Qhyf-HxpxMQhfs20SBCFQwo7e965sdVEiWika4IzZzyMX2ai0EtXvaeccYE5OCbyc08y3m-dGwm_Uks13jnaAUliy2tqIqYYPFZqrzwcChuJwv39qL2Cl_n11Nkmity1UeO1EGcrS8sorxP26m | GET
Nov 29 21:06:27 symfony [err] {OAuth} access token failed - facebook returns Array
(
)

Nov 29 21:06:27 symfony [info] {OAuth} call https://graph.facebook.com/me with params  | 
Nov 29 21:06:28 symfony [info] {OAuth} call https://graph.facebook.com/me with params  | 

It all goes wrong after this due to the missing token.

Symptoms are very similar to the ones reported by JeJeJeRe in this issue: chok/sfMelodyPlugin#9

He solved it by moving his project to a real online domain. I don't think it should necessarily be the root cause here. Looking at the domain name configured in your project (sfmelodydemo.dev) I suppose you are also using a virtual environment. Can you please confirm that? Any other help with setting up the demo would be appreciated.

Thanks in advance.

@mWardi
Copy link
Owner

mWardi commented Nov 30, 2011

Hello battika,
Thank you for pointing on this. Well, I am using ubuntu 10.04, less pain configuring v-hosts. and i don't think it is an environment problem. I tried different scenarios by changing the configurations and i still didn't get that issue.
Please check again if you set up your facebook application properly. I never worked on Windows before, but as long as facebook redirect you back to your application, your dev environment is working fine.
You can comment userActions->executeFacebookSignup() and then check if you are getting the desired information from facebook in the session.
You may add the following code in sfMelodyActions->executeCheckSession()

    $user = $this->getUser()->getMelodyUser();
    $token = $this->getUser()->getMelodyToken();
    print_r('<pre>');
    print_r('<h1>Melody User</h1>');
    print_r($user->toArray());
    print_r('</pre>');
    print_r('<hr/>');

    print_r('<pre>');
    print_r('<h1>Melody Token</h1>');
    print_r($token->toArray());
    print_r('</pre>');
    print_r('<hr/>');

    die();

you will have something like this :

Melody Token

Array
(
    [id] => 
    [name] => facebook
    [token_key] => AAAEVR8LdU70BADiYABjHDZB9KBZASayQ8Irku6PXWshfROWKv918kdMOZCX6hZA9bW63HQq6otIrFTex6lVDzNjMEINctel6r8BC7y3UWfSUkVjnwXFq
    [token_secret] => 
    [user_id] => 
    [expire] => 1322650800
    [params] => Array
        (
            [expires] => 4841
        )

    [identifier] => 102644XXXX
    [status] => access
    [o_auth_version] => 2
    [created_at] => 
    [updated_at] => 
)

I will update the project asap as i am willing to add google connect and handle email check and account activation for twitter connect.

@battika
Copy link
Author

battika commented Nov 30, 2011

Hello ElWardi,

Thank you for your prompt and helpful answer. Thanks for adding more examples to the project I'm very interested in seeing how Google Connect will be done. I very much look forward to it.

I've managed to "solve" the issue but I'm even more confused now. What I actually did was installed Virtualbox on my Windows 7 and installed CentOS 6 on it. Deployed XAMPP for Linux from here http://www.apachefriends.org/en/xampp-linux.html
Copied my project files over to the Linux box and it worked right out of the box! I did not make a single change to the project files. Checked PHP version and both LAMPP and WAMP are using PHP 5.3.8.

I would like to find the root cause of the problem since I'm using Windows as dev environment and I have no intention to change it. Or at least this is something I have never considered until this point.

I will try your suggestions and see if they work out well.

Thank you again for your time and effort.

@mWardi
Copy link
Owner

mWardi commented Nov 30, 2011

I am keeping the issue open in case you or any other found out a fix for it,
Thanks.

@battika
Copy link
Author

battika commented Dec 2, 2011

Hello ElWardi,

I managed to find a solution to the problem. Windows version of the curl PHP library does not contain the Certificate Authority bundle (cacerts file) so curl will not be able to verify Facebook site's cerficate. Remember, we are using https:// to get data from Facebook. To avoid this issue we need to make sure that curl is provided with a valid cacerts file through the curl_setopt(, CURLOPT_CAINFO, ) function call.

You can find some more information here:
http://richardwarrender.com/2007/05/the-secret-to-curl-in-php-on-windows/

Since the problem is caused by the OAuthBase library I suggest that this issue should be closed.

Thanks very much for this great demo and I look forward to further updates.

@mWardi mWardi closed this as completed Dec 2, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants