无法在 lumen 5.2 上使用 socialite

Can't use socialite on lumen 5.2

这是我的流明配置 socialite,但出现错误:

致命错误:调用成员函数 set() on null

有什么想法吗?


我的 AuthController

namespace App\Http\Controllers;
use Socialite;

class AuthController extends Controller {

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

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

我的Route.php

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

我的bootstrap/app.php 添加了这个

class_alias(Laravel\Socialite\Facades\Socialite::class, 'Socialite');
$app->register(Laravel\Socialite\SocialiteServiceProvider::class);
$app->configure('services');

我的config/services

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

**

Fatal error: Call to a member function set() on null in D:\xampp\htdocs\user-service\vendor\laravel\socialite\src\Two\AbstractProvider.php on line 134
Whoops, looks like something went wrong.
1/1
FatalErrorException in D:\xampp\htdocs\user-service\vendor\laravel\socialite\src\Two\AbstractProvider.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->Laravel\Lumen\Concerns\{closure}()

**

您首先需要更正您的两种方法中的Socialite调用:

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

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

不要在 Socialite :: driver 处使用空格。

Lumen 5.2 的重要变化(参见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.

Lumen 5.2 不再支持会话。如果您需要这些,最好使用 Laravel。