- return redirect($this->redirectPath());
- }
-
- /**
- * Redirect to the social site for authentication intended to register.
- * @param $socialDriver
- * @return mixed
- * @throws UserRegistrationException
- * @throws SocialDriverNotConfigured
- */
- public function socialRegister($socialDriver)
- {
- $this->checkRegistrationAllowed();
- session()->put('social-callback', 'register');
- return $this->socialAuthService->startRegister($socialDriver);
- }
-
- /**
- * The callback for social login services.
- * @param Request $request
- * @param string $socialDriver
- * @return RedirectResponse|Redirector
- * @throws SocialSignInException
- * @throws UserRegistrationException
- * @throws SocialDriverNotConfigured
- */
- public function socialCallback(Request $request, string $socialDriver)
- {
- if (!session()->has('social-callback')) {
- throw new SocialSignInException(trans('errors.social_no_action_defined'), '/login');
- }
-
- // Check request for error information
- if ($request->has('error') && $request->has('error_description')) {
- throw new SocialSignInException(trans('errors.social_login_bad_response', [
- 'socialAccount' => $socialDriver,
- 'error' => $request->get('error_description'),
- ]), '/login');
- }
-
- $action = session()->pull('social-callback');
-
- // Attempt login or fall-back to register if allowed.
- $socialUser = $this->socialAuthService->getSocialUser($socialDriver);
- if ($action == 'login') {
- try {
- return $this->socialAuthService->handleLoginCallback($socialDriver, $socialUser);
- } catch (SocialSignInAccountNotUsed $exception) {
- if ($this->socialAuthService->driverAutoRegisterEnabled($socialDriver)) {
- return $this->socialRegisterCallback($socialDriver, $socialUser);
- }
- throw $exception;
- }
- }
-
- if ($action == 'register') {
- return $this->socialRegisterCallback($socialDriver, $socialUser);
- }
-
- return redirect()->back();
- }