This project is related to tutorial from Codingo Tuts.
In tutorial I am creating Laravel application with email authentication and user roles, but I am also using [Laravel Socialite] for Facebook and Twitter logins. At the end of this tutorial you will be able to use any other social provider in matter of seconds.
Everything is covered there so new Laravel developers can grasp it quickly. I am following simple plan while I am developing:
- Creating views for application
- Creating migrations and models related to users and roles
- User seeder with some dummy users
- Middleware for administrator and user roles
- Routes and AuthController
- Creating table and model for Social logins
- Creating Social Logic
This plan is not strict and if you are familiar with something you may just skip that part.
Main beauty is modular approach in implementing new Socialite providers. Application uses to routes one for redirecting user to certain social site and other to accept response from that site:
s = 'social.';
Route::get('/social/redirect/{provider}', ['as' => $s . 'redirect', 'uses' => 'Auth\AuthController@getSocialRedirect']);
Route::get('/social/handle/{provider}', ['as' => $s . 'handle', 'uses' => 'Auth\AuthController@getSocialHandle']);
To add new social provider you just need to insert new element in services.php like this:
'facebook' => [
'client_id' => env('FB_ID'),
'client_secret' => env('FB_SECRET'),
'redirect' => env('FB_REDIRECT')
],
'twitter' => [
'client_id' => env('TW_ID'),
'client_secret' => env('TW_SECRET'),
'redirect' => env('TW_REDIRECT')
],
And now you need to create new login link using following route:
route('social.redirect', ['provider' => 'provider_key_from_services']); //example
route('social.redirect', ['provider' => 'facebook']);
route('social.redirect', ['provider' => 'twitter']);
###Todo's Project is not over, I will publish few more tutorials regarding this matter. You can expect:
- Handling when user disallows social app access
- Taking emails of users who sign-up over Twitter and other providers which don't share that data
- User account actions, like change password, change email etc