redirect() : redirect('/error?err=sso_disabled'); } /** * Register (if needed) the user and authenticate him * * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse */ public function callback(Request $request, string $driver) { try { $socialiteUser = Socialite::driver($driver)->user(); } catch (\Exception $e) { return redirect('/error?err=sso_failed'); } /** @var User|null $user */ $user = User::firstOrNew([ 'oauth_id' => $socialiteUser->getId(), 'oauth_provider' => $driver, ]); if (! $user->exists) { if (User::count() === 0) { $user->is_admin = true; } else if (Settings::get('disableRegistration')) { return redirect('/error?err=no_register'); } $user->password = bcrypt(Str::random()); } $user->email = $socialiteUser->getEmail() ?? $socialiteUser->getId() . '@' . $driver; $user->name = $socialiteUser->getNickname() ?? $socialiteUser->getName() ?? $driver . ' #' . $socialiteUser->getId(); $user->last_seen_at = Carbon::now()->format('Y-m-d H:i:s'); $user->save(); Auth::guard()->login($user); return redirect('/accounts'); } }