Пример #1
1
 public function handleFbCallback()
 {
     $fb_user = Socialite::driver('facebook')->user();
     $user = User::firstOrCreate(['firstname' => $fb_user->user['first_name'], 'lastname' => $fb_user->user['last_name'], 'email' => $fb_user->email]);
     Auth::login($user, true);
     return Redirect::to('/books');
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     Socialite::extend('google2', function () {
         $config = $this->app['config']['services.google'];
         return Socialite::buildProvider(\App\GoogleProvider::class, $config);
     });
 }
Пример #3
0
 public function facebookCallback()
 {
     try {
         $facebook = Socialite::driver('facebook')->scopes(['email'])->user();
         // 確認使用者有提供 Email
         if (null === $facebook->getEmail()) {
             throw new OAuthException();
         }
         // 如果 Email 不存在,創見帳號,如 Email 已存在,則略過此步驟
         if (null === ($account = Account::where('email', '=', $facebook->getEmail())->first(['id']))) {
             $account = Account::create(['email' => $facebook->getEmail(), 'password' => str_random(32)]);
             if (!$account->exists) {
                 throw new ModelNotFoundException();
             }
             $account->load(['user'])->getRelation('user')->update(['nickname' => $facebook->getName() . '@facebook']);
         }
         \Auth::loginUsingId($account->getAttribute('id'), true);
         return redirect()->route('home');
     } catch (ClientException $e) {
         $data = ['您似乎並未允許本網站存取您的資料', false];
     } catch (InvalidStateException $e) {
         $data = ['似乎出了點狀況,請嘗試重新登入', false];
     } catch (ModelNotFoundException $e) {
         $data = ['網站似乎出了點狀況,請稍候再嘗試', false];
     } catch (OAuthException $e) {
         $data = ['您似乎並未允許本網站存取您的信箱', true];
     } catch (\Exception $e) {
         $data = ['網站似乎出了點狀況,請稍候再嘗試', false];
         \Log::error('Non-catch exception.', ['code' => $e->getCode(), 'message' => $e->getMessage()]);
     }
     return view('errors.oauthFailed', ['message' => $data[0], 'invalidEmail' => $data[1]]);
 }
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     if (in_array($this->provider, $this->allowedProviders)) {
         $user = User::findByUserNameOrCreate(Socialite::with($this->provider)->user());
         $this->auth->login($user);
     }
 }
