Step 1: Install Laravel 8
First, create a new Laravel project:
Step 2: Install Laravel UI (Optional for scaffolding authentication)
If you're using Laravel 8 or earlier and want to add the authentication UI (login, register views), you can install the Laravel UI package.
This command generates all necessary views and routes for basic authentication.
Step 3: Update Your Database Credentials
Open the .env
file and update your database credentials:
Make sure to replace the GOOGLE_CLIENT_ID
, FACEBOOK_CLIENT_ID
, and GITHUB_CLIENT_ID
with the actual credentials from the respective developer platforms.
Step 4: Install Socialite
To enable OAuth authentication, install the Laravel Socialite package:
Then, add the Socialite service provider to your config/app.php
:
Step 5: Add Socialite Configuration
In config/services.php
, add the configuration for Google, Facebook, and GitHub:
Step 6: Create the User Migration
Create a migration file to store user data, including provider info for social login:
In the generated migration file, update the up()
method like so:
Then, run the migration:
Step 7: Add Routes for Social Authentication
Add the routes for Google, Facebook, and GitHub authentication in routes/web.php
:
Step 8: Create the LoginController
Create the LoginController
:
In the LoginController
, add the methods to handle the social logins:
Step 9: Add Social Login Buttons to the Login Page
Modify resources/views/auth/login.blade.php
to include social login buttons:
Step 10: Run the Development Server
Finally, run the Laravel development server:
Visit the following URL in your browser:
Final Notes
-
Ensure that you've registered your app on Google, Facebook, and GitHub developer consoles and obtained the correct credentials (Client ID and Client Secret).
-
Ensure your
.env
file contains the correct credentials for each service.