示例#1
22
 /**
  * Обробатываем данные с провайдера
  * @param Request $request
  * @param $provider
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|Redirect
  */
 public function oauthHandle(Request $request, $provider)
 {
     try {
         $user = \Socialite::driver($provider)->user();
     } catch (Exception $e) {
         //@TODO уведомление об ошибке типа что то не так!
         return redirect('/');
     }
     $userDB = User::where('oauth_id', $user->getId())->where('provider', $provider)->first();
     if (!is_null($userDB)) {
         Auth::login($userDB);
         if (Auth::check()) {
             //@TODO показываем уведомление об успешной авторизации
             return redirect($this->redirectTo);
         } else {
             //@TODO уведомление об ошибке типа что то не так!
             return redirect('/');
         }
     } else {
         if (!is_null($user->getEmail())) {
             return $this->createAndLogin($user, $provider);
         } else {
             session(['oauth' => $user, 'provider' => $provider]);
             return view('auth.oauth.email');
         }
     }
 }
示例#2
0
 /**
  * Create OAuth User
  * 
  * @param  User      $user
  * @param  Socialite $socialite
  */
 public static function createOAuthUser(User $user, $socialite)
 {
     $oauth_user = new self();
     $oauth_user->provider = $socialite->provider;
     $oauth_user->provider_id = $socialite->getId();
     $oauth_user->provider_token = $socialite->token;
     $user->oauths()->save($oauth_user);
 }
示例#3
0
 /**
  * Create User
  * 
  * @param  Socialite $socialite
  * 
  * @return User      $user
  */
 public static function createUserFromOAuth($socialite)
 {
     $temp_pass = CustomLibrary::generateTempPass($socialite->token);
     $user = new self();
     $user->name = $socialite->getName();
     $user->email = $socialite->getEmail();
     $user->password = bcrypt($temp_pass);
     $user->save();
     // $this->emailTemporaryPassword($temp_pass);
     return $user;
 }
示例#4
0
 /**
  * Obtain the user information from GitHub.
  *
  * @return Response
  */
 public function handleProviderCallback()
 {
     $githubUser = \Socialite::driver('github')->user();
     $id = $githubUser->getId();
     $user = User::where('github_id', $id)->first();
     $token = $githubUser->token;
     // We need to add this token to the session so we can make api calls elsewhere
     session(['access_token' => $token]);
     // If the user exists, just update fields that they may have changed in their Github settings
     if (!is_null($user)) {
         $user->username = $githubUser->getNickname();
         if ($githubUser->getName()) {
             $user->name = $githubUser->getName();
         }
         $user->avatar_url = $githubUser->getAvatar();
         $user->save();
         Auth::login($user);
     } else {
         $user = new User();
         $user->github_id = $id;
         $user->username = $githubUser->getNickname();
         if ($githubUser->getName()) {
             $user->name = $githubUser->getName();
         }
         $user->avatar_url = $githubUser->getAvatar();
         $user->save();
         Auth::login($user);
     }
     return redirect('/auth?authenticated=true');
 }
示例#5
0
 private function handleProviderCallback()
 {
     $user = \Socialite::with('google')->user();
     \Event::fire(new GoogleLoggedIn($user));
     \Auth::login(User::where('google_id', $user->id)->first(), true);
     return \Redirect::to('/')->with('flash_message', ['type' => 'green', 'close' => true, 'header' => 'Your sign in was successful.', 'body' => 'You have correctly authenticated with PandaLove.']);
 }
 public function facebook()
 {
     $user = Socialite::driver('facebook')->user();
     //print_r($user);
     echo $user['id'];
     $userId = Users::getUserId($user['id']);
     if ($userId) {
         Auth::loginUsingId($userId);
         $firstname = Users::getFirstName($userId);
         Session::put('first_name', $firstname);
         $data = "Welcome ";
         return Redirect::to('/dashboard')->with('message', $data . " " . $firstname);
     } else {
         echo "haha";
         return;
         $newUserData['first_name'] = $user['first_name'];
         $newUserData['last_name'] = $user['last_name'];
         $newUserData['email'] = $user['email'];
         $newUserData['uid'] = $user['id'];
         $newUserData['signup_type'] = 2;
         //$newUserData['profile_image'] = "https://graph.facebook.com/"+$result['id']+"/picture?width=250&height=250";
         Session::put('fb', $newUserData);
         return View::make('fbgoogle')->with('newUserData', $newUserData);
     }
     return;
 }
 public function providerLogin($provider)
 {
     // ユーザー情報取得
     $userData = \Socialite::with($provider)->user();
     // ユーザー作成
     $user = App\Models\User::firstOrCreate(['name' => $userData->nickname, 'email' => $userData->email, 'avatar' => $userData->avatar]);
     \Auth::login($user);
     return redirect('/');
 }
