本文整理汇总了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');
}
示例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');
}
示例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('/');
}
示例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');
}
示例5: callback
public function callback(SocialAccountService $service, $provider)
{
$driver = Socialite::driver($provider);
$user = $service->createOrGetUser($driver, $provider);
Auth::login($user, true);
return redirect()->intended('/');
}
示例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]]);
}
示例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;
}
}
示例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());
}
示例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>";
}
示例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);
}
示例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', '/'));
}
示例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'));
}
示例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;
}
示例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');
}
示例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/');
}