Login to an OAuth2 service.

@param string                                $provider
@param \OAuth\Common\Service\AbstractService $service

@return Redirect
542363
protected function oauth2Login($provider, $service)
	{
		if ($code = Input::get('code')) {
			try {
				$token = $service->requestAccessToken($code);
			} catch (Exception $e) {
				return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
					->with(
						Config::get('laravel-social::error_flash_var'),
						'There was a problem logging in to your account (2).'
					);
			}
			
			return $this->processLogin($provider, $service, array(
				'token'         => $token->getAccessToken(),
				'refresh_token' => $token->getRefreshToken(),
				'end_of_life'   => $token->getEndOfLife(),
				'extra_params'  => $token->getExtraParams(),
			));
		}
		
		return Redirect::to((string) $service->getAuthorizationUri());
	}
461410
public function buildProvider($provider, $config)
    {
        $provider = new $provider(
            $this->app['request'], $config['client_id'],
            $config['client_secret'], $config['redirect_uri']
        );

        $provider->setBaseURL($config['tokenpass_url']);

        return $provider;
    }
978858
public function getApplicableAuthenticators($service = Authenticator::LOGIN)
    {
        $authenticators = $this->getAuthenticators();

        /** @var Authenticator $authenticator */
        foreach ($authenticators as $name => $authenticator) {
            if (!($authenticator->supportedServices() & $service)) {
                unset($authenticators[$name]);
            }
        }

        if (empty($authenticators)) {
            throw new LogicException('No applicable authenticators found');
        }

        return $authenticators;
    }
29188
protected function loadDeferredProvider($service)
	{
		$provider = $this->deferredServices[$service];

		// If the service provider has not already been loaded and registered we can
		// register it with the application and remove the service from this list
		// of deferred services, since it will already be loaded on subsequent.
		if ( ! isset($this->loadedProviders[$provider]))
		{
			$this->registerDeferredProvider($provider, $service);
		}
	}
1372112
static function createProvider($key, $redirect) {
    switch ($key) {
      case "google":
        return self::google($redirect);
      case "facebook":
        return self::facebook($redirect);
      case "github":
        return self::github($redirect);

      break;
        throw new UserAuthenticationException("No such known OAuth2 provider '$key'");
    }
  }
927709
public function loginAndRegisterVia($provider)
    {
        $this->authenticationService = $this->authenticationServiceFactory->getInstance($provider);

        $isUserLoggedIn = $this->accountService->checkUser();

        // active sw login session
        if ($isUserLoggedIn) {
            return $isUserLoggedIn;
        }

        if ($this->authenticationService !== null) {
            // sso login
            $isAuthenticated = $this->authenticationService->login();
            $customer = null;
            if ($isAuthenticated) {
                // get user data from sso provider
                $user = $this->authenticationService->getUser();
                if ($user !== null && $user->getEmail() !== '') {
                    // get sw customer
                    $customer = $this->customerService->getCustomerByIdentity($provider, $user->getId());
                    if ($customer !== null) {
                        // new login
                        $isUserLoggedIn = $this->tryLoginCustomer($customer);
                    } else {
                        $customer = $this->customerService->getCustomerByEmail($user->getEmail());
                        if ($customer !== null) {
                            // connect
                            $customer = $this->registerService->connectUserWithExistingCustomer($user, $customer);
                        } else {
                            // register
                            $customer = $this->registerService->registerCustomerByUser($user);
                        }
                        $isUserLoggedIn = $this->tryLoginCustomer($customer);
                    }
                }
            } else {
                $isUserLoggedIn = false;
            }

            $this->container->get('events')->notify(
                'Port1HybridAuth_Service_SingleSignOn_CustomerLoggedIn',
                [
                    'customer' => $customer,
                    'isUserLoggedIn' => $isUserLoggedIn
                ]
            );
        }
        return $isUserLoggedIn;
    }
1176030
public function redirectToProvider($provider)
    {
        return Socialite::driver($provider)->scopes(Config::get('services.'.$provider.'.scopes'))->redirect();
    }
66594
public function register($provider, $options = array()) //, $force = false)
	{
		/*if ($registered = $this->getRegistered($provider) && !$force)
		{
			return $registered;
		}*/

		// If the given "provider" is a string, we will resolve it, passing in the
		// application instance automatically for the developer. This is simply
		// a more convenient way of specifying your service provider classes.
		if (is_string($provider))
		{
			$provider = $this->resolveProviderClass($provider);
		}

		$provider->register();

		// Once we have registered the service we will iterate through the options
		// and set each of them on the application so they will be available on
		// the actual loading of the service objects and for developer usage.
		foreach ($options as $key => $value)
		{
			$this[$key] = $value;
		}

		// Since service providers can do more than just register callbacks,
		// we need to track the loaded providers for futher use later in the
		// application.
		$this->markAsRegistered($provider);

		// If the application has already booted, we will call this boot method on
		// the provider class so it has an opportunity to do its boot logic and
		// will be ready for any usage by the developer's application logics.
		if ($this->booted)
		{
			$this->bootProvider($provider);
		}

		return $this;
	}
