Support the ongoing development of →
Authentication Requests Session
Last updated 3 months ago.

Are you requesting the data correctly? Laravel 4 example

$name = Input::get('name');

laravel 5 example , need use statement:

<?php namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

class UserController extends Controller {

    public function store(Request $request)
        $name = $request->input('name');

You have

$code = Request::get('code');

Probably need to be

$code = Input::get('code'); //if laravel 4
Last updated 7 years ago.

I checked one by one line code

Error this line

$result = json_decode($githubService->request('user/emails'), true);

CURL active, no problem, and same problem.

I used in example

My Controller follow facebook example

public function loginWithFacebook(Request $request)
    // get data from request
    $code = $request->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 ( ! is_null($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/>";

        //display whole array.
    // if not ask for permission first
        // get fb authorization
        $url = $fb->getAuthorizationUri();

        // return to facebook login url
        return redirect((string)$url);
Last updated 7 years ago.

Before i had trouble when testing on localhost (StreamClient an CurlClient)

I used CurlClient in shared hosting is OK

And i changed

$result = json_decode($githubService->request('user/email',true));


$result = json_decode($githubService->request('user'));

Full Controller

public function loginWithGithub()
        $code = Request::get('code');
        $OAuth = new OAuth();
        $githubService = $OAuth::consumer('GitHub');
        if ( ! is_null($code))
            $token = $githubService->requestAccessToken($code);
            $result = json_decode($githubService->request('user'));
        else {
            $url = $githubService->getAuthorizationUri();
            return redirect((string)$url);
Last updated 7 years ago.

Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 - All rights reserved.