- About
- Available Providers
- Installation
- Usage
- Creating a Handler
- Creating a Provider
- Overriding a Provider
A package for Laravel Socialite that allows you to easily add new providers or override current providers.
- You will have access to all of the providers that you load in using the manager.
- Instantiation is deferred until Socialite is called
- You can override current providers
- You can create new providers
- See the SocialiteProviders list
- You can also make your own or modify someone else's
Note: You will not need to do this if you require one of the available providers.
// This assumes that you have composer installed globally
composer require socialiteproviders/manager
-
Remove
Laravel\Socialite\SocialiteServiceProvider
from yourproviders[]
array inconfig\app.php
if you have added it already. -
Add
SocialiteProviders\Manager\ServiceProvider
to yourproviders[]
array inconfig\app.php
.
For example:
'providers' => [
// a whole bunch of providers
// remove 'Laravel\Socialite\SocialiteServiceProvider',
'SocialiteProviders\Manager\ServiceProvider', // add
];
-
Add
SocialiteProviders\Manager\SocialiteWasCalled
to yourlisten[]
array in<app_name>/Providers/EventServiceProvider
. -
Add your listeners (i.e. the ones from the providers) to the
SocialiteProviders\Manager\SocialiteWasCalled[]
that you just created. -
Note: You do not need to add anything for the built-in socialite providers unless you override them with your own providers.
For example:
/**
* The event handler mappings for the application.
*
* @var array
*/
protected $listen = [
`SocialiteProviders\Manager\SocialiteWasCalled` => [
'Your\Name\Space\ProviderNameExtendSocialite@handle', // the listener for the provider that you made
'SocialiteProviders\Meetup\MeetupExtendSocialite@handle', // the listener for an actual provider
// This is where we define all of our ExtendSocialite listeners (i.e. new providers)
],
];
Note: In these examples, you need to replace the providername
with the actual name of the provider.
- Add your provider to
config/services.php
.
'providername' => [
'client_id' => env('PROVIDERNAME_KEY'),
'client_secret' => env('PROVIDERNAME_SECRET'),
'redirect' => env('PROVIDERNAME_REDIRECT_URI'),
]
- Append provider values to your
.env
file
// other values above
PROVIDERNAME_KEY=yourkeyfortheservice
PROVIDERNAME_SECRET=yoursecretfortheservice
PROVIDERNAME_REDIRECT_URI=https://example.com/login
You should now be able to use it like you would regularly use socialite:
return Socialite::with('providername')->redirect();
// replace providername with your provider name!
Below is an example handler. You need to add this full class name to the listen[]
in the EventServiceProvider
.
- See also the Laravel docs about events.
providername
is the name of the provider such asmeetup
.- You will need to change your the namespacing and class names of course.
namespace Your\Name\Space;
use SocialiteProviders\Manager\SocialiteWasCalled;
class ProviderNameExtendSocialite
{
public function handle(SocialiteWasCalled $socialiteWasCalled)
{
$socialiteWasCalled->extendSocialite('providername', 'Your\Name\Space\ProviderName');
}
}
- Look at the already made providers for inspiration.
- See this article on Medium
You can easily override a built-in laravel/socialite
provider by creating a new one with exactly the same name.