In this case we want to authenticate with twitter. This gist assumes new twitter app is already generated (we need client id, client secret and redirect url).
First require the package with composer
composer require laravel/socialite:~2.0
Register service provider and facade for the package.
Then add credentials for authentication with twitter in config/services.php
:
'twitter' => [
'client_id' => env('TWITTER_CLIENT_ID'),
'client_secret' => env('TWITTER_CLIENT_SECRET'),
'redirect' => 'http://127.0.0.1:8000/oauthproxy'
],
Just to quickly show how to use it, add the following in routes.php
:
get('/twitter', function()
{
return Socialize::with('twitter')->redirect();
});
// route needs to match redirect url
get('/oauthproxy', function()
{
dd(Socialize::with('twitter')->user());
});
..and visit /twitter
url.