namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
$event->extendSocialite('google-one-tap', \SocialiteProviders\GoogleOneTap\Provider::class);
});
}
}
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// other providers
\SocialiteProviders\GoogleOneTap\GoogleOneTapExtendSocialite::class,
],
];
}
use Laravel\Socialite\Facades\Socialite;
return Socialite::driver('google-one-tap')->userFromToken($token);
// routes/web.php
use App\Controllers\Auth\GoogleOneTapController;
use Illuminate\Support\Facades\Route;
Route::post('auth/google-one-tap', [GoogleOneTapController::class, 'handler'])
->middleware('guest')
->name('google-one-tap.handler');
// e.g. GoogleOneTapController.php
use App\Models\User;
use Illuminate\Http\Request;
use Laravel\Socialite\Facades\Socialite;
use SocialiteProviders\GoogleOneTap\Exceptions\InvalidIdTokenException;
public function handler(Request $request)
{
// Verify and validate JWT received from Google One Tap prompt
try {
$googleUser = Socialite::driver('google-one-tap')->userFromToken($request->input('credential'));
} catch (InvalidIdTokenException $exception) {
return response()->json(['error' => $exception])
}
// Log the user in if the Google ID is associated with a user
if ($googleUser = User::where('google_id', $googleUser['id'])->first()) {
auth()->login($googleUser);
}
// Send user to registration form to provide missing details like username
return redirect()->view('register.google-one-tap', compact('googleUser'))
}
$select_by = request()->input('select_by')
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.