Использовал пакеты
socialiteproviders.github.io/providers/twitch
https://github.com/laravel/socialite
В качестве инструкции использовал видео:
https://laracasts.com/series/whats-new-in-laravel-...
Rout:
Route::get('/twitch', 'Auth\AuthController@twitch');
AuthController:
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Laravel\Socialite\Facades\Socialite;
use App\AuthenticateUser;
use Illuminate\Http\Request;
class AuthController extends Controller
{
public function twitch(AuthenticateUser $authenticateUser, Request $request )
{
return $authenticateUser->execute($request->has('code'));
}
}
EventServiceProvider:
<?php
namespace App\Providers;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'App\Events\SomeEvent' => [
'App\Listeners\EventListener',
],
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// add your listeners (aka providers) here
'SocialiteProviders\Twitch\TwitchExtendSocialite@handle',
],
];
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function boot(DispatcherContract $events)
{
parent::boot($events);
//
}
}
AuthenticateUser.php :
<?php
namespace App;
use Illuminate\Contracts\Auth\Authenticator;
use Laravel\Socialite\Contracts\Factory as Socialite;
class AuthenticateUser {
private $users;
private $socialite;
private $auth;
public function __construc(UserRepository $users, Socialite $socialite, Authenticator $auth)
{
$this->users = $users;
$this->socialite = $socialite;
$this->auth = $auth;
}
public function execute($hasCode)
{
if (! $hasCode) return $this->getAuthorizationFirst();
$this->socialite->driver('twitch')->user();
}
private function getAuthorizationFirst()
{
$user = $this->socialite->driver('twitch')->redirect();
dd($user);
}
}
В чем ошибка ?