示例#8
0
 public function callback($provider)
 {
     $oauthUser = \Socialite::with($provider)->user();
     if (is_null($user = User::where('name', '=', $oauthUser->nickname)->first())) {
         $user = User::create(['name' => $oauthUser->nickname, 'email' => $oauthUser->email, 'avatar' => $oauthUser->avatar]);
     }
     Auth::login($user, true);
     return redirect('articles');
 }
示例#9
0
 public function getFacebookCallback(Request $req)
 {
     $user = \Socialite::with('facebook')->user();
     $data = array('name' => $user->name, 'email' => $user->email, 'password' => $req['code']);
     $request = new Request();
     $request = User::firstOrNew($data);
     $request->save();
     Auth::login($request);
     return redirect('');
 }
 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::to('home');
 }
示例#11
0
 public function callback()
 {
     $qq = \Socialite::with('qq')->user();
     if ($qq != null) {
         $user = $this->createUser($qq);
         Auth::login($user, true);
         return redirect('/');
     } else {
         return view('qq.callback');
     }
 }
示例#12
0
 public function oauth()
 {
     $code = Request::get('code', null);
     $type = Request::get('type', 'weibo');
     if (!$code) {
         return \Socialite::with($type)->redirect();
     }
     $oauth = \Socialite::with($type)->user();
     dd($oauth);
     // return \Socialite::with('weibo')->scopes(array('email'))->redirect();
 }
示例#13
0
 /**
  * @param string $provider
  * @param JWTAuth $jwt
  * @return \Illuminate\Http\Response
  */
 public function getCallback($provider, JWTAuth $jwt)
 {
     if (!in_array($provider, $this->getProviders())) {
         return redirect('/login');
     }
     try {
         $user = \Socialite::driver($provider)->user();
         return $this->handleSocialLogin($jwt, $user, $provider);
     } catch (\Exception $e) {
         return redirect('/login?' . http_build_query(['error' => $e->getMessage()]));
     }
 }
示例#14
0
 public function getSocialAuthCallback()
 {
     try {
         $providerData = \Socialite::with('facebook')->user();
     } catch (Exception $e) {
         return redirect('/login/facebook');
     }
     $user = User::where('provider_user_id', $providerData->id)->where('provider', 'facebook')->orWhere('email', $providerData->email)->first();
     if (!$user) {
         $user = User::create(['email' => $providerData->email, 'name' => $providerData->name, 'provider' => "facebook", 'provider_user_id' => $providerData->id]);
     }
     Auth::login($user, true);
     return redirect('/dashboard');
 }
示例#15
0
 public function signInVkCallback()
 {
     try {
         $user = \Socialite::driver('vkontakte')->user();
     } catch (Exception $e) {
         return Redirect::to('signin/vk');
     }
     if ($authUser = $this->findOrCreateUser($user, 'vkontakte')) {
         \Auth::login($authUser, true);
         return \Redirect::to('/');
     } else {
         return \Redirect::to('signin')->with('provider_signin_error', 'Your email that we getting from VKONTAKTE network already registered in the system. Maybe you have to authorize with the other social networks?');
     }
 }
