overtrue / laravel-socialite
Social OAuth authentication for Laravel 5.
Fund package maintenance!
overtrue
Installs: 507 055
Dependents: 2
Suggesters: 0
Security: 0
Stars: 340
Watchers: 10
Forks: 47
Open Issues: 0
Requires
- overtrue/socialite: ^4.0
Requires (Dev)
- brainmaestro/composer-git-hooks: dev-master
- friendsofphp/php-cs-fixer: ^3.3
- laravel/pint: *
- mockery/mockery: ^1.4
- phpunit/phpunit: ^10.0|^11.0
README
Installation
$ composer require "overtrue/laravel-socialite"
if you have been installed the
overtrue/socialite
package, please remove it fromcomposer.json
before 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.php
orconfig/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', ], //... ];
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.
❤️ Sponsor me
如果你喜欢我的项目并想支持它,点击这里 ❤️
Project supported by JetBrains
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
PHP 扩展包开发
想知道如何从零开始构建 PHP 扩展包?
请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》
License
MIT