1002833
public function registerProvider($provider)
    {
        if (($provider = $this->getProvider($provider))) {
        } elseif (is_string($provider)) {
            $provider = $this->resolveProvider($provider);
        }

        if ($this->registeredProvider($provider)) {
            return $provider;
        }

        if (method_exists($provider, 'register')) {
            $provider->register();
        }

        $this->markAsRegistered($provider);

        // If the application has already booted, we will call this boot method on
        // the provider class so it has an opportunity to do its boot logic and
        // will be ready for any usage by this developer's application logic.
        if ($this->booted) {
            $this->bootProvider($provider);
        }
        return $provider;
    }
481780
public function run( $service ) {

        return $this->redirectWithMessages(
            $this->synchronizer->disconnect( $service ),
            Yii::t( 'SyncSocial', 'Service was successfully disconnected' ),
            Yii::t( 'SyncSocial', 'There is error in disconnection' )
        );
    }
1207551
protected function oauth1Login($provider, $service)
	{
		if ($oauth_token = Input::get('oauth_token')) {
			try {
				$token = $service->requestAccessToken(
					$oauth_token,
					Input::get('oauth_verifier'),
					$service->getStorage()->retrieveAccessToken($provider)->getRequestTokenSecret()
				);
			} catch (Exception $e) {
				return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
					->with(
						Config::get('laravel-social::error_flash_var'),
						'There was a problem logging in to your account (3).'
					);
			}
			
			return $this->processLogin($provider, $service, array(
				'token'         => $token->getAccessToken(),
				'secret'        => $token->getAccessTokenSecret(),
				'refresh_token' => $token->getRefreshToken(),
				'end_of_life'   => $token->getEndOfLife(),
				'extra_params'  => $token->getExtraParams(),
			));
		}
		
		try {
			// Extra request needed for oauth1 to get a request token.
			$token = $service->requestRequestToken();
		} catch (Exception $e) {
			return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
				->with(
						Config::get('laravel-social::error_flash_var'),
						'There was a problem logging in to your account (4).'
					);
		}
		
		return Redirect::to((string) $service->getAuthorizationUri(array(
			'oauth_token' => $token->getRequestToken(),
		)));
	}
257367
public function callback($provider = null)
    {
        $this->getProviderDetails($provider);

        $socialUser = Socialite::driver($this->driver)->user();
        $user       = User::where('email', $socialUser->getEmail())
                          ->orWhereHas('socials', function ($query) use ($socialUser) {
                              $query->where('user_socials.email', $socialUser->getEmail())->where('provider', $this->driver);
                          })->first();

        if (is_null($user)) {
            $user = $this->register($socialUser);
        }

        if (! $user->hasProvider($this->driver)) {
            $user->addSocial($socialUser, $this->driver);
        } else {
            $user->getProvider($this->driver)->updateFromProvider($socialUser, $this->driver);
        }

        auth()->login($user, request('remember', false));
        event(new UserLoggedIn($user, $socialUser));

        return redirect()
            ->intended(route('home'))
            ->with('message', 'You have been logged in.');
    }
291906
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /**
         * @var \Zend\Authentication\AuthenticationService $service
         */
        $service   = $serviceLocator->get('Zend\Authentication\AuthenticationService');
        $assertion = new IsLoggedIn($service);

        return $assertion;
    }
1057965
public function login($service, $config = array())
    {
        $config = new AnConfig($config);

        $config->append(array(
            'html' => $this->icon($service),
            'url' => $this->url($service),
            'attributes' => array(),
        ));

        $html = $this->getService('com:base.template.helper.html');

        $link = $html->link($config->html, $config->url, $config->attributes)
                     ->class('btn btn-'.$service)
                     ->dataTrigger('PostLink')
                     ->title($service);

        return $link;
    }
46859
protected function _handleLoginAction(ServerRequest $request, Response $response)
    {
        $request->allowMethod($this->getConfig('requestMethod'));

        $providerName = $request->getParam('provider');
        $provider = $this->_getService($request)->getProvider($providerName);
        $authUrl = $provider->makeAuthUrl();

        $this->_setRedirectUrl($request);

        return $response->withLocation($authUrl);
    }
63716
public function clearCSRFState(string $service):OAuthStorageInterface{

		if(array_key_exists($service, $_SESSION[$this->stateVar])){
			unset($_SESSION[$this->stateVar][$service]);
		}

		return $this;
	}
1020295
public function signInWithProvider($provider_name, Request $request)
    {
        $provider = $this->getProvider($provider_name, $request);

        if (!$provider) {
            return $this->response(['errors' => [
                'code'    => 'PROVIDER_NOT_FOUND',
                'message' => 'No provider found',
            ]], Response::HTTP_BAD_REQUEST);
        }

        $provider->stateless();

        if ($request->input('code') !== null) {
            try {
                return $this->authenticateByCode($provider, $request->input('code'));
            } catch (\Exception $e) {
                return $this->response([
                    'code'    => 'CODE_NOT_VALID',
                    'message' => 'Code invalid or expired'.$e->getMessage(),
                ], Response::HTTP_BAD_REQUEST);
            }
        }
    }