Hi, It's very easy to add a Github login to your laravel application. Let's understand how we can do this. So, I'm going to practical example now.
Create Github OAuth App
Now, you have to go to...
Gurpreet Kait
Author
Hi, It's very easy to add a Github login to your laravel application. Let's understand how we can do this. So, I'm going to practical example now.
Create Github OAuth App
Now, you have to go to your GitHub account in your account go to Settings>Developer settings>OAuth Apps, and create your app there.
now you have created your app. You will get the secret key and Client id. Come back to your laravel application and do the next steps.
Install A Socialite Package
I'm assuming that you have already installed the Socialite package so that we can implement the GitHub Login in our application. if you are using Breeze or any other authentication package then you have to manage it accordingly, I think you just have to change the paths not anything extra to implement the social GitHub login.
if you have, you don't need to create just implement the methods in that controller with `routes`.
LoginController Will look like this:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Laravel\Socialite\Facades\Socialite;
class LoginController extends Controller
{
public function index()
{
return view('welcome');
}
public function redirectToGithub()
{
return Socialite::driver('github')->redirect();
}
public function callback()
{
$user = Socialite::driver('github')->user();
dd($user); //do whatever with user data
}
}