Skip to content

Instantly share code, notes, and snippets.

@JSila
Last active August 29, 2015 14:16
Show Gist options
  • Save JSila/4bd40d72c1a86f29ed55 to your computer and use it in GitHub Desktop.
Save JSila/4bd40d72c1a86f29ed55 to your computer and use it in GitHub Desktop.
How to: Laravel Socialite

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment