Gets basic user session data and performs OAuth login redirect.

@return array
@throws \DreamFactory\Core\Exceptions\BadRequestException
@throws \DreamFactory\Core\Exceptions\UnauthorizedException
480554
protected function handleGET()
    {
        $serviceName = $this->getOAuthServiceName();
        if (!empty($serviceName)) {
            /** @type BaseOAuthService $service */
            $service = ServiceManager::getService($serviceName);
            $serviceGroup = $service->getServiceTypeInfo()->getGroup();

            if ($serviceGroup !== ServiceTypeGroups::OAUTH) {
                throw new BadRequestException('Invalid login service provided. Please use an OAuth service.');
            }

            return $service->handleLogin($this->request->getDriver());
        }

        return Session::getPublicInfo();
    }
1036268
public function loginAction()
    {
        $request = $this->get('request_stack')->getCurrentRequest();
        /*
        if($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
            $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
        } else {
            $error = $request->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
        }
        */

        $session = $request->getSession();

        // get the login error if there is one
        if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) {
            $error = $request->attributes->get(
                Security::AUTHENTICATION_ERROR
            );
        } elseif (null !== $session && $session->has(Security::AUTHENTICATION_ERROR)) {
            $error = $session->get(Security::AUTHENTICATION_ERROR);
            $session->remove(Security::AUTHENTICATION_ERROR);
        } else {
            $error = '';
        }

        // last username entered by the user
        $lastUsername = (null === $session) ? '' : $session->get(Security::LAST_USERNAME);

        return array(
            'last_username' => $lastUsername,
            'error' => $error,
            'selfregister' => $this->container->getParameter("fom_user.selfregister"),
            'reset_password' => $this->container->getParameter("fom_user.reset_password")
        );
    }
1084805
public function checkLogin()
    {
        $this->defaultData();
        $userService = $this->getServiceLocator()->get(tao_models_classes_UserService::class);
        if (!$this->isXmlHttpRequest()) {
            throw new common_exception_BadRequest('wrong request mode');
        }

        $data = array('available' => false);
        if ($this->hasRequestParameter('login')) {
            $data['available'] = $userService->loginAvailable($this->getRequestParameter('login'));
        }

        $this->returnJson($data);
    }
157685
public function getRequestCredentials()
    {
        if ($this->requestCredentials === null) {
            $this->requestCredentials = function () {
                $credentials = [];

                if (isset($_SERVER['PHP_AUTH_USER'])) {
                    $credentials['login'] = $_SERVER['PHP_AUTH_USER'];
                }

                if (isset($_SERVER['PHP_AUTH_PW'])) {
                    $credentials['password'] = $_SERVER['PHP_AUTH_PW'];
                }

                if (count($credentials) > 0) {
                    return $credentials;
                }
            };
        }

        $credentials = $this->requestCredentials;

        return $credentials();
    }
838484
public function login(){
        if ($this->getGet('code')) {
            $this->client->authenticate($this->getGet('code'));
            $this->setSession('token', $this->client->getAccessToken());

            $redirect = $this->config->redirect_uris[0];
            header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
            return;
        }


        $token = $this->getSession('token');
        if ($token) {
            $this->client->setAccessToken($token);
        }

        if ($this->client->getAccessToken()) {
            $user = $this->oauth2_service->userinfo->get();
            $this->setSession('token', $this->client->getAccessToken());
            return $user;
        }
    }
1071735
public function getCurrentSessionUserInfo()
    {
        $ts = $this->config->table_sessions;
        $tu = $this->config->table_users;

        $query = "
		SELECT {$ts}.uid, {$ts}.expiredate, {$ts}.ip, {$tu}.email, {$tu}.username
		FROM {$ts}, {$tu}
		WHERE hash = :hash AND {$ts}.uid = {$tu}.id";

        $query = $this->dbh->prepare($query);
        $query->execute([
            'hash'	=>	$this->getCurrentSessionHash()
        ]);

        if ($query->rowCount() == 0) {
            return false;
        }

        return $query->fetch(\PDO::FETCH_ASSOC);
    }
943478
public function getData()
    {
        $this->validate('merId', 'password', 'merUrlIdx');
        $data = array(
            'mer_id'            => $this->getMerId(),
            'password'          => $this->getPassword(),
            'mer_url_idx'       => $this->getMerUrlIdx(),
            'client_ip'         => $this->getClientIp(),
        );
        return $data;
    }
1361239
public function getSessionFromRedirect()
        {
            $session = $this->getFacebookHelper()->getSessionFromRedirect();

            $this->session->put('session', $session);

            return $session;
        }
1038900
public function login()
    {
        $_SESSION['auth'] = 'login';

        if ($this->userStore->find()->count() === 0) {
            return $this->redirect('/setup');
        }

        Event::trigger('beforeLogin', $this);

        if ($this->request->getMethod() == 'POST') {
            $user = Store::get('User')->getByEmail($this->getParam('email'));

            if ($user && password_verify($this->getParam('password', ''), $user->getHash())) {
                $_SESSION['user_id'] = $user->getId();

                $url = $this->config->get('site.full_admin_url');

                if (isset($_SESSION['previous_url'])) {
                    $url = $_SESSION['previous_url'];
                }

                return $this->redirect($url);
            } else {
                Event::trigger('loginFailed', $this->view);
                $this->template->errorMessage = 'Your email address or password were incorrect.';
            }
        }
    }
