/** * Grant access tokens for basic user credentials. * Check the supplied username and password for validity. * * You can also use the $client_id param to do any checks required based * on a client, if you need that. * * Required for OAuth2::GRANT_TYPE_USER_CREDENTIALS. * * @param string $username Username to be check with. * @param string $password Password to be check with. * * @return boolean TRUE if the username and password are valid, and FALSE if it isn't. * Moreover, if the username and password are valid, and you want to * * @see http://tools.ietf.org/html/rfc6749#section-4.3 * * @ingroup oauth2_section_4 */ public function checkUserCredentials($username, $password) { $credentials = array('username' => $username, 'password' => $password); $response = \RUser::userLogin($credentials); return $response; }
/** * Log-in client if successful or terminate api if not authorized * * @param string $scope Name of the scope to test against * @param bool $terminateIfNotAuthorized Terminate api if client is not authorized * * @throws Exception * @return bool * * @since 1.2 */ public function isAuthorized($scope, $terminateIfNotAuthorized) { $authorized = false; JFactory::getApplication()->triggerEvent('RApiHalBeforeIsAuthorizedCheck', array($scope, $terminateIfNotAuthorized, $this->options, $this->authorizationCheck, &$authorized)); if ($authorized) { return $authorized; } // OAuth2 check if ($this->authorizationCheck == 'oauth2') { /** @var $response OAuth2\Response */ $response = RApiOauth2Helper::verifyResourceRequest($scope); if ($response instanceof OAuth2\Response) { if (!$response->isSuccessful() && $terminateIfNotAuthorized) { // OAuth2 Server response is in fact correct output for errors $response->send($this->options->get('format', 'json')); JFactory::getApplication()->close(); } } elseif ($response === false && $terminateIfNotAuthorized) { throw new Exception(JText::_('LIB_REDCORE_API_OAUTH2_SERVER_IS_NOT_ACTIVE')); } else { $response = json_decode($response); if (!empty($response->user_id)) { $user = JFactory::getUser($response->user_id); // Load the JUser class on application for this client JFactory::getApplication()->loadIdentity($user); JFactory::getSession()->set('user', $user); return true; } $authorized = false || !$terminateIfNotAuthorized; } } elseif ($this->authorizationCheck == 'joomla') { // Get username and password from globals $credentials = RApiHalHelper::getCredentialsFromGlobals(); $authorized = RUser::userLogin($credentials) || !$terminateIfNotAuthorized; } if (!$authorized && $terminateIfNotAuthorized) { $customError = $this->triggerFunction('createCustomHttpError', 401, $this->apiErrors); $this->setStatusCode(401, $customError); } return $authorized || !$terminateIfNotAuthorized; }