artdarek / oauth-4-laravel

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

Failed to request resource #124

Open ahmadina opened 9 years ago

ahmadina commented 9 years ago

Hi , Hi I am using the following code with the error :

OAuth \ Common \ Http \ Exception \ TokenResponseException Failed to request resource.

  1. OAuth\Common\Http\Exception\TokenResponseException …/­vendor/­lusitanian/­oauth/­src/­OAuth/­Common/­Http/­Client/­StreamClient.php68
public function getOauthGoogle() 
{

    // get data from input
    $code = Input::get('code');

    // get google service
    $googleService = OAuth::consumer('Google','http://chenderghaz.ir/auth/oauth/google');

    // check if code is valid

    // if code is provided get user data and sign in
    if (!empty($code)) 
    {

        // This was a callback request from google, get the token
        $token = $googleService->requestAccessToken($code);

        // Send a request with it
        $result = json_decode( $googleService->request( 'https://www.googleapis.com/oauth2/v1/userinfo' ), true );

        $message = 'Your unique Google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
        echo $message. "<br/>";

        //Var_dump
        //display whole array().
        dd($result);

    }
    // if not ask for permission first
    else {
        // get googleService authorization
        $url = $googleService->getAuthorizationUri();

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

I looked but could not find an answer to this problem :((((

How to fix it? please help

knvpk commented 9 years ago

Im having the same problem....

knvpk commented 9 years ago

I have add 'ignore_errors' => true to return http array of generateStreamContext method in /var/www/LaravelOauth/vendor/lusitanian/oauth/src/OAuth/Common/Http/Client/StreamClient.php

Now its working perfectly but i dont know it is correct way or not

croshim commented 9 years ago

same error

ahmadina commented 9 years ago

This package is unfortunately very poor support? Nobody is answering :(

begmst commented 9 years ago

The same problem - very bad

jansenfelipe commented 9 years ago

Same error....

MadMikeyB commented 9 years ago

Make sure your client_id and client_secret are set in /app/config/packages/artdarek/oauth-4-laravel/config.php - that fixed this for me. They have to be named client_id and client_secret.

See also this comment on Stack Overflow for debug tips for this issue: http://stackoverflow.com/questions/28006102/laravel-tumblr-oauth-failed-to-request-resource/28035736#comment44403888_28006102

RMarecek commented 9 years ago

In Google console "APIs & auth" turn on Google+ API. Now it works fine (tested on localhost).

FeliciousX commented 9 years ago

It could be a PHP thing since by default it uses files_get_contents() Try using curl instead like in #21

Switching from StreamClient to CurlClient