本文整理汇总了PHP中Laravel\Socialite\Facades\Socialite类的典型用法代码示例。如果您正苦于以下问题:PHP Socialite类的具体用法?PHP Socialite怎么用?PHP Socialite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Socialite类的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: boot
/**
* 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: 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]]);
}
示例4: handle
/**
* 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: 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');
}
示例6: 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('/');
}
示例7: 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');
}
示例8: callback
public function callback(SocialAccountService $service, $provider)
{
$driver = Socialite::driver($provider);
$user = $service->createOrGetUser($driver, $provider);
Auth::login($user, true);
return redirect()->intended('/');
}
示例9: handleProviderCallback
public function handleProviderCallback()
{
$user = Socialite::with('battlenet')->user();
$authUser = $this->findOrCreateUser($user);
Auth::login($authUser, true);
return redirect()->route('home');
}
示例10: 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;
}
}
示例11: getSocialAuthCallback
public function getSocialAuthCallback($provider = null)
{
if ($user = Socialite::with($provider)->user()) {
dd($user);
} else {
return 'something went wrong';
}
}
示例12: getLogin
/**
* 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: 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());
}
示例14: 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>";
}
示例15: 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);
}