API authentication via social networks for your Laravel application
API authentication via social networks for your Laravel application
This package adds a social grant for your OAuth2 server. It can be useful if have an API and want to provide the ability for your users to login/register through social networks.
As a result you will be able to exchange access_token, issued by the OAuth2 server of any social provider,
to access_token and refresh_token issued by your own OAuth2 server.
You will receive this access_token and return the user instance that corresponds to it on your own.
You can install this package via composer using this command:
composer require coderello/laravel-passport-social-grantThe package will automatically register itself.
As the first step, you need to implement SocialUserResolverInterface:
Here is an example using Socialite -
userFromToken($accessToken);
return $this->findOrCreateUser($provider, $providerUser);;
}
protected function findOrCreateUser(string $provider, ProviderUser $providerUser): ?Authenticatable
{
// todo your logic here
// $email = $providerUser->getEmail();
}
}The next step is to bind SocialUserResolverInterface to your implementation.
You can do it by adding the appropriate key-value pair to $bindings property in AppServiceProvider:
SocialUserResolver::class,
];
}You are done!
Example of usage with axios:
…Example of usage with guzzlehttp/guzzle:
…You can run the tests with:
composer testPlease see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
Created by Illia Sakovich
Maintained by Ankur Kumar
The MIT License (MIT). Please see License File for more information.
No open issues yet, or sync has not completed.