/** * Attempt to log in an user using a social authentication provider. * * @param string * @return Response */ public function loginWithProvider($providerSlug) { // If the remote provider sends an error cancel the process foreach (['error', 'error_message', 'error_code'] as $error) { if (Input::has($error)) { return $this->goBack(_('Something went wrong') . '. ' . Input::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::set("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 (Input::has('oauth_token') or Input::has('code')) { 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(); }
/** * 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(); }