Пример #1
0
 public function handleProviderCallback(Guard $auth, Socialite $socialite, UsersService $userService, SessionManager $manager)
 {
     $user = $socialite->with('vkontakte')->user();
     $authUser = $userService->findOrCreateByVk($user);
     $auth->login($authUser);
     $manager->driver()->save();
     return redirect('/');
 }
Пример #2
0
 /**
  * @param null $provider
  * @return string
  */
 public function getSocialAuthCallback($provider = null)
 {
     if ($user = $this->socialite->with($provider)->user()) {
         $this->checkSocialUser($user, $provider);
         return redirect('home');
     } else {
         return 'something went wrong';
     }
 }
Пример #3
0
 /**
  * Process the Facebook callback, ensure they gave us the correct permissions, create the user if they don't exist, and log them in.
  *
  * @return mixed
  */
 public function getSocialAuthCallback()
 {
     $user = $this->socialite->with('facebook')->user();
     if (!$this->validateUserFacebookAttributes($user)) {
         return $this->getFacebookReSocialAuth();
     }
     if (User::where('facebook_id', $user->id)->get()->count() === 0) {
         $dbUser = $this->createUserFromSocialite($user);
     } else {
         $dbUser = User::where('facebook_id', $user->id)->get()->first();
     }
     Auth::loginUsingId($dbUser->id);
     return redirect('/');
 }
 /**
  * Handle sociel authentication callback.
  */
 public function authCallback(Socialite $socialite, $provider)
 {
     $auth = $socialite->with($provider)->user();
     $userAuth = UserAuth::where('uid', '=', $auth->getId())->first();
     if ($userAuth) {
         $user = $userAuth->user;
     } else {
         if ($auth->getEmail()) {
             $user = User::where('email', '=', $auth->getEmail())->first();
             if (is_null($user)) {
                 $user = User::create(['name' => $auth->getName(), 'username' => $auth->getNickname(), 'email' => $auth->getEmail()]);
             }
         } else {
             $user = User::create(['name' => $auth->getName(), 'username' => $auth->getNickname()]);
         }
         $userAuth = UserAuth::create(['provider' => $provider, 'uid' => $auth->getId()]);
         $userAuth->user()->associate($user);
         $userAuth->save();
     }
     Auth::loginUsingId($user->id);
     return redirect()->intended('/')->with(array('message' => 'Your are now logged in!', 'message_type' => 'success'));
 }
Пример #5
0
 /**
  * Obtain the user information from Provider.
  *
  * @param  string          $provider
  * @param  Socialite|SocialiteManager       $socialite
  * @param  User  $userModel
  *
  * @throws UnprocessableEntityException
  *
  * @return ApiResponse
  */
 public function handleProviderCallback($provider, Socialite $socialite, User $userModel)
 {
     $this->validateProvider($provider);
     $socialUser = $socialite->with($provider)->user();
     // Verify so we received an email address, if using oAuth credentials
     // with Twitter for instance, that isn't whitelisted, no email
     // address will be returned with the response.
     // See the notes in Spira API doc under Social Login for more info.
     if (!$socialUser->email) {
         // The app is connected with the service, but the 3rd party service
         // is not configured or allowed to return email addresses, so we
         // can't process the data further. Let's throw an exception.
         \Log::critical('Provider ' . $provider . ' does not return email.');
         throw new UnprocessableEntityException('User object has no email');
     }
     // Parse the social user to fit within Spira's user model
     $socialUser = ParserFactory::parse($socialUser, $provider);
     // Get or create the Spira user from the social login
     try {
         $user = $userModel->findByEmail($socialUser->email);
     } catch (ModelNotFoundException $e) {
         $user = $userModel->newInstance();
         $user->fill(array_merge($socialUser->toArray(), ['user_type' => 'guest']));
         $user->save();
     }
     $socialLogin = new SocialLogin(['provider' => $provider, 'token' => $socialUser->token]);
     $user->addSocialLogin($socialLogin);
     // Prepare response data
     $token = $this->jwtAuth->fromUser($user, ['method' => $provider]);
     $returnUrl = $socialite->with($provider)->getCachedReturnUrl() . '?jwtAuthToken=' . $token;
     $response = $this->getResponse();
     $response->redirect($returnUrl, 302);
     return $response;
 }