Support the ongoing development of Laravel.io →
Authentication Requests Session
Last updated 1 year ago.
0

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 8 years ago.
0

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

https://github.com/Lusitanian/PHPoAuthLib/blob/master/examples...

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/>";

        //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((string)$url);
    }
}
Last updated 8 years ago.
0

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));

with

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

Full Controller

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

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.