Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

laravel - Can't use socialite on lumen 5.2

Here is my config socialite for lumen but I got error:

Fatal error: Call to a member function set() on null

Any idea?


my AuthController

namespace AppHttpControllers;
use Socialite;

class AuthController extends Controller {

public function redirectToProvider() {
  return Socialite :: driver('github')->redirect();
}

public function handleProviderCallback() {
  $user = Socialite :: driver('github')->user();
  dd( $user );
}
}

my Route.php

$app->get('auth/github', 'AuthController@redirectToProvider');
$app->get('auth/github/callback', 'AuthController@handleProviderCallback');

my bootstrap/app.php added this

class_alias(LaravelSocialiteFacadesSocialite::class, 'Socialite');
$app->register(LaravelSocialiteSocialiteServiceProvider::class);
$app->configure('services');

my config/services

 return [
   'github' => [
    'client_id' => '############',
    'client_secret' => '#############',
    'redirect' => 'my callback url',
  ],
];

**

Fatal error: Call to a member function set() on null in D:xampphtdocsuser-servicevendorlaravelsocialitesrcTwoAbstractProvider.php on line 134
Whoops, looks like something went wrong.
1/1
FatalErrorException in D:xampphtdocsuser-servicevendorlaravelsocialitesrcTwoAbstractProvider.php line 134:
Call to a member function set() on null
in AbstractProvider.php line 134
at Application->handleShutdown() in RegistersExceptionHandlers.php line 55
at Application->LaravelLumenConcerns{closure}()

**

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You first need to correct your Socialite calls in your two methods:

public function redirectToProvider()
{
  return Socialite::driver('github')->redirect();
}

public function handleProviderCallback()
{
  $user = Socialite::driver('github')->user();
  dd( $user );
}

Don't use spaces at Socialite :: driver.

Important change Lumen 5.2 (see release notes)

Lumen 5.2 represents a shift on slimming Lumen to focus solely on serving stateless, JSON APIs. As such, sessions and views are no longer included with the framework.

Sessions are not supported anymore in Lumen 5.2. If you need those you better use Laravel instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...