示例#16
0
 public function handleProviderCallback($provider)
 {
     $providerUser = Socialite::driver($provider)->user();
     switch ($provider) {
         case 'stripe':
             SellerMeta::create(['user_id' => Auth::user()->id, 'key' => 'stripe_token', 'value' => $providerUser->token]);
             SellerMeta::create(['user_id' => Auth::user()->id, 'key' => 'stripe_id', 'value' => $providerUser->id]);
             break;
         default:
             # code...
             break;
     }
     Auth::user()->assignRole('seller');
     return redirect()->route('seller.show', Auth::user()->id)->withSuccess('Successfully added Stripe credentials.');
 }
示例#17
0
 public function handleProviderCallback()
 {
     $user = \Socialite::with('github')->user();
     // OAuth One Providers
     $token = $user->token;
     $tokenSecret = $user->tokenSecret;
     echo $token;
     /*if(Auth::attempt($credentials)){
     
     			return Redirect::to('admin');
     
     		} else {
     
     			return Redirect::to('login');
     		}*/
 }
示例#18
0
 public function pageFacebook()
 {
     $socialize_user = \Socialite::with($provider)->user();
     $facebook_user_id = $socialize_user->getId();
     // unique facebook user id
     $user = Contributors::where('facebook_user_id', $facebook_user_id)->first();
     // register (if no user)
     if (!$user) {
         $user = new Contributors();
         $user->facebook_id = $facebook_user_id;
         $user->save();
     }
     // login
     Auth::loginUsingId($user->id);
     return redirect('/');
 }
示例#19
0
 public function getLoginFacebook()
 {
     $provider = \Socialite::with('facebook');
     if (\Input::has('code')) {
         $user = $provider->user();
         $check_email = $this->mst_user->where('email', '=', $user->email)->first();
         if (count($check_email) > 0) {
             //jika email ada di db, forced to login
             \Auth::loginUsingId($check_email->id);
             \Log::info('login using id');
             return redirect()->intended($this->redirectPath());
         } else {
             \Log::info('gagal login, user tdk ditemukan');
             return redirect()->back()->withErrors(['email' => 'User tidak ditemukan.']);
         }
     } else {
         \Log::info('gagal login');
         return $provider->redirect();
     }
 }
示例#20
0
 /**
  * Attempt to log in an user using a social authentication provider.
  *
  * @param  Illuminate\Http\Request $request
  * @param  string
  * @return Response
  */
 public function loginWithProvider(Request $request, $providerSlug)
 {
     // Use provider name as the throttling cache key
     $request['provider'] = $providerSlug;
     // Check if there are too many login attempts for current provider and IP
     if ($this->hasTooManyLoginAttempts($request)) {
         // Flash error message
         $seconds = (int) \Cache::get($this->getLoginLockExpirationKey($request)) - time();
         $message = sprintf(_('Please try again in %d seconds.'), $seconds);
         return $this->goBack(_('Too many login attempts') . '. ' . $message);
     }
     $this->incrementLoginAttempts($request);
     // If the remote provider sends an error cancel the process
     foreach (['error', 'error_message', 'error_code'] as $error) {
         if ($request->has($error)) {
             return $this->goBack(_('Something went wrong') . '. ' . $request->get($error));
         }
     }
     // Get provider
     $provider = Provider::whereSlug($providerSlug)->firstOrFail();
     // Make sure it's usable
     if (!$provider->isUsable()) {
         return $this->goBack(_('Unavailable provider'));
     }
     // Set provider callback url
     config(["services.{$provider->slug}.redirect" => \URL::current()]);
     // Create an Oauth service for this provider
     $oauthService = \Socialite::with($provider->slug);
     // Check if current request is a callback from the provider
     if ($request->has('oauth_token') or $request->has('code')) {
         $this->clearLoginAttempts($request);
         return $this->loginSocialUser($provider, $oauthService->user());
     }
     // If we have configured custom scopes use them
     if ($scopes = config("services.{$provider->slug}.scopes")) {
         $oauthService->scopes($scopes);
     }
     // Request user to authorize our App
     return $oauthService->redirect();
 }
