mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-08-19 09:51:35 +02:00
Merge branch 'feature/openid-support' of https://github.com/indykoning/2FAuth into indykoning-feature/openid-support
This commit is contained in:
44
app/Http/Controllers/Auth/SocialiteController.php
Normal file
44
app/Http/Controllers/Auth/SocialiteController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Facades\Settings;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
|
||||
class SocialiteController extends Controller
|
||||
{
|
||||
public function redirect(Request $request, $driver)
|
||||
{
|
||||
return Socialite::driver($driver)->redirect();
|
||||
}
|
||||
|
||||
public function callback(Request $request, $driver)
|
||||
{
|
||||
$socialiteUser = Socialite::driver($driver)->user();
|
||||
|
||||
/** @var User $user */
|
||||
$user = User::firstOrNew([
|
||||
'email' => $socialiteUser->getEmail(),
|
||||
], [
|
||||
'name' => $socialiteUser->getName(),
|
||||
'password' => bcrypt(Str::random()),
|
||||
]);
|
||||
|
||||
if (!$user->exists && Settings::get('disableRegistrationSso')) {
|
||||
return response(401);
|
||||
}
|
||||
|
||||
$user->last_seen_at = Carbon::now()->format('Y-m-d H:i:s');
|
||||
$user->save();
|
||||
|
||||
Auth::guard()->login($user, true);
|
||||
|
||||
return redirect('/accounts?authenticated');
|
||||
}
|
||||
}
|
@@ -27,6 +27,7 @@ class SinglePageController extends Controller
|
||||
$isTestingApp = config('2fauth.config.isTestingApp') ? 'true' : 'false';
|
||||
$lang = App::getLocale();
|
||||
$locales = collect(config('2fauth.locales'))->toJson(); /** @phpstan-ignore-line */
|
||||
$openidAuth = config('services.openid.client_secret') ? true : false;
|
||||
|
||||
// if (Auth::user()->preferences)
|
||||
|
||||
@@ -35,6 +36,7 @@ class SinglePageController extends Controller
|
||||
'appConfig' => collect([
|
||||
'proxyAuth' => $proxyAuth,
|
||||
'proxyLogoutUrl' => $proxyLogoutUrl,
|
||||
'openidAuth' => $openidAuth,
|
||||
'subdirectory' => $subdir,
|
||||
])->toJson(),
|
||||
'defaultPreferences' => $defaultPreferences,
|
||||
|
Reference in New Issue
Block a user