Пример #1
1
 /**
  * Handle OAuth login.
  *
  * @param string $provider
  *
  * @return \Laravel\Lumen\Http\Redirector|\Illuminate\Http\RedirectResponse
  */
 public function getOAuth($provider)
 {
     switch ($provider) {
         case 'google':
         case 'facebook':
             if (!$this->request->exists('code')) {
                 return redirect('/login')->withErrors(trans('passwords.oauth_failed'));
             }
             break;
         case 'twitter':
             if (!$this->request->exists('oauth_token') || !$this->request->exists('oauth_verifier')) {
                 return redirect('/login')->withErrors(trans('passwords.oauth_failed'));
             }
             break;
     }
     /** @var SocialiteUser $userInfo */
     $userInfo = $this->socialite->driver($provider)->user();
     if ($this->registrar->loginViaOAuth($userInfo, $provider)) {
         return ['message' => 'Login successful'];
     }
     throw new LoginNotValidException(trans('passwords.oauth_failed'));
 }