lightmagic / laravel-socialite
Social OAuth authentication for Laravel 5.
1.0.3
2017-03-20 01:31 UTC
Requires
- lightmagic/socialite: ~1.0
This package is not auto-updated.
Last update: 2024-11-13 21:02:07 UTC
README
Installation
$ composer require "overtrue/laravel-socialite:~1.0"
if you have been installed the
overtrue/socialite
package, please remove it fromcomposer.json
before this command.
Configuration
- After installing the Socialite library, register the
Overtrue\LaravelSocialite\ServiceProvider
in your config/app.php configuration file:
'providers' => [ // Other service providers... Overtrue\LaravelSocialite\ServiceProvider::class, ],
- Add the follow line to the
aliases
section ofconfig/app.php
:
'Socialite' => Overtrue\LaravelSocialite\Socialite::class,
- 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\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.
License
MIT