


The method above handles the callback for twitter only.Ĭall the method on your routes as shown below: Route::get('login/twitter/callback', I would add a link to resources/views/auth/ & resources/views/auth/. The up method in your migration should look like this: public function up() We also make the password field in the users’ table nullable. Here, we are doing the following: adding provider and provider_id columns to the users’ table. Also, when creating users via OAuth we will not be passing any passwords, therefore, we need to set the password field in the migration nullable. To counter this, you can set the email field to nullable but because the aim of this tutorial is to make it possible for a user to signup using any of Facebook, Twitter or Google with the same email and retain their profile, we will not make the email field nullable. With Facebook, there are cases where the user does not have an email set up but a phone number and thus the hash sent back by the callback will not have an email resulting to an error. There are a few things I want us to make changes to before creating the users’ table.Ī user created via OAuth will have a provider and we also need a provider_idwhich should be unique. We will use the migration for creating the users’ table in this example but you can use any migration of your choice. If you look inside database/migrations of your project, you will notice that Laravel already comes with some migrations for creating the users’ and password resets tables.
#LARAVEL SOCIALITE CODE#
The complete code can be found in Github. Laravel Socialite provides an expressive, fluent interface to OAuth authentication with Facebook, Twitter, Google, LinkedIn, GitHub, GitLab and Bitbucket. For this tutorial, we will add Facebook, Twitter, and Google Signups. Socialite currently supports authentication with Facebook, Twitter, LinkedIn, Google, GitHub, and Bitbucket.
#LARAVEL SOCIALITE HOW TO#
In this tutorial, I will show you how to add multiple social providers to a Laravel app using Socialite a package built by Laravel for social authentication. The picture above shows a site that uses the social login for its sign up.