Пример #5
0
 /**
  * Obtain the user information from Google.
  *
  * @param Request $request
  * @return Socialite ->user()
  */
 public function handleGoogleProviderCallback(Request $request)
 {
     if ($request->get('error') == "access_denied") {
         return redirect('/');
     }
     $authorizationCode = $request->get('code');
     $googleTokens = Tokens::getGoogleTokens($authorizationCode);
     //return var_dump($googleTokens);
     $user = Socialite::driver('google')->getUserByToken($googleTokens->access_token);
     $email = $user['emails'][0]['value'];
     $name = $user['name']['givenName'] . " " . $user['name']['familyName'];
     $avatar = $user['image']['url'];
     if (!GoogleUser::existsByEmailAndId($email, Auth::user()->id) && isset($googleTokens->refresh_token)) {
         GoogleUser::create(['user_id' => Auth::user()->id, 'email' => $email, 'names' => $name, 'avatar' => $avatar, 'googleAccessToken' => $googleTokens->access_token, 'googleRefreshToken' => $googleTokens->refresh_token, 'uriCode' => $authorizationCode, 'expireValue' => $googleTokens->expires_in]);
         return redirect('/availability/google')->with(['message' => 'You have linked this profile (' . $email . ')']);
     } elseif (GoogleUser::existsByEmailAndId($email, Auth::user()->id) && isset($googleTokens->refresh_token)) {
         $id = GoogleUser::where('email', '=', $email)->where('user_id', '=', Auth::user()->id)->select('id')->first()->pluck('id')['id'];
         GoogleUser::updateTokens($id, ['googleAccessToken' => $googleTokens->access_token, 'googleRefreshToken' => $googleTokens->refresh_token, 'uriCode' => $authorizationCode, 'expireValue' => $googleTokens->expires_in]);
         return redirect('/availability/google')->with(['message' => 'You already have this profile (' . $email . '). Data is updated.']);
     } elseif (GoogleUser::existsByEmailAndId($email, Auth::user()->id) && !isset($googleTokens->refresh_token)) {
         return redirect('/availability/google')->with(['message' => 'You already have this profile (' . $email . ')']);
     } elseif (!GoogleUser::existsByEmailAndId($email, Auth::user()->id) && !isset($googleTokens->refresh_token)) {
         return redirect('/availability/google')->withErrors(['Missing refresh token. Contact the administrator.']);
     } else {
         return var_dump($authorizationCode, $googleTokens, $user);
         abort(500, "Auth error. Contact the admin");
     }
     return redirect('/availability/google');
 }
 public function handleProviderCallback($provider, Request $request)
 {
     try {
         $user = Socialite::driver($provider)->user();
         if (!empty($request->session()->get('token'))) {
             $userPending = User::where('remember_token', $request->session()->get('token'))->first();
             if (empty($userPending) || $userPending->email != $user->email) {
                 if ($provider == 'google') {
                     $request->session()->flash('error', Lang::get("general.LoginGoogleFailed"));
                 } else {
                     $request->session()->flash('error', Lang::get("general.LoginFacebookFailed"));
                 }
                 return redirect('/create-account/' . $request->session()->get('token'));
             }
             $userPending->pending_company_id = null;
             $userPending->save();
         }
     } catch (\Exception $e) {
         if ($provider == 'google') {
             $request->session()->flash('error', Lang::get("general.LoginGoogleFailed"));
         } else {
             $request->session()->flash('error', Lang::get("general.LoginFacebookFailed"));
         }
         return redirect('/auth/login');
     }
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return redirect('/');
 }
 public function getSocialHandle($provider)
 {
     $user = Socialite::driver($provider)->user();
     $socialUser = null;
     $userCheck = User::where('email', '=', $user->email)->first();
     // Create new user id doesn't exists
     if (!empty($userCheck)) {
         $socialUser = $userCheck;
     } else {
         $socialUser = User::create(['name' => $user->name, 'email' => $user->email, 'avatar' => $user->avatar]);
     }
     // End
     // Update social information
     if ($socialUser->google() and $provider == 'google') {
         $socialUser->google()->save($this->fillSocialData($user));
     }
     if ($socialUser->facebook() and $provider == 'facebook') {
         $socialUser->facebook()->save($this->fillSocialData($user));
     }
     if ($socialUser->twitter() and $provider == 'twitter') {
         $socialUser->twitter()->save($this->fillSocialData($user));
     }
     // End
     // Authenticate user
     Auth::login($socialUser);
     // End
     return redirect()->route('home');
 }
Пример #8
0
 public function callback(SocialAccountService $service, $provider)
 {
     $driver = Socialite::driver($provider);
     $user = $service->createOrGetUser($driver, $provider);
     Auth::login($user, true);
     return redirect()->intended('/');
 }
Пример #9
0
 public function handleProviderCallback()
 {
     $user = Socialite::with('battlenet')->user();
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return redirect()->route('home');
 }
Пример #10
0
 /**
  *
  * @param Request $request
  *
  * @return mixed
  */
 public function google(Request $request)
 {
     if ($request->has('redirectUri')) {
         config()->set("services.google.redirect", $request->get('redirectUri'));
     }
     $provider = Socialite::driver('google');
     $provider->stateless();
     $profile = $provider->user();
     $email = $profile->email;
     $name = $profile->name;
     $google_token = $profile->token;
     $google_id = $profile->id;
     $user = User::where('email', $email)->first();
     if (is_null($user)) {
         $data = ['email' => $email, 'name' => $name, 'password' => null, 'confirmation_code' => null, 'confirmed' => '1', 'social_auth_provider_access_token' => $google_token, 'google_id' => $google_id, 'social_auth_provider' => 'google', 'social_auth_provider_id' => $google_id];
         $user = User::create($data);
         $response = Response::json($user);
         return $response;
     } else {
         $user->google_id = $google_id;
         $user->social_auth_provider_access_token = $profile->token;
         $user->social_auth_provider_id = $profile->id;
         $user->social_auth_provider = 'google';
         $user->save();
         $response = Response::json($user);
         return $response;
     }
 }
Пример #11
0
 public function getSocialAuthCallback($provider = null)
 {
     if ($user = Socialite::with($provider)->user()) {
         dd($user);
     } else {
         return 'something went wrong';
     }
 }
Пример #12
0
 /**
  * Store a newly created resource in storage.
  * @Get("/{provider}/callback", as="social.login.getLogin")
  * @param string $provider
  * @return \Illuminate\Http\Response
  */
 public function getLogin($provider)
 {
     $userData = Socialite::with($provider)->user();
     Log::debug(print_r($userData, true));
     $user = User::firstOrCreate(['username' => $userData->nickname, 'email' => $userData->email]);
     Auth::login($user);
     return response()->redirectToRoute('articles.getIndex');
 }
