overtrue/laravel-socialite
Laravel Socialite
Installation
$ composer require "overtrue/laravel-socialite"
if you have been installed the
overtrue/socialitepackage, please remove it fromcomposer.jsonbefore this command.
Configuration
- You will also need to add credentials for the OAuth services your application utilizes. These credentials should be placed in your
config/socialite.phporconfig/services.phpconfiguration file, and should use the key facebook, twitter, linkedin, google, github or bitbucket, depending on the providers your application requires. For example:
<?php
return [
//...
'github' => [
'client_id' => 'your-app-id',
'client_secret' => 'your-app-secret',
'redirect' => 'http://localhost/socialite/callback.php',
],
//...
];
Usage
<?php
namespace App\Http\Controllers;
use Socialite;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
class AuthController extends Controller
{
/**
* Redirect the user to the GitHub authentication page.
*/
public function redirectToProvider()
{
return redirect()->to(Socialite::create('github')->redirect());
}
/**
* Obtain the user information from GitHub.
*/
public function handleProviderCallback(Request $request)
{
$user = Socialite::create('github')->userFromCode($request->query('code'));
// $user->getId();
// $user->getNickname();
// ...
}
}
And register routes:
Route::get('/oauth/github', 'AuthController@redirectToProvider');
Route::get('/oauth/github/callback', 'AuthController@handleProviderCallback');
About more usage, please refer to overtrue/socialite.
:heart: Sponsor me
如果你喜欢我的项目并想支持它,点击这里 :heart:
Project supported by JetBrains
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
License
MIT
Related Packages
doctrine/dbal
Powerful PHP database abstraction layer (DBAL) with many features for database s...
644,549,754
9,698
laravel/serializable-closure
Laravel Serializable Closure provides an easy and secure way to serialize closur...
423,477,751
607
nunomaduro/collision
Cli error handling for console/command-line PHP applications.
399,241,428
4,660
Version History
| Version | Released | License |
|---|---|---|
| 4.1.0 | MIT | |
| 4.0.1 | MIT | |
| 4.0.0 | MIT | |
| 3.0.0 | MIT | |
| 2.1.0 | MIT | |
| 2.0.0 | MIT | |
| 1.1.0 | MIT | |
| 1.0.3 | MIT | |
| 1.0.2 | MIT | |
| 1.0.1 | MIT | |
| 1.0.0 | MIT |