Login using social service.

@param $serviceName string social service name
@param $response    AbstractUser response data

@throws SocialException
421007
public function login($serviceName, AbstractUser $response)
    {
        $userId = $this->repo->getUserIdBySocialId($response->id, $serviceName);
        if (auth()->check()) { // user already logged and service has not been connected
            $user = auth()->user();
            if ($userId) { // This service has already been connected
                session()->put('url.intended', route('connectedServices'));
                throw new SocialException(
                    trans(
                        'gzero-social::common.service_already_connected_message',
                        ['service_name' => title_case($serviceName)]
                    )
                );
            } else { // create connection for new service
                $this->repo->addUserSocialAccount($user, $serviceName, $response);
            }
        } else {
            if ($userId) { // login user with this service
                $this->auth->loginUsingId($userId);
            } else { // create new user
                $user = $this->repo->createNewUser($serviceName, $response);
                $this->auth->login($user);
                session()->put('showWelcomePage', true);
                session()->put('url.intended', route('account.welcome', ['method' => title_case($serviceName)]));
            }
        }
    }
840055
private function registerService(ContainerBuilder $container, $serviceId, $serviceClass)
    {
        if (class_exists($serviceClass)) {
            $container->register($serviceId, $serviceClass);
        }
    }
802024
public function socialLogin($serviceName)
    {
        if (config('services.' . $serviceName)) {
            $this->setDynamicRedirectUrl($serviceName);
            return $this->socialite->driver($serviceName)->redirect();
        }
        return redirect('/');
    }
1051192
public function init($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret, $bearerToken)
    {
        $this->twitter->setConsumerKey($consumerKey, $consumerSecret);

        if (! is_null($bearerToken)) {
            $this->setBearerToken($bearerToken);
        } elseif (! is_null($oauthToken) && ! is_null($oauthTokenSecret)) {
            $this->setToken($oauthToken, $oauthTokenSecret);
        } elseif ($this->hasSessionToken()) {
            $this->setSessionToken();
        }
    }
520561
private function validateResponse($response) {
        if ($response->getStatusCode() !== 200) {
            $statusCode = $response->getStatusCode();
            throw new ServerException('Server responded with HTTP status ' . $statusCode, $statusCode);
        } else if (strpos($response->getHeader('Content-Type')[0], 'application/json') === false) {
            throw new ServerException('Server did not respond with the expected content-type (application/json)');
        }

        try {
            $body = (string) $response->getBody();
            $json = json_decode($body, true);
            if (json_last_error()) {
                throw new ServerException(json_last_error_msg());
            }
        } catch (RuntimeException $e) {
            throw new ServerException($e->getMessage());
        }
    }
334679
private function activate($container, ArrayResolver $serviceConfig, $serviceName)
    {
        $this->typeInitializer->initialize($container, $serviceConfig);

        $activator = $this->activatorFactory->getActivator($serviceName, $serviceConfig);

        return $activator->createInstance($container, $serviceConfig, $serviceName);
    }
1018476
public static function oneById($serviceName, $id)
	{
		if(!self::has($serviceName)) {
			return null;
		}
		/** @var ReadOneInterface $serviceInstance */
		$serviceInstance = self::get($serviceName);
		try {
			$result = $serviceInstance->oneById($id);
		} catch (NotFoundHttpException $e) {
			$result = null;
		}
		return $result;
	}
403702
public function authenticate($username, $password, $tenantName)
	{
		$command = $this->identityClient->getCommand('Authenticate');
		$command->setUsername($username)->setPassword($password)->setTenantname(
			$tenantName
		);
		try {
			$authResult = $command->execute()->getResult;
			$this->username = $username;
			$this->password = $password;
			$this->tenantName = $tenantName;

			//Copy Service Catalog
			$this->serviceCatalog = $authResult['access']['serviceCatalog'];

			//Get token
			$this->token = $authResult['access']['token'];

			//Default Region
			$this->region = 'RegionOne';
		} catch (OpenstackException $e) {

		}
	}
1144977
private function _login($username, $password) {
        $data["Envelope"] = array(
            "Body" => array(
                "Login" => array(
                    "USERNAME" => $username,
                    "PASSWORD" => $password,
                ),
            ),
        );
        $response = $this->_request($data);
        $result = $response["Envelope"]["Body"]["RESULT"];
        if ($this->_isSuccess($result)) {
            $this->_jsessionid = $result['SESSIONID'];
            $this->_session_encoding = $result['SESSION_ENCODING'];
            $this->_username = $username;
            $this->_password = $password;
        } else {
            throw new \Exception("Login Error: ".$this->_getErrorFromResponse($response));
        }
    }
