Files
2026-06-10 08:30:03 +00:00

28 lines
745 B
PHP
Executable File

<?php
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str;
use Laravel\Socialite\Facades\Socialite;
Route::get('/auth/redirect', function () {
$targetUrl = request()->query('target_url', url('/'));
Session::put('target_url', $targetUrl);
return Socialite::driver('google')->redirect();
});
Route::get('/auth/callback', function () {
$googleUser = Socialite::driver('google')->user();
$token = $googleUser->token;
$targetUrl = Session::pull('target_url', url('/'));
$separator = parse_url($targetUrl, PHP_URL_QUERY) ? '&' : '?';
$redirectUrl = $targetUrl . $separator . 'access_token=' . urlencode($token);
return redirect()->to($redirectUrl);
});