示例#21
0
 /**
  * Login with Facebook.
  */
 public function facebook(Request $request)
 {
     $name = 'facebook';
     if ($request->has('redirectUri')) {
         config()->set("services.{$name}.redirect", $request->get('redirectUri'));
     }
     $provider = Socialite::driver($name);
     $provider->stateless();
     //$fb_profile = $provider->user();
     // Step 1 + 2
     try {
         $fb_user = Socialite::driver('facebook')->user();
     } catch (\Exception $e) {
         //return redirect('auth/login')->withErrors(['error' => $e->getMessage()]); // http://localhost/pasu/public/auth/login
         return response()->json(["error" => $e->getMessage()], 500);
     }
     // Handle the user etc.
     // Step 3. Create a new user account or return an existing one.
     $authUser = $this->findOrCreateUser($fb_user);
     $token = JWTAuth::fromUser($auth_user);
     return response()->json(compact('token'));
 }
示例#22
0
 protected function driver(string $provider, bool $popup = false) : Provider
 {
     $driver = \Socialite::driver($provider);
     switch ($provider) {
         case 'facebook':
             /** @var \Laravel\Socialite\Two\FacebookProvider $driver */
             $driver->scopes(['public_profile', 'email', 'user_about_me', 'user_birthday', 'user_website', 'user_work_history'])->fields(['first_name', 'last_name', 'gender', 'email', 'birthday', 'website', 'bio', 'work']);
             if ($popup) {
                 $driver->asPopup();
             }
             break;
         case 'github':
             /** @var \Laravel\Socialite\Two\GithubProvider $driver */
             $driver->scopes(['user', 'user:email']);
             break;
         case 'linkedin':
             /** @var \Laravel\Socialite\Two\LinkedInProvider $driver */
             $driver->scopes(['r_basicprofile', 'r_emailaddress']);
             //those are actually consumer's hard settings
             break;
         case 'google':
             /** @var \Laravel\Socialite\Two\GoogleProvider $driver */
             // nothing to do here
             break;
         case 'live':
             /** @var \SocialiteProviders\Live\Provider $driver */
             $driver->scopes(['wl.basic', 'wl.emails', 'wl.birthday', 'wl.calendars_update', 'wl.events_create', 'wl.work_profile']);
             break;
         case 'twitter':
             /** @var \Laravel\Socialite\One\TwitterProvider $driver */
         /** @var \Laravel\Socialite\One\TwitterProvider $driver */
         case 'bitbucket':
             /** @var \Laravel\Socialite\One\BitbucketProvider $driver */
             // there's nothing to be done with OAuth 1.0 clients
             break;
     }
     return $driver;
 }
示例#23
0
 public function callback(SocialAccountService $service, $provider)
 {
     $user = $service->createOrGetUser(\Socialite::driver($provider)->user(), $provider);
     Auth::login($user);
     return redirect()->to('/home');
 }
示例#24
0
 /**
  * Obtain the user information from GitHub.
  *
  * @return Response
  */
 public function handleProviderCallback()
 {
     $user = Socialite::driver('github')->user();
     // $user->token;
 }
示例#25
0
/**
 *
 * BlogPost Routes
 *
 */
Route::get('addblogpost', 'BlogPostController@create');
Route::post('addblogpost', 'BlogPostController@store');
Route::get('blog/index/', 'BlogPostController@index');
Route::get('blog/{id}', 'BlogPostController@show');
Route::post('/blog/addcomment/{id}', 'BlogPostController@addComment');
Route::get('blog/tags/{slug}', 'BlogPostController@showByTag');
/**
 *
 * Contacts route
 *
 */
Route::get('contacts', 'HomeController@contacts');
Route::post('contacts', 'HomeController@contactsProcess');
/**
 * Route for social auth
 */
