anjanesh's avatar

Laravel Socialite in a non-Laravel project

I had a PHP project done using vanilla PHP before I started to learn Laravel. I need to integrate Login with Social links now. Is it doable (I mean, not by editing a lot of original source code) to use Laravel Socialite in a non-Laravel project ? https://laravel.com/docs/10.x/socialite

0 likes
6 replies
LaryAI's avatar
Level 58

Yes, it is possible to use Laravel Socialite in a non-Laravel project. Here's how you can do it:

  1. Install Laravel Socialite using Composer:
composer require laravel/socialite
  1. Create a new file, let's say socialite.php, in your non-Laravel project.

  2. In socialite.php, require the Composer autoloader and import the necessary classes:

require 'vendor/autoload.php';

use Laravel\Socialite\Facades\Socialite;
  1. 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 redirect method:
$redirectUrl = Socialite::driver('github')->redirect()->getTargetUrl();
header("Location: $redirectUrl");
exit;
  1. 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 user method:
$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.

juanma386's avatar

@LaryAI Sorry team; My try is with proyect CI4::4.4.3 CodeIgniter; Plain first is working php8.2; Server local shell advanced deployment with linux debian 10

<?php
namespace App\Controllers\Auth;
...
use CodeIgniter\HTTP\RedirectResponse;
use Laravel\Socialite\Facades\Socialite;
...
	   // Facade not found; where is implement this root class;
       Facade::add('socialite', 'Laravel\Socialite\Facades\Socialite');
       $redirectUrl = Socialite::driver($driver, (array)config('Social'))->redirect();
	   header("Location: $redirectUrl");
	   exit;

Please need instructions to appy "fake" Facades to solve this implement and use this code;

agent47's avatar

@LaryAI please can you give me any hint, i'm working in a project where login required with azure. i have setup the method for login (regular company emails) but i need to add also personal email, here comes the hard part, users with personal email don't have the possibility for password reset. it redirects them back to /login with error message

juanma386's avatar

Sorry team of comment without sentide, this idea is deprecated; Solve problem with profesional library Hybridauth; Socialite is a native of library laravel; It is not feasible to create a new library again.

1 like
anjanesh's avatar

Hybridauth has not been updated since 2020 ? Why does it still use jQuery ?

Please or to participate in this conversation.