Exemplo n.º 1
0
 /**
  * Method to register custom library.
  *
  * @return  void
  */
 public function onAfterInitialise()
 {
     if (defined('REDCORE_LIBRARY_LOADED')) {
         $apiName = JFactory::getApplication()->input->getString('api');
         if ($this->isApiEnabled($apiName)) {
             $input = JFactory::getApplication()->input;
             if (!empty($apiName)) {
                 try {
                     // We will disable all error messaging from PHP from the output
                     error_reporting(0);
                     ini_set('display_errors', 0);
                     JError::setErrorHandling(E_ERROR, 'message');
                     JFactory::getApplication()->clearHeaders();
                     $webserviceClient = $input->get->getString('webserviceClient', '');
                     $optionName = $input->get->getString('option', '');
                     $optionName = strpos($optionName, 'com_') === 0 ? substr($optionName, 4) : $optionName;
                     $viewName = $input->getString('view', '');
                     $version = $input->getString('webserviceVersion', '');
                     $token = $input->getString(RBootstrap::getConfig('oauth2_token_param_name', 'access_token'), '');
                     $apiName = ucfirst($apiName);
                     $method = strtoupper($input->getMethod());
                     $task = RApiHalHelper::getTask();
                     $data = RApi::getPostedData();
                     $dataGet = $input->get->getArray();
                     if (empty($webserviceClient)) {
                         $webserviceClient = JFactory::getApplication()->isAdmin() ? 'administrator' : 'site';
                     }
                     $options = array('api' => $apiName, 'optionName' => $optionName, 'viewName' => $viewName, 'webserviceVersion' => $version, 'webserviceClient' => $webserviceClient, 'method' => $method, 'task' => $task, 'data' => $data, 'dataGet' => $dataGet, 'accessToken' => $token, 'format' => $input->getString('format', $this->params->get('webservices_default_format', 'json')), 'id' => $input->getString('id', ''), 'absoluteHrefs' => $input->get->getBool('absoluteHrefs', true));
                     // Create instance of Api and fill all required options
                     $api = RApi::getInstance($options);
                     // Run the api task
                     $api->execute();
                     // Display output
                     $api->render();
                 } catch (Exception $e) {
                     $code = $e->getCode() > 0 ? $e->getCode() : 500;
                     if (strtolower($apiName) == 'soap') {
                         // We must have status of 200 for SOAP communication even if it is fault
                         $message = RApiSoapHelper::createSoapFaultResponse($e->getMessage());
                         header("Content-Type: soap+xml");
                         header("Content-length: " . strlen($message));
                         header("Status: 200");
                         echo $message;
                     } else {
                         // Set the server response code.
                         header('Status: ' . $code, true, $code);
                         // Check for defined constants
                         if (!defined('JSON_UNESCAPED_SLASHES')) {
                             define('JSON_UNESCAPED_SLASHES', 64);
                         }
                         // An exception has been caught, echo the message and exit.
                         echo json_encode(array('message' => $e->getMessage(), 'code' => $e->getCode(), 'type' => get_class($e)), JSON_UNESCAPED_SLASHES);
                     }
                 }
                 JFactory::getApplication()->close();
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Method to instantiate the file-based api call.
  *
  * @param   mixed  $options  Optional custom options to load. JRegistry or array format
  *
  * @throws Exception
  * @since   1.4
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     JPluginHelper::importPlugin('redcore');
     $this->webservice = new RApiHalHal($options);
     $this->webservice->authorizationCheck = 'joomla';
     // Init Environment
     $this->triggerFunction('setApiOperation');
     // Set initial status code
     $this->setStatusCode($this->statusCode);
 }
Exemplo n.º 3
0
 /**
  * Method to instantiate the file-based api call.
  *
  * @param   mixed  $options  Optional custom options to load. JRegistry or array format
  *
  * @throws Exception
  * @since   1.5
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     JPluginHelper::importPlugin('redcore');
     JPluginHelper::importPlugin('redpayment');
     // Init Environment
     $this->triggerFunction('setApiOperation');
     $dataGet = $this->options->get('dataGet', array());
     $this->paymentName = isset($dataGet->payment_name) ? $dataGet->payment_name : null;
     $this->extensionName = isset($dataGet->extension_name) ? $dataGet->extension_name : null;
     $this->ownerName = isset($dataGet->owner_name) ? $dataGet->owner_name : null;
     $this->orderId = isset($dataGet->order_id) ? $dataGet->order_id : null;
     $this->paymentId = isset($dataGet->payment_id) ? (int) $dataGet->payment_id : 0;
     // Set initial status code
     $this->setStatusCode($this->statusCode);
     $this->requestData = $this->options->get('data', array());
     if (is_object($this->requestData)) {
         $this->requestData = JArrayHelper::fromObject($this->requestData);
     }
 }
Exemplo n.º 4
0
 /**
  * Method to instantiate the file-based api call.
  *
  * @param   mixed  $options  Optional custom options to load. JRegistry or array format
  *
  * @since   1.2
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     // Get the global JAuthentication object.
     jimport('joomla.user.authentication');
     // Register OAuth2 classes
     require_once dirname(__FILE__) . '/Autoloader.php';
     OAuth2\Autoloader::register();
     // OAuth2 Server config from plugin
     $this->serverConfig = array('use_jwt_access_tokens' => (bool) RBootstrap::getConfig('oauth2_use_jwt_access_tokens', false), 'store_encrypted_token_string' => (bool) RBootstrap::getConfig('oauth2_store_encrypted_token_string', true), 'use_openid_connect' => (bool) RBootstrap::getConfig('oauth2_use_openid_connect', false), 'id_lifetime' => RBootstrap::getConfig('oauth2_id_lifetime', 3600), 'access_lifetime' => RBootstrap::getConfig('oauth2_access_lifetime', 3600), 'www_realm' => 'Service', 'token_param_name' => RBootstrap::getConfig('oauth2_token_param_name', 'access_token'), 'token_bearer_header_name' => RBootstrap::getConfig('oauth2_token_bearer_header_name', 'Bearer'), 'enforce_state' => (bool) RBootstrap::getConfig('oauth2_enforce_state', true), 'require_exact_redirect_uri' => (bool) RBootstrap::getConfig('oauth2_require_exact_redirect_uri', true), 'allow_implicit' => (bool) RBootstrap::getConfig('oauth2_allow_implicit', false), 'allow_credentials_in_request_body' => (bool) RBootstrap::getConfig('oauth2_allow_credentials_in_request_body', true), 'allow_public_clients' => (bool) RBootstrap::getConfig('oauth2_allow_public_clients', true), 'always_issue_new_refresh_token' => (bool) RBootstrap::getConfig('oauth2_always_issue_new_refresh_token', false));
     // Set database names to Redcore DB tables
     $prefix = JFactory::getDbo()->getPrefix();
     $databaseConfig = array('client_table' => $prefix . 'redcore_oauth_clients', 'access_token_table' => $prefix . 'redcore_oauth_access_tokens', 'refresh_token_table' => $prefix . 'redcore_oauth_refresh_tokens', 'code_table' => $prefix . 'redcore_oauth_authorization_codes', 'user_table' => $prefix . 'redcore_oauth_users', 'jwt_table' => $prefix . 'redcore_oauth_jwt', 'jti_table' => $prefix . 'redcore_oauth_jti', 'scope_table' => $prefix . 'redcore_oauth_scopes', 'public_key_table' => $prefix . 'redcore_oauth_public_keys');
     $conf = JFactory::getConfig();
     $dsn = 'mysql:dbname=' . $conf->get('db') . ';host=' . $conf->get('host');
     $username = $conf->get('user');
     $password = $conf->get('password');
     $storage = new OAuth2\Storage\Pdoredcore(array('dsn' => $dsn, 'username' => $username, 'password' => $password), $databaseConfig);
     $this->server = new OAuth2\Server($storage, $this->serverConfig);
     // Add the "Authorization Code" grant type (this is where the oauth magic happens)
     $this->server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage, $this->serverConfig));
     // Add the "Client Credentials" grant type (it is the simplest of the grant types)
     $this->server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage, $this->serverConfig));
     // Add the "User Credentials" grant type (this is modified to suit Joomla authorization)
     $this->server->addGrantType(new OAuth2\GrantType\UserCredentials($storage, $this->serverConfig));
     // Add the "Refresh Token" grant type (this is great for extending expiration time on tokens)
     $this->server->addGrantType(new OAuth2\GrantType\RefreshToken($storage, $this->serverConfig));
     /*
      * @todo Implement JwtBearer Grant type with public_key
     // Typically, the URI of the oauth server
     $audience = rtrim(JUri::base(), '/');
     
     // Add the "Refresh Token" grant type (this is great for extending expiration time on tokens)
     $this->server->addGrantType(new OAuth2\GrantType\JwtBearer($storage, $audience));
     */
     // Init Environment
     $this->setApiOperation();
 }
Exemplo n.º 5
0
 /**
  * Method to instantiate the file-based api call.
  *
  * @param   mixed  $options  Optional custom options to load. JRegistry or array format
  *
  * @throws Exception
  * @since   1.2
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     JPluginHelper::importPlugin('redcore');
     $this->setWebserviceName();
     $this->client = $this->options->get('webserviceClient', 'site');
     $this->webserviceVersion = $this->options->get('webserviceVersion', '');
     $this->hal = new RApiHalDocumentResource('');
     if (!empty($this->webserviceName)) {
         if (empty($this->webserviceVersion)) {
             $this->webserviceVersion = RApiHalHelper::getNewestWebserviceVersion($this->client, $this->webserviceName);
         }
         $this->webservice = RApiHalHelper::getInstalledWebservice($this->client, $this->webserviceName, $this->webserviceVersion);
         if (empty($this->webservice)) {
             throw new Exception(JText::sprintf('LIB_REDCORE_API_HAL_WEBSERVICE_NOT_INSTALLED', $this->webserviceName, $this->webserviceVersion));
         }
         if (empty($this->webservice['state'])) {
             throw new Exception(JText::sprintf('LIB_REDCORE_API_HAL_WEBSERVICE_UNPUBLISHED', $this->webserviceName, $this->webserviceVersion));
         }
         $this->webservicePath = $this->webservice['path'];
         $this->configuration = RApiHalHelper::loadWebserviceConfiguration($this->webserviceName, $this->webserviceVersion, 'xml', $this->webservicePath, $this->client);
         // Set option and view name
         $this->setOptionViewName($this->webserviceName, $this->configuration);
         // Set base data
         $this->setBaseDataValues();
     }
     // Init Environment
     $this->triggerFunction('setApiOperation');
     // Set initial status code
     $this->setStatusCode($this->statusCode);
     // Check for defined constants
     if (!defined('JSON_UNESCAPED_SLASHES')) {
         define('JSON_UNESCAPED_SLASHES', 64);
     }
     // OAuth2 check
     if (RBootstrap::getConfig('webservices_authorization_check', 0) == 0) {
         $this->authorizationCheck = 'oauth2';
     } elseif (RBootstrap::getConfig('webservices_authorization_check', 0) == 1) {
         $this->authorizationCheck = 'joomla';
     }
 }
Exemplo n.º 6
0
 /**
  * Creates instance of OAuth2 server object
  *
  * @return  RApiOauth2Oauth2
  */
 public static function getOAuth2Server()
 {
     if (RBootstrap::getConfig('enable_oauth2_server', 0) == 0) {
         return null;
     }
     if (!isset(self::$serverApi)) {
         $options = array('api' => 'oauth2');
         self::$serverApi = RApi::getInstance($options);
     }
     return self::$serverApi;
 }