/** * Google+側で認証後にリダイレクトされてくる * */ public function getCallback() { // TODO: 認証エラー処理 (認証キャンセルされると、500エラーで返ってくる) // ユーザー情報を取得 $userData = $this->socialite->driver('google')->user(); // 情報取得 $sns_id = $userData->getId(); //ユーザID $sns_name = $userData->getName(); //名前 $sns_email = $userData->getEmail(); //メールアドレス // ユーザーが登録済かチェック $user = User::where('oauth_flg', "google")->where('oauth_id', $sns_id)->first(); if (!$user) { //自分のuserテーブル登録されていないユーザなので新規ユーザ //ユーザ登録の処理 User::create(['name' => $sns_name, 'email' => $sns_email, 'password' => bcrypt('google%' . $sns_id), 'oauth_flg' => 'google', 'oauth_id' => $sns_id]); //登録したユーザー情報を取得 $user = User::where('oauth_flg', "google")->where('oauth_id', $sns_id)->first(); } //ログイン Auth::login($user); // リダイレクト return redirect('/tasks'); }
/** * Obtain the user information from Eve Online. * * @param \Laravel\Socialite\Contracts\Factory $social * * @return \Seat\Web\Http\Controllers\Auth\Response */ public function handleProviderCallback(Socialite $social) { $eve_data = $social->driver('eveonline')->user(); // Check if there is a SeAT account with the same name. If this is the // case, we need to confirm the current password for the user before // we convert the account to an SSO account. if (User::where('name', $eve_data->name)->where('eve_id', null)->first()) { // Store the data from Eveonline in the sesion. session()->put('eve_sso', $eve_data); // Redirect to the password confirmation page. return redirect()->route('auth.eve.confirmation.get'); } // Get or create the User bound to this login. $user = $this->findOrCreateUser($eve_data); // Login the account auth()->login($user, true); // Check if an account was just logged in for the first // time using SSO and ask for an email address if its required. if (User::where('name', $eve_data->name)->where('active', 0)->first() && setting('require_activation', true) == 'yes') { // Redirect to the password confirmation page. return redirect()->route('auth.eve.email'); } // Set the main characterID based on the response. $this->setCharacterId($eve_data); return redirect()->intended(); }
/** * Handle redirection from GitHub OAuth * * @param SocialiteManager $socialiteManager * @param UserService $userService * * @return \Illuminate\Http\RedirectResponse */ public function handleGitHubRdirect(SocialiteManager $socialiteManager, UserService $userService) { $user = $socialiteManager->driver('github')->user(); $id = $userService->registerUser($user); \Auth::driver('github')->loginUsingId($id); return redirect()->route('main'); }
function it_creates_a_user_if_authorization_is_granted(Factory $socialite, UserRepository $users, Authenticator $auth, User $user, AuthenticateUserListener $listener) { $socialite->driver('github')->willReturn(new ProviderStub()); $users->findByUsernameOrCreate(ProviderStub::$data)->willReturn($user); $auth->login($user, self::HAS_CODE)->shouldBeCalled(); $listener->userHasLoggedIn($user)->shouldBeCalled(); $this->execute(self::HAS_CODE, $listener); }
public function handleProviderCallback(Guard $auth, Socialite $socialite, UsersService $userService, SessionManager $manager) { $user = $socialite->driver('facebook')->user(); $authUser = $userService->findOrCreateByFacebook($user); $auth->login($authUser); $manager->driver()->save(); return redirect('/'); }
/** * @param boolean $hasCode * @param AuthenticateUserListener $listener * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function github($hasCode, AuthenticateUserListener $listener) { if (!$hasCode) { return $this->socialite->driver('github')->redirect(); } $user = $this->users->findOrCreate($this->socialite->driver('github')->user(), 'github'); $this->auth->login($user, true); return $listener->userHasLoggedIn($user); }
/** * @param $driver * @return array */ public function getUser($driver) { $userData = $this->socialite->driver($driver)->user(); switch ($driver) { case 'facebook': return ['name' => $userData->name, 'email' => $userData->email, 'avatar' => $userData->avatar, 'facebook_user_id' => $userData->id]; } return []; }
public function __construct(Socialite $socialite) { $this->driver = $this->getDriver(); // Set redirect URL config(["services.{$this->driver}.redirect" => route('social.callback', $this->driver)]); $this->client = $this->getClient(); $this->provider = $socialite->driver($this->driver); $this->socialite = $socialite; }
public function callback() { \Config::set("services.{$this->driver}.redirect", action(\Config::get("services.{$this->driver}.redirect_action"))); $serviceUser = $this->socialite->driver($this->driver)->user(); $serviceUserId = $serviceUser->getId(); $name = $serviceUser->getName(); $email = $serviceUser->getEmail(); $authUserId = $this->serviceAuthenticationService->getAuthModelId($this->driver, ['service' => $this->driver, 'service_id' => $serviceUserId, 'name' => $name, 'email' => $email]); if (!empty($authUserId)) { $this->authenticatableService->signInById($authUserId); } return redirect()->action($this->redirectAction); }
/** * When the user has authenticated it will return to this route. * * @param Authentication $authentication * @param $driver * @return \Illuminate\Http\RedirectResponse */ public function callback(Authentication $authentication, $driver) { if (!in_array($driver, $this->availableProviders)) { return abort(404); } app()->configure('services'); try { $socialiteUser = $this->socialite->driver($driver)->user(); $authentication->loginOrCreateUser($socialiteUser, $driver); return redirect('/'); } catch (Exception $e) { return redirect('login-failed'); } }
/** * Obtain the user information from facebook. * * @return Response */ public function handleProviderCallback() { $user = Socialite::driver('facebook')->user(); //dd($user); //return $user; //return $user->token; }
/** * Show the application login form. * * @param string $provider * * @return \Symfony\Component\HttpFoundation\Response|array */ public function getLogin($provider = null) { if (!is_null($provider)) { return $this->socialite->driver($provider)->redirect(); } return ['message' => 'Ready']; }
/** * @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'; } }
/** * Find the existing user or create a new one for this account. * * @param $provider * * @throws EmailAlreadyInUse * * @return User */ public function findOrCreateUser($provider) : User { /** @var \Laravel\Socialite\Two\User $providerUser */ $providerUser = $this->socialite->driver($provider)->user(); $user = User::byProvider($provider, $providerUser->id)->first(); if (is_null($user)) { $user = User::where('email', $providerUser->getEmail())->first(); // If provider isn't associated with user, do that now if (is_null($user)) { return $this->registrar->create($provider, $providerUser); } $userProvider = app(UserProvider::class, [['provider' => $provider, 'provider_id' => $providerUser->getId()]]); $user->providers()->save($userProvider); return $user; } // update the avatar if it has changed if (!is_null($providerUser->getAvatar()) && $user->avatar != $providerUser->getAvatar()) { $user->update(['avatar' => $providerUser->getAvatar()]); } return $user; }
/** * Obtain the user information from Facebook. * */ public function handleProviderCallback() { try { //https://developers.facebook.com/docs/graph-api/reference/user $user = $this->socialite->driver('facebook')->fields(['name', 'first_name', 'last_name', 'email', 'gender', 'verified'])->user(); } catch (Exception $e) { return redirect('auth/facebook'); } $authUser = $this->findOrCreateUser($user); Auth::login($authUser, true); return redirect()->route('home')->with(['success' => 'You are now logged in with your Facebook account']); }
/** * 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')); }
/** * 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('/'); }
/** * @return \Laravel\Socialite\Contracts\User */ private function getSocialUser() { $user = $this->socialite->driver($this->provider)->user(); // check how many fb friends if ($this->provider == 'facebook') { $friendCount = 0; try { $data = file_get_contents("https://graph.facebook.com/v2.5/me/friends?access_token=" . $user->token); if ($data) { $dataArr = json_decode($data); if (isset($dataArr->summary)) { $friendCount = $dataArr->summary->total_count; } } } catch (\Exception $e) { throw new \RuntimeException($e->getMessage()); } if ($friendCount <= 0) { return ['user' => $user, 'success' => false, 'message' => 'Facebook account must have at least 10 friends!']; } } return ['user' => $user, 'success' => true]; }
/** * Constructs the OAuthController. * * @param \Laravel\Socialite\Contracts\Factory */ public function __construct(Socialite $socialite) { $this->socialite = $socialite->driver('github')->scopes(['user:email', 'public_repo', 'repo', 'read:repo_hook', 'write:repo_hook', 'admin:repo_hook', 'admin:org_hook']); $this->middleware('guest', ['except' => 'out']); }
public function __construct(Factory $socialite, Redirector $redirector) { $this->socialite = $socialite->driver('youtube'); $this->redirector = $redirector; }
/** * @param $provider * @return \Laravel\Socialite\Contracts\User */ public function getSocialUser($provider) { return $this->socialite->driver($provider)->user(); }
/** * @return \Laravel\Socialite\Contracts\User */ private function getUser($provider) { return $this->socialite->driver($provider)->user(); }
private function getAuthorizationFirst() { return $this->socialiteFactory->driver('github')->scopes(['user:email', 'read:org', 'repo'])->redirect(); }
private function getGoogleUser() { return $this->socialite->driver('google')->user(); }
private function getProviderUser($provider) { // dd($this->socialite->driver($provider)->user()); return $this->socialite->driver($provider)->user(); }
public function __construct(Socialite $social) { $this->github = $social->driver('github'); }
private function getGitHubUser() { return $this->socialite->driver('github')->user(); }
/** * @return \Laravel\Socialite\Contracts\User */ private function getSocialUser($provider = 'google') { return $this->socialite->driver($provider)->user(); }
/** * user method * * @param $driverName * * @return \Codex\Addon\Auth\Socialite\User */ protected function user($driverName) { $driver = $this->social->driver($driverName); return $driver->user(); }
/** * Handle OAuth login. * * @param \Illuminate\Http\Request $request * @param \Laravel\Socialite\Contracts\Factory $socialite * @param string $provider * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse */ public function handleOAuthReturn(Request $request, SocialiteContract $socialite, $provider) { switch ($provider) { case 'google': case 'facebook': if (!$request->exists('code')) { return redirect('/login')->withErrors(trans('passwords.oauth_failed')); } break; case 'twitter': if (!$request->exists('oauth_token') || !$request->exists('oauth_verifier')) { return redirect('/login')->withErrors(trans('passwords.oauth_failed')); } break; } /** @var SocialiteUser $userInfo */ $userInfo = $socialite->driver($provider)->user(); if ($this->loginViaOAuth($userInfo, $provider)) { return redirect()->intended($this->redirectPath()); } return redirect('/login')->withErrors(trans('passwords.oauth_failed')); }