Yes, it is possible to use Laravel Socialite in a non-Laravel project. Here's how you can do it:
- Install Laravel Socialite using Composer:
composer require laravel/socialite
-
Create a new file, let's say
socialite.php, in your non-Laravel project. -
In
socialite.php, require the Composer autoloader and import the necessary classes:
require 'vendor/autoload.php';
use Laravel\Socialite\Facades\Socialite;
- You can now use Laravel Socialite in your non-Laravel project. For example, to redirect the user to the social login provider, you can use the
redirectmethod:
$redirectUrl = Socialite::driver('github')->redirect()->getTargetUrl();
header("Location: $redirectUrl");
exit;
- After the user logs in with the social provider and is redirected back to your non-Laravel project, you can retrieve the user details using the
usermethod:
$user = Socialite::driver('github')->user();
Note that you may need to configure the social providers in the config/services.php file. However, since you're not using Laravel, you'll need to manually set the configuration options in your socialite.php file.
Remember to replace 'github' with the appropriate social provider you want to use (e.g., 'facebook', 'google', etc.).
That's it! You can now integrate Laravel Socialite into your non-Laravel project.