Setting Up Laravel Socialite Provider
Laravel SocialiteProvider is a great extension to the Laravel Socialite package that provides adding SSO capability to your app out of the box.
If you are looking to integrate with a OAuth provider that you could not find in Socialite, it would be a good idea to look for it in the SocialiteProvider documentation. If it is listed then integrating it in your app would be as fun as any of the standard Socialite channels (currently Facebook, Twitter, LinkedIn, Google, GitHub, GitLab, and Bitbucket) is.
Two things that you would want to remember are:
- You need to have Socialite in place. So make sure you install Socialite before installing SocialiteProvider.
- You can keep using the existing functionality from Socialite. Use SocialiteProvider for just the new integration not being provided by Socialite.
The documentation by SocialiteProvide is quite straightforward:
Install the package
composer require socialiteproviders/trello
Update
config/app.php
'providers' => [ \SocialiteProviders\Manager\ServiceProvider::class, // add ];
Update
app\Providers\EventServiceProvider.php
protected $listen = [ \SocialiteProviders\Manager\SocialiteWasCalled::class => [ \SocialiteProviders\Trello\TrelloExtendSocialite::class.'@handle', ], ];
and you are done with the installation. Now just implementation remains.
Set up the:
app related secrets in your
.env
TRELLO_CLIENT_ID=xxx TRELLO_CLIENT_SECRET=xxx TRELLO_REDIRECT_URI=xxx
configuration in your
config/services.php
'trello' => [ 'client_id' => env('TRELLO_CLIENT_ID'), 'client_secret' => env('TRELLO_CLIENT_SECRET'), 'redirect' => env('TRELLO_REDIRECT_URI') ],
front-end triggers (buttons etc.) and your routes in
web.php
Route::get('/login', function () { return Socialite::driver('trello') ->setScopes(['read', 'activity:read_all']) ->redirect(); });
logic to handle/save the response
$user = Socialite::driver('trello')->user(); $name = $user->accessTokenResponseBody['name'];