Пример #13
0
 public function handleProviderCallback()
 {
     //notice we are not doing any validation, you should do it
     $user = Socialite::driver($provider)->user();
     // stroing data to our use table and logging them in
     $data = ['name' => $user->getName(), 'google' => $user->getEmail()];
     Auth::login(User::firstOrCreate($data));
     //after login redirecting to home page
     return redirect($this->redirectPath());
 }
Пример #14
0
 public function handleProviderCallback($provider)
 {
     //notice we are not doing any validation, you should do it
     $user = Socialite::driver($provider)->user();
     // stroing data to our use table and logging them in
     $data = ['name' => $user->getName(), 'email' => $user->getEmail()];
     //   Auth::login(User::firstOrCreate($data));
     //after login redirecting to home page
     return "<h1>Hello " . $user->getName() . "</h1>";
 }
Пример #15
0
 public function getSocialHandle($provider)
 {
     $user = Socialite::driver($provider)->user();
     $socialUser = null;
     //Check is this email belongs to OZU
     if (!preg_match('/((ozu|ozyegin)\\.edu(\\.[a-zA-Z]+)?|\\.ac\\.[a-zA-Z]+)$/i', $user->email)) {
         return redirect()->route('auth.login')->with('message', 'You can only login with your.name@(ozu|ozyegin).edu.tr')->with('status', 'danger')->withInput();
     }
     //Check is this email present
     $userCheck = User::where('email', '=', $user->email)->first();
     if (!empty($userCheck)) {
         $socialUser = $userCheck;
     } else {
         $sameSocialId = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
         if (empty($sameSocialId)) {
             //There is no combination of this social id and provider, so create new one
             $newSocialUser = new User();
             $newSocialUser->email = $user->email;
             $parts = explode("@", $user->email);
             $username = explode(".", $parts[0]);
             $alt_name = ucfirst($username[0]);
             $alt_last = ucfirst($username[1]);
             $name = explode(' ', $user->name);
             $newSocialUser->first_name = isset($name[0]) && !empty($name[0]) ? $name[0] : $alt_name;
             $newSocialUser->last_name = isset($name[2]) ? $name[2] : (isset($name[1]) ? $name[1] : $alt_last);
             $newSocialUser->save();
             $socialData = new Social();
             $socialData->social_id = $user->id;
             $socialData->provider = $provider;
             $newSocialUser->social()->save($socialData);
             // Add role
             if (in_array($user->email, $this->privilegedEmails)) {
                 $role = Role::whereName('administrator')->first();
             } else {
                 $role = Role::whereName('user')->first();
             }
             $newSocialUser->assignRole($role);
             $socialUser = $newSocialUser;
         } else {
             //Load this existing social user
             $socialUser = $sameSocialId->user;
         }
     }
     $this->auth->login($socialUser, true);
     if ($this->auth->user()->hasRole('user')) {
         return redirect('/');
     }
     if ($this->auth->user()->hasRole('administrator')) {
         return redirect('/');
     }
     if ($this->auth->user()->hasRole('super')) {
         return redirect('/');
     }
     return App::abort(500);
 }
Пример #16
0
 /**
  * Obtain the user information from GitHub.
  *
  * @return Response
  */
 public function handleProviderCallback(Request $request)
 {
     $user = Socialite::driver('google')->user();
     $token = $user->token;
     // All Providers
     $user->getId();
     $user->getNickname();
     $user->getName();
     $user->getEmail();
     $user->getAvatar();
 }
 public function handleProviderCallback($provider)
 {
     try {
         $user = Socialite::driver($provider)->user();
     } catch (\Exception $e) {
         return redirect('/faurgs/auth/' . $provider);
     }
     $authUser = $this->findOrCreateUser($user);
     \Auth::login($authUser, true);
     return redirect('/faurgs/unidades');
 }
Пример #18
0
 /**
  * Send User to Oauth URL
  */
 public function connect($provider_name, $redir)
 {
     session(['oauth_redir' => $redir]);
     try {
         $provider = Provider::where('provider_safe_name', '=', $provider_name)->firstOrFail();
     } catch (ModelNotFoundException $e) {
         echo 'Caught exception: ', $e->getMessage(), "\n";
         exit;
     }
     return Socialite::driver($provider_name)->redirect();
 }