Route::get('/socialite/{provider}', ['as' => 'socialite.auth', function ($provider) {
    return \Socialite::driver($provider)->redirect();
}]);
Route::get('/socialite/{provider}/callback', 'SocialController@supervisor');
Route::get('sitemap', 'SitemapsController@posts');
Route::get('recip/{post}', ['as' => 'post.show', function (App\Post $post) {
    $title = $post->htmltitle . ' | ' . App\Models\CmsOption::getValue('Название сайта');
    $metaOptions = ['recipie' => $post];
    return view('recipieSingle', ['recipie' => $post, 'title' => $title, 'metaOptions' => $metaOptions]);
}]);
示例#26
0
 public function check(Request $request)
 {
     $user = \Socialite::driver('vkontakte')->user();
     print_r($user);
     exit;
 }
示例#27
0
 /**
  * Get google user details
  * @return mixed
  */
 private function getGoogleUser()
 {
     return \Socialite::with('google')->user();
 }
示例#28
0
 /**
  * Obtain the user information from GitHub.
  *
  * @return Response
  */
 public function handleGitHubCallback()
 {
     $gh_user = \Socialite::driver('github')->user();
     if (\Auth::check()) {
         $user = \Auth::user();
         $user->github_id = $gh_user->getId();
         $user->github_token = $gh_user->token;
         $user->save();
         return redirect()->action('Auth\\AuthController@edit')->withMessage('Your GitHub account has been connected!');
     }
     $user = User::where('github_id', $gh_user->getId())->first();
     $name = explode(' ', $gh_user->name);
     if ($user) {
         \Auth::login($user);
         $user->github_token = $gh_user->token;
         $user->save();
         return redirect()->intended($this->redirectPath());
     } else {
         $user = User::where('email', $gh_user->getEmail())->first();
         if ($user) {
             return redirect()->back()->withErrors(['github' => 'You have not authorized your SD Hacks account for GitHub. Please log in to do so.']);
         } else {
             $user = new User();
             $user->email = $gh_user->getEmail();
             $user->github_token = $gh_user->token;
             $user->github_id = $gh_user->getId();
             $user->save();
             return view('auth.success');
         }
     }
 }
示例#29
0
 public function handleProviderCallback()
 {
     try {
         $user = Socialite::driver('facebook')->user();
     } catch (Exception $e) {
         return redirect('/');
     }
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return redirect('/');
 }
            return redirect(config('app.website') . '/twitter-callback.html?id=' . $tokenId . '&username='******'Cannot get user id!');
        }
    } catch (Exception $e) {
        abort(422, 'Error logging into twitter!');
    }
}]);
Route::get('instagram/login/{userId}', ['as' => 'instagram.login', function ($userId) {
    Request::session()->put('instagram_user_id', $userId);
    return Socialite::driver('instagram')->redirect();
}]);
Route::get('instagram/callback', ['as' => 'instagram.callback', function () {
    try {
        if (Request::session()->has('instagram_user_id')) {
            $user = Socialite::driver('instagram')->user();
            $tokenId = 0;
            if (!($socialAccount = UserSocialToken::where('type', '=', 'instagram')->where('user_id', '=', Request::session()->get('instagram_user_id'))->whereNull('expires_at')->first())) {
                $userSocialToken = new UserSocialToken();
                $userSocialToken->type = 'instagram';
                $userSocialToken->expires_at = null;
                $userSocialToken->short_lived_token = $user->token;
                $userSocialToken->long_lived_token = $user->token;
                $userSocialToken->entity_id = $user->id;
                $userSocialToken->entity_name = $user->nickname;
                $userSocialToken->user_id = Request::session()->get('instagram_user_id');
                $userSocialToken->save();
                $tokenId = $userSocialToken->id;
            } else {
                $socialAccount->short_lived_token = $user->token;
                $socialAccount->long_lived_token = $user->token;