/** * Обробатываем данные с провайдера * @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'); } } }
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; }
/** * 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'); }
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'); }
/** * @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()])); } }
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?'); } }
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.'); }
/** * 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')); }
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; }
/** * Obtain the user information from GitHub. * * @return Response */ public function handleProviderCallback() { $user = Socialite::driver('github')->user(); // $user->token; }
/** * * 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]); }]);
public function check(Request $request) { $user = \Socialite::driver('vkontakte')->user(); print_r($user); exit; }
public function bitbucketHandleProviderCallback() { $social_user = \Socialite::driver('bitbucket')->user(); $social_user->avatar = str_replace("/avatar/32/", "/avatar/256/", $social_user->avatar); return $this->checkSocialUser($social_user, 'bitbucket_id'); }
/** * 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'); } } }
public function handleProviderCallback() { try { $user = Socialite::driver('facebook')->user(); } catch (Exception $e) { return redirect('/'); } $authUser = $this->findOrCreateUser($user); Auth::login($authUser, true); return redirect('/'); }
public function handleProviderCallback(\Request $request, $provider) { $user = \Socialite::driver($provider)->user(); dd($user); }
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;
/** * Obtain the user information from GitHub. * * @return Response */ public function handleProviderCallback() { $user = \Socialite::driver('facebook')->user(); $userx = $user->token; return redirect()->route('getnews')->with('token', $userx); }
| and give it the controller to call when that URI is requested. | */ Route::get('/', function () { // $user = Socialite::driver('facebook')->user(); // dd($user->getId()); // $userId = $user->id; // return view('index')->with('userId', $userId); return view('index'); }); Route::get('/auth/facebook', function () { return Socialite::driver('facebook')->redirect(); }); Route::get('/callback/facebook', function (App\User $user) { // from: http://stackoverflow.com/a/30825601/633056 $socialite = Socialite::driver('facebook')->user(); if (App\User::where('email', '=', $socialite->email)->first()) { $checkUser = App\User::where('email', '=', $socialite->email)->first(); Auth::login($checkUser); return redirect('/'); } $user->facebook_id = $socialite->getId(); $user->name = $socialite->getName(); $user->email = $socialite->getEmail(); $user->avatar = $socialite->getAvatar(); $user->save(); Auth::login($user); return redirect('/'); }); Route::get('/auth/logout', function () { Auth::logout();
|-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/login', function () { return Socialite::with('github')->redirect(); }); Route::get('/session', function (Illuminate\Http\Request $req) { // Hack to set client_id and other params required to // issue an access token // Ideally I'd like to do something like issueForUserId... But alas!!! $req->request->set('client_id', 'id'); $req->request->set('client_secret', 'secret'); $req->request->set('grant_type', 'user'); $github = Socialite::driver('github'); $github->stateless(); $githubUser = $github->user(); $user = App\User::firstOrNew(['email' => $githubUser->email]); if (!$user->exists) { $user->name = $githubUser->name; $user->password = str_random(16); $user->save(); } Auth::login($user); return Response::json(Authorizer::issueAccessToken()); });
private function getAuthorizationFirst($provider) { return \Socialite::driver($provider)->redirect(); }
public function callback(SocialAccountService $service, $provider) { $user = $service->createOrGetUser(\Socialite::driver($provider)->user(), $provider); Auth::login($user); return redirect()->to('/home'); }
<?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It is a breeze. Simply tell Lumen the URIs it should respond to | and give it the Closure to call when that URI is requested. | */ $app->get('/', function () use($app) { return Socialite::driver('github')->redirect(); }); $app->get('callback', function () { $user = Socialite::driver('github')->user(); $client = new \Github\Client(); $client->authenticate(config('services.github.user_token'), config('services.github.user_password'), Github\Client::AUTH_URL_TOKEN); $client->organization('wearehx')->teams()->addMember(config('services.github.team'), $user->user['login']); return redirect('https://github.com/wearehx'); });