Package Data | |
---|---|
Maintainer Username: | overtrue |
Maintainer Contact: | anzhengchao@gmail.com (overtrue) |
Package Create Date: | 2015-12-09 |
Package Last Update: | 2024-03-13 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-15 15:17:31 |
Package Statistics | |
---|---|
Total Downloads: | 531,822 |
Monthly Downloads: | 34,306 |
Daily Downloads: | 671 |
Total Stars: | 340 |
Total Watchers: | 10 |
Total Forks: | 47 |
Total Open Issues: | 0 |
$ composer require "overtrue/laravel-socialite:~2.0"
if you have been installed the
overtrue/socialite
package, please remove it fromcomposer.json
before this command.
Overtrue\LaravelSocialite\ServiceProvider
in your config/app.php configuration file:'providers' => [
// Other service providers...
Overtrue\LaravelSocialite\ServiceProvider::class,
],
aliases
section of config/app.php
:'Socialite' => Overtrue\LaravelSocialite\Socialite::class,
config/socialite.php
or config/services.php
configuration 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',
],
//...
];
<?php
namespace App\Http\Controllers;
use Socialite;
use Illuminate\Routing\Controller;
class AuthController extends Controller
{
/**
* Redirect the user to the GitHub authentication page.
*
* @return Response
*/
public function redirectToProvider()
{
return Socialite::driver('github')->redirect();
}
/**
* Obtain the user information from GitHub.
*
* @return Response
*/
public function handleProviderCallback()
{
$user = Socialite::driver('github')->user();
// $user->token;
}
}
And register routes:
Route::get('/oauth/github', 'AuthController@redirectToProvider');
Route::get('/oauth/github/callback', 'AuthController@handleProviderCallback');
About more usage, please refer to overtrue/socialite.
想知道如何从零开始构建 PHP 扩展包?
请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》
MIT