-
composer.json
Open in GitHub{ // "require": { "php": "^8.0", // "laravel/socialite": "^5.0" }, // }
-
app/Http/Controllers/Auth/GithubController.php
Open in GitHubuse App\Http\Controllers\Controller; use Laravel\Socialite\Facades\Socialite; use Laravel\Socialite\Two\User as SocialiteUser; class GithubController extends Controller { public function redirectToProvider() { return Socialite::driver('github')->redirect(); } public function handleProviderCallback() { try { $socialiteUser = $this->getSocialiteUser(); } catch (InvalidStateException $exception) { $this->error('errors.github_invalid_state'); return redirect()->route('login'); } try { $user = User::findByGithubId($socialiteUser->getId()); } catch (ModelNotFoundException $exception) { return $this->userNotFound(new GithubUser($socialiteUser->getRaw())); } return $this->userFound($user, $socialiteUser); } private function getSocialiteUser(): SocialiteUser { return Socialite::driver('github')->user(); } // }
-
routes/web.php
Open in GitHubuse Illuminate\Support\Facades\Route; use App\Http\Controllers\Auth\GithubController; // Route::namespace('Auth')->group(function () { // Route::get('login/github', [GithubController::class, 'redirectToProvider'])->name('login.github'); Route::get('auth/github', [GithubController::class, 'handleProviderCallback']); }); //
-
resources/views/auth/login.blade.php
Open in GitHub// <a href="{{ route('login.github') }}" class="button button-dark mb-4"> <span class="flex items-center justify-center"> <x-icon-github class="inline h-4 w-4 mr-2" /> Github </span> </a> //