794694
public function adm_get_safe_user_data() {
		if (!$this->store_is_logged_in())
			return [AdminStoreError::USER_NOT_LOGGED_IN];
		$data = $this->user_data;
		foreach (['upass', 'usalt', 'sid', 'token', 'expire'] as $key)
			unset($data[$key]);
		return [0, $data];
	}
794902
public function getCredentials()
    {
        $auth = $this->request->getHeader('Authorization');

        if (!$auth) {
            return null;
        }

        if ('basic ' !== strtolower(substr($auth, 0, 6))) {
            return null;
        }

        $credentials = explode(':', base64_decode(substr($auth, 6)), 2);

        if (2 !== count($credentials)) {
            return null;
        }

        return $credentials;
    }
48033
public function getSession() {
    if (!$this->sessionLoaded) {
      $session = null;
      $write_cookie = true;

      // try loading session from signed_request in $_REQUEST
      $signedRequest = $this->getSignedRequest();
      if ($signedRequest) {
        // sig is good, use the signedRequest
        $session = $this->createSessionFromSignedRequest($signedRequest);
      }

      // try loading session from $_REQUEST
      if (!$session && isset($_REQUEST['session'])) {
        $session = json_decode(
          get_magic_quotes_gpc()
            ? stripslashes($_REQUEST['session'])
            : $_REQUEST['session'],
          true
        );
        $session = $this->validateSessionObject($session);
      }

      // try loading session from cookie if necessary
      if (!$session && $this->useCookieSupport()) {
        $cookieName = $this->getSessionCookieName();
        if (isset($_COOKIE[$cookieName])) {
          $session = array();
          parse_str(trim(
            get_magic_quotes_gpc()
              ? stripslashes($_COOKIE[$cookieName])
              : $_COOKIE[$cookieName],
            '"'
          ), $session);
          $session = $this->validateSessionObject($session);
          // write only if we need to delete a invalid session cookie
          $write_cookie = empty($session);
        }
      }

      $this->setSession($session, $write_cookie);
    }

    return $this->session;
  }
1112554
public function getAllSession()
    {
        if (isset($this->objectSession) && $this->objectSession != NULL && is_object($this->objectSession)) {
            $this->logger->info(__FUNCTION__, 'Session with CI Session Class');
            $data = $this->objectSession->get_userdata();
        } else {
            $this->logger->info(__FUNCTION__, 'Session with The Http Foundation Component');
            $data = $this->session->all();
        }
        $this->logger->info(__FUNCTION__, 'ALL Session Data: ' . json_encode($data));

        return $data;
    }
1244343
public function login()
    {
        $this->loadModel('CakeManager.Roles');

        // Redirect if user is already logged in
        if ($this->authUser) {
            $redirect = $this->Roles->redirectFrom($this->authUser['role_id']);
            return $this->redirect($redirect);
        }

        if ($this->request->is('post')) {
            $user = $this->Auth->identify();
            if ($user) {
                $this->Auth->setUser($user);

                $redirect = $this->Roles->redirectFrom($user['role_id']);

                // firing an event: afterLogin
                $_event = new Event('Controller.Users.afterLogin', $this, [
                    'user' => $user
                ]);
                $this->eventManager()->dispatch($_event);

                return $this->redirect($redirect);
            }

            // firing an event: afterInvalidLogin
            $_event = new Event('Controller.Users.afterInvalidLogin', $this, [
                'user' => $user
            ]);
            $this->eventManager()->dispatch($_event);

            $this->Flash->error(__('Your username or password is incorrect.'));
        }

        $this->set('registerEnabled', Configure::read('CM.Register'));

        $this->render(Configure::read('CM.UserViews.login'));
    }
1335726
protected function handlePOST()
    {
        if (empty($payload = $this->getPayloadData())) {
            throw new BadRequestException('No data supplied for operation.');
        }

        $data = [
            'username'          => array_get($payload, 'username'),
            'first_name'        => array_get($payload, 'first_name'),
            'last_name'         => array_get($payload, 'last_name'),
            'name'              => array_get($payload, 'name'),
            'email'             => array_get($payload, 'email'),
            'phone'             => array_get($payload, 'phone'),
            'security_question' => array_get($payload, 'security_question'),
            'security_answer'   => array_get($payload, 'security_answer'),
            'default_app_id'    => array_get($payload, 'default_app_id')
        ];

        $data = array_filter($data, function ($value) {
            return !is_null($value);
        });

        $user = Session::user();

        if (empty($user)) {
            throw new NotFoundException('No user session found.');
        }

        $oldToken = Session::getSessionToken();
        $email = $user->email;
        $user->update($data);

        if (!empty($oldToken) && $email !== array_get($data, 'email', $email)) {
            // Email change invalidates token. Need to create a new token.
            $forever = JWTUtilities::isForever($oldToken);
            Session::setUserInfoWithJWT($user, $forever);
            $newToken = Session::getSessionToken();

            return ['success' => true, 'session_token' => $newToken];
        }

        return ['success' => true];
    }
97819
protected function getCredentials()
    {
        if (empty($this->username) || empty($this->password)) {
            throw new \Exception('Basic authentication requires a $username & $password property.');
        }

        return [$this->username, $this->password];
    }
1355704
private function getSession()
    {
        $vars = array(
            'method' => 'auth.getSession',
            'api_key' => $this->apiKey,
            'token' => $this->token
        );
        $sig = $this->apiSig($this->apiSecret, $vars);
        $vars['api_sig'] = $sig;

        if ($call = $this->apiGetCall($vars)) {
            $this->username = (string) $call->session->name;
            $this->sessionKey = (string) $call->session->key;
            $this->subscriber = (string) $call->session->subscriber;
        } else {
            return false;
        }
    }