artdarek / oauth-4-laravel

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

Issue when trying to login (exception thrown) #59

Open pdemaio opened 10 years ago

pdemaio commented 10 years ago

This happens to me with facebook login and with google plus login. After login, when i'm returned to my site I get an error because this exception

$level = error_reporting(0); $response = file_get_contents($endpoint->getAbsoluteUri(), false, $context); error_reporting($level); if (false === $response) { $lastError = error_get_last(); if (is_null($lastError)) { throw new TokenResponseException('Failed to request resource.'); }

this came from lusitanian/oauth/src/OAuth/Common/Http/Client/StreamClient.php class.

Any idea why i'm getting this? I've forced php to use Allow_Url_Fopen but i don't know where to look at (i'm on a shared hosting)

philmccarty commented 10 years ago

I had this exact same error. Turns out, I just needed to add a "/" on the return_uri. Worked perfectly after that.

ascension commented 10 years ago

I am experiencing this issue as well. allow_url_fopen is enabled. I am using the code from the facebook example. I have tested google+ and it works just fine.

philmccarty commented 10 years ago

Did you try adding a slash to the end of your URI? Could you post your code?

ascension commented 10 years ago
public function loginWithFacebook() {

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

    // get fb service
    $fb = OAuth::consumer('Facebook');

    // check if code is valid

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

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

        // Send a request with it
        $result = json_decode( $fb->request( '/me' ), true );

        $message = 'Your unique facebook 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 fb authorization
        $url = $fb->getAuthorizationUri();

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

}

philmccarty commented 10 years ago

You need a return URI in your Oauth call. And in your FB app settings you need to add that to the allowed URIs. IT should look like

$fb = OAuth::consumer('Facebook','http://yourdomain.com/returnpage/');

On Sat, May 10, 2014 at 2:26 PM, Jerrod Bunce notifications@github.comwrote:

public function loginWithFacebook() {

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

// get fb service
$fb = OAuth::consumer('Facebook');

// check if code is valid

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

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

    // Send a request with it
    $result = json_decode( $fb->request( '/me' ), true );

    $message = 'Your unique facebook 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 fb authorization
    $url = $fb->getAuthorizationUri();

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

}

— Reply to this email directly or view it on GitHubhttps://github.com/artdarek/oauth-4-laravel/issues/59#issuecomment-42754777 .

ascension commented 10 years ago

Even with providing a url that matches my FB app settings it does not work.

philmccarty commented 10 years ago

Can you show a screenshot of both?

Sent from my iPhone

On May 11, 2014, at 2:33 PM, Jerrod Bunce notifications@github.com wrote:

Even with providing a url that matches the settings in my FB app settings it does not work.

— Reply to this email directly or view it on GitHub.

ascension commented 10 years ago

Figured it out. Turns out my FB app settings were wrong.

philmccarty commented 10 years ago

Cool. Good luck!

On May 12, 2014, at 9:24 AM, Jerrod Bunce notifications@github.com wrote:

Figured it out. Turns out my FB app settings were wrong.

— Reply to this email directly or view it on GitHub.