Пример #19
0
 public function handleFacebookCallback()
 {
     $facebook = Socialite::driver('facebook')->user();
     if (empty(User::where('email', $facebook->getEmail())->first())) {
         $user = User::firstOrCreate(['first_name' => $facebook->getName(), 'email' => $facebook->getEmail(), 'password' => bcrypt('55555')]);
         Auth::login($user, true);
     } else {
         Auth::login(User::where('email', $facebook->getEmail())->first(), true);
     }
     return Redirect::to('/books');
 }
Пример #20
0
 /**
  * Obtain the user information from facebook
  *
  * @return response
  */
 public function handleProviderCallback()
 {
     try {
         $user = Socialite::driver('facebook')->user();
     } catch (Exception $e) {
         return redirect('auth/facebook');
     }
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return redirect()->route('home');
 }
Пример #21
0
 public function authFacebookHandle()
 {
     try {
         $user = Socialite::driver('facebook')->user();
     } catch (Exception $e) {
         return redirect()->route('frontend.account.auth.facebook');
     }
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return redirect(route('frontend.account.dashboard'));
 }
 public function handleProviderCallback($provider)
 {
     try {
         $user = Socialite::driver($provider)->user();
     } catch (\Exception $e) {
         return \Redirect::to('auth/social/' . $provider);
     }
     $authUser = $this->findOrCreateUser($user, $provider);
     \Auth::login($authUser, true);
     return \Redirect::to('dashboard');
 }
Пример #23
0
 /**
  * Obtain the user information from Google.
  *
  * @return Response
  */
 public function handleProviderCallback()
 {
     try {
         $data = Socialite::driver('google')->user();
     } catch (\Exception $e) {
         return redirect()->route('auth.signin')->withWarning('Authentication failed. Try again later.');
     }
     $user = $this->userResolver->findOrCreateUser($data);
     Auth::login($user, true);
     return redirect()->intended(route('home'))->withInfo($this->pullRandomQuote());
 }
 /**
  * Obtain the user information from GitHub.
  *
  * @return Response
  */
 public function handleProviderCallback()
 {
     try {
         $user = Socialite::driver('twitter')->user();
     } catch (Exception $e) {
         return redirect('auth/twitter');
     }
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return redirect('dashboard/');
 }
 /**
  * Obtain the user information from authentication service provider.
  *
  * @return Response
  */
 public function handleProviderCallback($provider)
 {
     try {
         $user = Socialite::driver($provider)->user();
     } catch (Exception $e) {
         return Redirect::to('auth/$provider');
     }
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return Redirect::to('home');
 }
Пример #26
0
 public function handleFacebookCallback()
 {
     $user = Socialite::driver('facebook')->user();
     if (User::where('email', '=', $user->email)->first()) {
         alert()->success('La dirección de email asociada al perfil social con el que estás intentando iniciar sesión ya se encuentra en nuestra base de datos.', 'Oops.')->persistent('OK');
         return redirect(route('home'));
     }
     $authUser = $this->findOrCreateUser($user, 'Facebook');
     auth()->login($authUser, true);
     return view('auth.close');
 }
Пример #27
0
 /**
  * Obtain the user information from GitHub.
  *
  * @return Response
  */
 public function handleProviderCallback()
 {
     try {
         $user = Socialite::driver('github')->user();
     } catch (Exception $e) {
         return Redirect::to('auth/github');
     }
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return redirect(session()->get('redirect_to', '/'));
 }
Пример #28
0
 /**
  * Obtain the user information from Google.
  *
  * @return Response
  */
 public function handleProviderCallback()
 {
     try {
         $user = Socialite::with('google2')->user();
     } catch (ClientException $e) {
         Log::error($e->getResponse()->getBody()->getContents());
     }
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return redirect('/');
 }
 public function handleProviderCallBack()
 {
     $user = Socialite::driver('facebook')->user();
     $token = $user->token;
     $user->getName();
     $user->getAvatar();
     session()->put('name', $user->getName());
     session()->put('avatar', $user->getAvatar());
     //        dd($user);
     return redirect()->action('HomeController@home');
 }
Пример #30
0
 public static function getProfileGithub($request)
 {
     $provider = Socialite::driver('github');
     $provider->setRequest($request);
     $userOAuth = $provider->stateless()->user();
     $user = new User();
     $user->nome = $userOAuth->getName();
     $user->email = $userOAuth->getEmail();
     $user->avatar = $userOAuth->getAvatar();
     return $user;
 }