artdarek / oauth-4-laravel

OAuth Service Provider for Laravel 4
684 stars 217 forks source link

requestAccessToken() errors: "Failed to request resource." #114

Open simplenotezy opened 9 years ago

simplenotezy commented 9 years ago

When running:

        /**
         * Get Facebook sDK
         */

            $fb = OAuth::consumer( 'Facebook' );

        /**
         * Set code
         */

            $fb->requestAccessToken($facebook_token); // this line

I'll get the error:

"Failed to request resource."

image

Why?

GregersBoye commented 9 years ago

I get the same error when using $googleService->requestAccessToken( $code );

For some reason, in Lusitanian it gets 'false' back from google.

oizawa commented 9 years ago

I didn't any problems with facebook, it works well for me, but not with twitter.

    // get request token
    $reqToken = $tw->requestRequestToken();

    // get Authorization Uri sending the request token
    $url = $tw->getAuthorizationUri(array('oauth_token' => $reqToken->getRequestToken()));

    // return to twitter login url
    return Redirect::to( (string)$url );

It get requestAccessToken() errors: "Failed to request resource." when call requestRequestToken();

when I manually use curl to request token, it returned the access token and directly input to this methods:

$url = $tw->getAuthorizationUri(array('oauth_token' => 'manually input access token'));

and it works returned PIN.

so twitter authentication process working, but not with method requestRequestToken(), anyone !?

simplenotezy commented 9 years ago

I am still experincing this issue. Anyone would know why?

RaniSharim commented 9 years ago

Try to pass the OAuth redirect URIs manually - facebook goes all willy-nilly about missing trailing slashes.

simplenotezy commented 9 years ago

What do you mean Rani?

After debugging, this is the request that fails:

https://graph.facebook.com/oauth/access_token

RaniSharim commented 9 years ago

$fb = OAuth::consumer( 'Facebook','http://my.app.com/' ); Instead of $fb = OAuth::consumer( 'Facebook');

This will send the redirect URI with trailing a slash, which doesn't always happen automatically, and which facebook insists on.

simplenotezy commented 9 years ago

Ah, I see. I've tried. Still, without luck.

Anyways, shouldn't facebook return a error message if this was the issue?

RaniSharim commented 9 years ago

It does, and returns it in the body, but the inner function doesn't read it.

You have to make a change to lusitanian\oauth\src\OAuth\Common\Http\Client\StreamClient.php, at about line 50, to make it make a request with "ignore errors" on, and read the response body.

Take a look at this stackexchange thread: http://stackoverflow.com/questions/3710147/php-get-content-of-http-400-response

simplenotezy commented 9 years ago

Thanks Rani, I've tried implementing that, but it does not work.

Fun thing is, query takes 22 seconds before it fails (tried extending timeout period, no affect, still around 22seconds).

My staging server works perfectly - strange - maybe some Facebook domain configuration that is not correct, but since I don't get any error responses as to why request fails (!!), I have no idea where to start.

RaniSharim commented 9 years ago

That is odd. Maybe you should try inspecting $http_response_header - at least you'll which status code is returned, if any.

cmarfil commented 9 years ago

Same problem, i'm the developer of the app and with my fb account all works fine, but with other users and with "/me/taggable_friends" does not work :S