Answer the question
In order to leave comments, you need to log in
Laravel Auth why is authorization not working?
I used socialiteproviders.github.io/providers/twitch
packages
https://github.com/laravel/socialite
I
used video as instructions: https://laracasts.com/series/whats-new-in-laravel-...
Rout :
Route::get('/twitch', 'Auth\[email protected]');
<?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'));
}
}
<?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\[email protected]',
],
];
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function boot(DispatcherContract $events)
{
parent::boot($events);
//
}
}
<?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);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question