Я использую Laravel Socialite 5.0.
<?php
use Illuminate\Http\Request;
public function login(AuthenticateUser $authenticateUser, Request $request){
return $authenticateUser->execute($request->has('code'));
}
$request->has('code')
всегда возвращает ноль. Это почему?
Предоставляя мой класс AuthenticateUser, я вижу это как проблему перенаправления / запроса.
<?php
namespace App;
use Laravel\Socialite\Contracts\Factory as Socialite;
use Illuminate\Contracts\Auth\Guard as Guard;
use App\Repositories\UserRepository as UserRepository;
use Log;
class AuthenticateUser {
private $users;
private $socialite;
private $auth;
public function __construct (UserRepository $users, Socialite $socialite, Guard $auth) {
$this->users = $users;
$this->socialite = $socialite;
$this->auth = $auth;
}
public function execute ($hasCode) {
if( ! $hasCode){
Log::info('1');
return $this->getAuthorizationFirst();
}
Log::info('2');
$user = $this->socialite->driver('github')->user();
}
public function getAuthorizationFirst(){
return $this->socialite->driver('github')->redirect();
}
}
Добавление класса AuthController для справки:
class AuthController extends Controller {
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers;
/**
* Create a new authentication controller instance.
*
* @param \Illuminate\Contracts\Auth\Guard $auth
* @param \Illuminate\Contracts\Auth\Registrar $registrar
* @return void
*/
public function __construct(Guard $auth, Registrar $registrar)
{
$this->auth = $auth;
$this->registrar = $registrar;
$this->middleware('guest', ['except' => 'getLogout']);
}
public function login(AuthenticateUser $authenticateUser, Request $request){
Log::info('_'.$request->has('code').'_');
return $authenticateUser->execute($request->has('code'));
}
}
Проблема была с обратным URL-маршрутом!
Я возвращался по неправильному маршруту из приложения.
Других решений пока нет …