Improvement for OAuth2 Server. Implicit, Resource Owner Password and Client Credentials were added, and refactoring of oauth2 endpoints
This commit is contained in:
@@ -96,6 +96,8 @@ class WebApplication
|
||||
*/
|
||||
public function route()
|
||||
{
|
||||
$this->requestUri = strlen($this->requestUri) > 1? rtrim($this->requestUri, '/'): $this->requestUri;
|
||||
|
||||
if ($this->requestUri === "/") {
|
||||
if (file_exists("index.html")) {
|
||||
return self::RUNNING_INDEX;
|
||||
@@ -107,7 +109,47 @@ class WebApplication
|
||||
) {
|
||||
return self::RUNNING_API;
|
||||
} else {
|
||||
return self::RUNNING_WORKFLOW;
|
||||
list($this->requestUri,) = explode('?', $this->requestUri);
|
||||
$uriParts = explode('/', $this->requestUri);
|
||||
|
||||
if ($uriParts[2] == 'oauth2') {
|
||||
|
||||
if (! isset($uriParts[2])) {
|
||||
return self::RUNNING_WORKFLOW;
|
||||
}
|
||||
|
||||
/*$workspace = $uriParts[1];
|
||||
$class = 'oauth2';
|
||||
$action = isset($uriParts[3])? $uriParts[3]: 'index';*/
|
||||
|
||||
$uriTemp = explode('/', $_SERVER['REQUEST_URI']);
|
||||
array_shift($uriTemp);
|
||||
$workspace = array_shift($uriTemp);
|
||||
$_SERVER['REQUEST_URI'] = '/' . implode('/', $uriTemp);
|
||||
|
||||
$this->loadEnvironment($workspace);
|
||||
$this->configureRest($workspace, '1.0');
|
||||
//var_dump(class_exists('ProcessMaker\\Services\\OAuth2\\Server'));
|
||||
$this->rest->addAPIClass('\ProcessMaker\\Services\\OAuth2\\Server', 'oauth2');
|
||||
$this->rest->handle();
|
||||
|
||||
/*
|
||||
|
||||
$this->loadEnvironment($workspace);
|
||||
|
||||
require_once PATH_CONTROLLERS . $class . '.php';
|
||||
|
||||
if (is_callable(array($class, $action))) {
|
||||
$controller = new $class();
|
||||
$controller->setHttpRequestData($_REQUEST);
|
||||
$controller->call($action);
|
||||
} else {
|
||||
header('location: /errors/error404?url=' . urlencode($this->requestUri));
|
||||
}*/
|
||||
|
||||
} else {
|
||||
return self::RUNNING_WORKFLOW;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,8 +269,6 @@ class WebApplication
|
||||
$apiIniFile = $servicesDir . DS . 'api.ini';
|
||||
// $authenticationClass - contains the class name that validate the authentication for Restler
|
||||
$authenticationClass = 'ProcessMaker\\Services\\OAuth2\\Server';
|
||||
// $pmOauthClientId - contains PM Local OAuth Id (Web Designer)
|
||||
$pmOauthClientId = 'x-pm-local-client';
|
||||
|
||||
/*
|
||||
* Load Api ini file for Rest Service
|
||||
@@ -252,37 +292,9 @@ class WebApplication
|
||||
}
|
||||
}
|
||||
|
||||
// Setting current workspace to Api class
|
||||
Services\Api::setWorkspace(SYS_SYS);
|
||||
$cacheDir = defined("PATH_C")? PATH_C: sys_get_temp_dir();
|
||||
|
||||
$sysConfig = \System::getSystemConfiguration();
|
||||
|
||||
\Luracast\Restler\Defaults::$cacheDirectory = $cacheDir;
|
||||
$productionMode = (bool) !(isset($sysConfig["service_api_debug"]) && $sysConfig["service_api_debug"]);
|
||||
|
||||
Util\Logger::log("Serving API mode: " . ($productionMode? "production": "development"));
|
||||
|
||||
// create a new Restler instance
|
||||
//$rest = new \Luracast\Restler\Restler();
|
||||
$this->rest = new \Maveriks\Extension\Restler($productionMode);
|
||||
// setting flag for multipart to Restler
|
||||
$this->rest->setFlagMultipart($multipart);
|
||||
// setting api version to Restler
|
||||
$this->rest->setAPIVersion($version);
|
||||
// adding $authenticationClass to Restler
|
||||
$this->configureRest(SYS_SYS, $version, $multipart);
|
||||
$this->rest->addAuthenticationClass($authenticationClass, '');
|
||||
|
||||
// Setting database connection source
|
||||
list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, '');
|
||||
$port = empty($port) ? '' : ";port=$port";
|
||||
Services\OAuth2\Server::setDatabaseSource(DB_USER, DB_PASS, DB_ADAPTER.":host=$host;dbname=".DB_NAME.$port);
|
||||
|
||||
// Setting default OAuth Client id, for local PM Web Designer
|
||||
Services\OAuth2\Server::setPmClientId($pmOauthClientId);
|
||||
|
||||
$this->rest->setOverridingFormats('JsonFormat', 'UploadFormat');
|
||||
|
||||
$isPluginRequest = strpos($uri, '/plugin-') !== false ? true : false;
|
||||
|
||||
if ($isPluginRequest) {
|
||||
@@ -340,6 +352,44 @@ class WebApplication
|
||||
}
|
||||
}
|
||||
|
||||
public function configureRest($workspace, $version, $multipart = false)
|
||||
{
|
||||
// $pmOauthClientId - contains PM Local OAuth Id (Web Designer)
|
||||
$pmOauthClientId = 'x-pm-local-client';
|
||||
|
||||
// Setting current workspace to Api class
|
||||
Services\Api::setWorkspace($workspace);
|
||||
$cacheDir = defined("PATH_C")? PATH_C: sys_get_temp_dir();
|
||||
|
||||
$sysConfig = \System::getSystemConfiguration();
|
||||
|
||||
\Luracast\Restler\Defaults::$cacheDirectory = $cacheDir;
|
||||
$productionMode = false; //(bool) !(isset($sysConfig["service_api_debug"]) && $sysConfig["service_api_debug"]);
|
||||
|
||||
Util\Logger::log("Serving API mode: " . ($productionMode? "production": "development"));
|
||||
|
||||
// create a new Restler instance
|
||||
//$rest = new \Luracast\Restler\Restler();
|
||||
$this->rest = new \Maveriks\Extension\Restler($productionMode);
|
||||
$this->rest->setworkspace($workspace);
|
||||
// setting flag for multipart to Restler
|
||||
$this->rest->setFlagMultipart($multipart);
|
||||
// setting api version to Restler
|
||||
$this->rest->setAPIVersion($version);
|
||||
// adding $authenticationClass to Restler
|
||||
|
||||
// Setting database connection source
|
||||
list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, '');
|
||||
$port = empty($port) ? '' : ";port=$port";
|
||||
Services\OAuth2\Server::setDatabaseSource(DB_USER, DB_PASS, DB_ADAPTER.":host=$host;dbname=".DB_NAME.$port);
|
||||
|
||||
// Setting default OAuth Client id, for local PM Web Designer
|
||||
Services\OAuth2\Server::setPmClientId($pmOauthClientId);
|
||||
Services\OAuth2\Server::setWorkspace($workspace);
|
||||
|
||||
$this->rest->setOverridingFormats('JsonFormat', 'UploadFormat');
|
||||
}
|
||||
|
||||
public function parseApiRequestUri()
|
||||
{
|
||||
$url = explode("/", $this->requestUri);
|
||||
|
||||
Reference in New Issue
Block a user