當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Socialite::driver方法代碼示例

本文整理匯總了PHP中Laravel\Socialite\Facades\Socialite::driver方法的典型用法代碼示例。如果您正苦於以下問題:PHP Socialite::driver方法的具體用法?PHP Socialite::driver怎麽用?PHP Socialite::driver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Laravel\Socialite\Facades\Socialite的用法示例。


在下文中一共展示了Socialite::driver方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: handleFbCallback

 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');
 }
開發者ID:a1ex7,項目名稱:librauth,代碼行數:7,代碼來源:AuthController.php

示例2: handleGoogleProviderCallback

 /**
  * 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');
 }
開發者ID:svetlinyotov,項目名稱:Timeline_v2.0,代碼行數:35,代碼來源:AuthController.php

示例3: handleProviderCallback

 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('/');
 }
開發者ID:alientronics,項目名稱:fleetany-web,代碼行數:29,代碼來源:SocialLoginController.php

示例4: getSocialHandle

 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');
 }
開發者ID:leloulight,項目名稱:holidays-on-village,代碼行數:28,代碼來源:AuthController.php

示例5: callback

 public function callback(SocialAccountService $service, $provider)
 {
     $driver = Socialite::driver($provider);
     $user = $service->createOrGetUser($driver, $provider);
     Auth::login($user, true);
     return redirect()->intended('/');
 }
開發者ID:avil13,項目名稱:lab.friends,代碼行數:7,代碼來源:SocialController.php

示例6: facebookCallback

 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]]);
 }
開發者ID:BePsvPT,項目名稱:CCU,代碼行數:32,代碼來源:OAuthController.php

示例7: google

 /**
  *
  * @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;
     }
 }
開發者ID:Scaledesk,項目名稱:gritwings,代碼行數:34,代碼來源:AuthController.php

示例8: handleProviderCallback

 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());
 }
開發者ID:ncs-jss,項目名稱:elastic-heart,代碼行數:10,代碼來源:AuthController.php

示例9: handleProviderCallback

 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>";
 }
開發者ID:ncs-jss,項目名稱:elastic-heart,代碼行數:10,代碼來源:AuthController.php

示例10: getSocialHandle

 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);
 }
開發者ID:nouzun,項目名稱:gamification,代碼行數:55,代碼來源:AuthController.php

示例11: handleProviderCallback

 /**
  * 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', '/'));
 }
開發者ID:thomasbabuj,項目名稱:gistlog,代碼行數:16,代碼來源:AuthController.php

示例12: authFacebookHandle

 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'));
 }
開發者ID:yohanes1989,項目名稱:goprop,代碼行數:11,代碼來源:AuthController.php

示例13: getProfileGithub

 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;
 }
開發者ID:araujoronald,項目名稱:laravel_lab,代碼行數:11,代碼來源:OAuthProvider.php

示例14: handleFacebookCallback

 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');
 }
開發者ID:mmonbr,項目名稱:20Pavos,代碼行數:11,代碼來源:SocialAuthController.php

示例15: handleProviderCallback

 /**
  * 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/');
 }
開發者ID:ARCANEFORKS,項目名稱:suggestive,代碼行數:16,代碼來源:TwitterOAuthController.php


注:本文中的Laravel\Socialite\Facades\Socialite::driver方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。