I think that most people will use Socialite when executing social login with Laravel.
By using Socialite, it is very easy to execute social login😘
I would like to use Socialite outside of Laravel! That is what I thought, and I made a library that can be use with other frameworks and pure PHP, with the same execution method.
Github : https://github.com/socialite-manager/socialite (Please star😎)
Use(Twitter login)
Please obtain ConsumerKey and ConsumerSecret from Twitter in advance.
Install
composer require socialite-manager/socialite
Redirect
oath.php :
use Socialite\Socialite;
$config = [
'client_id' => 'xxx', //ConsumerKey
'client_secret' => 'xxx', //ConsumerSecret
'redirect' => 'http://example.com/callback.php', // Redirect URL
];
Socialite::driver('twitter', $config)->redirect();
Acquire user information
callback.php :
use Socialite\Socialite;
$config = [
'client_id' => 'xxx',
'client_secret' => 'xxx',
'redirect' => 'http://example.com/callback.php',
];
$user = Socialite::driver('twitter', $config)->user();
$user->getAvatar();
$user->getEmail();
$user->getId();
$user->getNickname();
$user->getName();
That's it😎
Use in framework
Have options for use with the framework.
For example CakePHP3
UsersController :
Socialite::driver('twitter', $config)
->setRequest($this->request)
->setSession($this->request->getSession());
Please check the documentation for details!
https://github.com/socialite-manager/socialite#advanced-usage
Discussion (0)