first commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?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);
|
||||
});
|
||||
Reference in New Issue
Block a user