973759
public function create( $serviceName ) {

		if ( is_string( $serviceName ) && isset( $this->aliases[$serviceName] ) ) {
			$serviceName = $this->aliases[$serviceName];
		}

		return $this->getReturnValueFromCallbackHandlerFor( $serviceName, func_get_args() );
	}
296459
public function login($identity)
    {
        if ($this->needRegenerate) {
            session_regenerate_id(true);
        }
        foreach ($identity as $name => $val) {
            $this->sessionData[$name] = $val;
        }
        $lifetime = ini_get('session.cookie_lifetime');
        $this->sessionData[self::REGENERATE_AFTER] = time() + $lifetime - min($lifetime*0.2, 300);
        $this->getSession()->set($this->sessionKey, $this->sessionData);
    }
579548
private function instantiateService($serviceName)
    {
        // Make sure service is registered
        if (!$this->registeredServices->keyExists($serviceName)) {
            throw new ServiceManagerException(ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND, [$serviceName]);
        }

        // Get service config from registered services array
        $config = $this->registeredServices->key($serviceName);

        // Check circular referencing
        if ($this->references->keyExists($serviceName)) {
            throw new ServiceManagerException(ServiceManagerException::SERVICE_CIRCULAR_REFERENCE, [$serviceName]);
        }

        // Set service name reference for circular referencing checks
        $this->references->key($serviceName, $serviceName);

        // Compile ConfigObject into ServiceConfig
        $configCompiler = new ConfigCompiler($serviceName, $config, $this->parameters);
        $this->compiledConfig->key($serviceName, $configCompiler->compile());

        /**
         * @var $config ServiceConfig
         */
        $config = $this->compiledConfig->key($serviceName);

        // Construct service container and get service instance
        $serviceCreator = new ServiceCreator($config);
        $service = $serviceCreator->getService();

        // Unset service name reference
        $this->references->removeKey($serviceName);

        // Store instance if this service has a CONTAINER scope
        if ($config->getScope() == ServiceScope::CONTAINER) {
            $this->instantiatedServices->key($serviceName, $service);
        }

        return $service;
    }
1337817
public function authenticate(Zend_Controller_Request_Abstract $request,
        Zend_Controller_Response_Abstract $response) {
        $this->setSreg(new Zend_OpenId_Extension_Sreg(
            array(
                "nickname"  => true,
                "email"     => true,
                "fullname"  => true,
                "dob"       => true,
                "gender"    => true,
                "country"   => true,
                "language"  => true,
            ),
            null,
            1.1
        ));

        return parent::authenticate($request);
    }
363654
public function registerServices(array $serviceClosureArr) : void
    {
        foreach ($serviceClosureArr as $closure) {
            $reflection = new \ReflectionFunction($closure);
            $arguments  = $reflection->getParameters();
            if (!$closure instanceof \Closure || count($arguments) !== 1) {
                throw new \Exception(
                    "Configuration 'services' definition must be a closure"
                    ." which takes the container as its parameter and also"
                    ." returns it after configuring it."
                );
            }
            $this->container = $closure($this->container);
        }
    }
856767
protected function onSuccess(ResponseInterface $response, ?callable $callback = null) : void
    {
        if (!is_null($callback)) {
            $callback($response);
        }
    }
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());
	}
396205
public function connect($serverLogin, $apikey)
    {
        $this->apiKey = $apikey;
        $this->serverLogin = $serverLogin;

        if (empty($this->apiKey)) {
            $this->console->writeln('MxKarma error: You need to define a api key');

            return;
        }

        if (empty($this->serverLogin)) {
            $this->console->writeln('MxKarma error: You need to define server login');

            return;
        }

        $params = [
            "serverLogin" => $serverLogin,
            "applicationIdentifier" => "eXpansion v ".AbstractApplication::EXPANSION_VERSION,
            "testMode" => "false",
        ];

        $this->console->writeln('> MxKarma attempting to connect...');
        $this->http->get(
            $this->buildUrl(
                "startSession", $params),
            [$this, "xConnect"]
        );
    }