From 9218b7657b24e579fb85177e95971828e9dc6b6e Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Tue, 15 May 2018 09:46:58 -0400 Subject: [PATCH] HOR-4485 --- config/oauthClients.php | 18 +++++++++++ workflow/engine/classes/WorkspaceTools.php | 32 +++++++++++++------ .../engine/controllers/InstallerModule.php | 14 ++++++++ workflow/engine/controllers/adminProxy.php | 11 +++++++ .../src/ProcessMaker/Core/Installer.php | 14 ++++++++ 5 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 config/oauthClients.php diff --git a/config/oauthClients.php b/config/oauthClients.php new file mode 100644 index 000000000..e4f9d666d --- /dev/null +++ b/config/oauthClients.php @@ -0,0 +1,18 @@ + [ + 'clientId' => 'x-pm-local-client', + 'clientSecret' => '179ad45c6ce2cb97cf1029e212046e81', + 'clientName' => 'PM Web Designer', + 'clientDescription' => 'ProcessMaker Web Designer App', + 'clientWebsite' => 'www.processmaker.com', + ], + 'mobile' => [ + 'clientId' => 'x-pm-mobile-client', + 'clientSecret' => '4426746995afa07e7485df1055471800', + 'clientName' => 'PM Mobile App', + 'clientDescription' => 'PM Mobile App for Android and iOS', + 'clientWebsite' => 'www.processmaker.com', + ], +]; diff --git a/workflow/engine/classes/WorkspaceTools.php b/workflow/engine/classes/WorkspaceTools.php index 6af1ad085..baf8ae6ec 100644 --- a/workflow/engine/classes/WorkspaceTools.php +++ b/workflow/engine/classes/WorkspaceTools.php @@ -2131,7 +2131,8 @@ class WorkspaceTools { $this->initPropel(true); $pmRestClient = OauthClientsPeer::retrieveByPK('x-pm-local-client'); - if (empty($pmRestClient)) { + $pmMobileRestClient = OauthClientsPeer::retrieveByPK(config('oauthClients.mobile.clientId')); + if (empty($pmRestClient) || empty($pmMobileRestClient)) { if (!is_file(PATH_DATA . 'sites/' . $workspace . '/' . '.server_info')) { $_CSERVER = $_SERVER; unset($_CSERVER['REQUEST_TIME']); @@ -2159,14 +2160,27 @@ class WorkspaceTools $skin ); - $oauthClients = new OauthClients(); - $oauthClients->setClientId('x-pm-local-client'); - $oauthClients->setClientSecret('179ad45c6ce2cb97cf1029e212046e81'); - $oauthClients->setClientName('PM Web Designer'); - $oauthClients->setClientDescription('ProcessMaker Web Designer App'); - $oauthClients->setClientWebsite('www.processmaker.com'); - $oauthClients->setRedirectUri($endpoint); - $oauthClients->save(); + if (empty($pmRestClient)) { + $oauthClients = new OauthClients(); + $oauthClients->setClientId('x-pm-local-client'); + $oauthClients->setClientSecret('179ad45c6ce2cb97cf1029e212046e81'); + $oauthClients->setClientName('PM Web Designer'); + $oauthClients->setClientDescription('ProcessMaker Web Designer App'); + $oauthClients->setClientWebsite('www.processmaker.com'); + $oauthClients->setRedirectUri($endpoint); + $oauthClients->save(); + } + + if (empty($pmMobileRestClient) && !empty(config('oauthClients.mobile.clientId'))) { + $oauthClients = new OauthClients(); + $oauthClients->setClientId(config('oauthClients.mobile.clientId')); + $oauthClients->setClientSecret(config('oauthClients.mobile.clientSecret')); + $oauthClients->setClientName(config('oauthClients.mobile.clientName')); + $oauthClients->setClientDescription(config('oauthClients.mobile.clientDescription')); + $oauthClients->setClientWebsite(config('oauthClients.mobile.clientWebsite')); + $oauthClients->setRedirectUri($endpoint); + $oauthClients->save(); + } } else { eprintln("WARNING! No server info found!", 'red'); } diff --git a/workflow/engine/controllers/InstallerModule.php b/workflow/engine/controllers/InstallerModule.php index f50aace55..509e9382a 100644 --- a/workflow/engine/controllers/InstallerModule.php +++ b/workflow/engine/controllers/InstallerModule.php @@ -1059,6 +1059,20 @@ class InstallerModule extends Controller 'REDIRECT_URI' => $endpoint, 'USR_UID' => '00000000000000000000000000000001' ]); + + if (!empty(config('oauthClients.mobile.clientId'))) { + DB::connection(self::CONNECTION_INSTALL) + ->table('OAUTH_CLIENTS') + ->insert([ + 'CLIENT_ID' => config('oauthClients.mobile.clientId'), + 'CLIENT_SECRET' => config('oauthClients.mobile.clientSecret'), + 'CLIENT_NAME' => config('oauthClients.mobile.clientName'), + 'CLIENT_DESCRIPTION' => config('oauthClients.mobile.clientDescription'), + 'CLIENT_WEBSITE' => config('oauthClients.mobile.clientWebsite'), + 'REDIRECT_URI' => $endpoint, + 'USR_UID' => '00000000000000000000000000000001' + ]); + } $indexFileUpdated = true; if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) { diff --git a/workflow/engine/controllers/adminProxy.php b/workflow/engine/controllers/adminProxy.php index 7c16fc4f9..b8363992f 100644 --- a/workflow/engine/controllers/adminProxy.php +++ b/workflow/engine/controllers/adminProxy.php @@ -1396,6 +1396,17 @@ class adminProxy extends HttpProxyController $oauthClients->setClientWebsite('www.processmaker.com'); $oauthClients->setRedirectUri($endpoint); $oauthClients->save(); + + if (!empty(config('oauthClients.mobile.clientId'))) { + $oauthClients = new OauthClients(); + $oauthClients->setClientId(config('oauthClients.mobile.clientId')); + $oauthClients->setClientSecret(config('oauthClients.mobile.clientSecret')); + $oauthClients->setClientName(config('oauthClients.mobile.clientName')); + $oauthClients->setClientDescription(config('oauthClients.mobile.clientDescription')); + $oauthClients->setClientWebsite(config('oauthClients.mobile.clientWebsite')); + $oauthClients->setRedirectUri($endpoint); + $oauthClients->save(); + } $result['success'] = true; $result['message'] = ''; diff --git a/workflow/engine/src/ProcessMaker/Core/Installer.php b/workflow/engine/src/ProcessMaker/Core/Installer.php index cd7ef9806..89560a0f2 100644 --- a/workflow/engine/src/ProcessMaker/Core/Installer.php +++ b/workflow/engine/src/ProcessMaker/Core/Installer.php @@ -220,6 +220,20 @@ class Installer 'USR_UID' => '00000000000000000000000000000001' ]); + if (!empty(config('oauthClients.mobile.clientId'))) { + DB::connection(self::CONNECTION_INSTALL) + ->table('OAUTH_CLIENTS') + ->insert([ + 'CLIENT_ID' => config('oauthClients.mobile.clientId'), + 'CLIENT_SECRET' => config('oauthClients.mobile.clientSecret'), + 'CLIENT_NAME' => config('oauthClients.mobile.clientName'), + 'CLIENT_DESCRIPTION' => config('oauthClients.mobile.clientDescription'), + 'CLIENT_WEBSITE' => config('oauthClients.mobile.clientWebsite'), + 'REDIRECT_URI' => $endpoint, + 'USR_UID' => '00000000000000000000000000000001' + ]); + } + /* Dump schema rbac && data */ $pws = PATH_RBAC_MYSQL_DATA . $schema; $qrs = $this->query_sql_file(PATH_RBAC_MYSQL_DATA . $schema);