From a5f08972ee41eac3b9d7ffd42a9dc054015f9542 Mon Sep 17 00:00:00 2001 From: Matt Moellering <85897501+matt-moellering@users.noreply.github.com> Date: Tue, 12 Mar 2024 12:47:54 -0700 Subject: [PATCH 1/5] add support for Laravel 11 (#339) --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 386556a..02b66bb 100644 --- a/composer.json +++ b/composer.json @@ -20,11 +20,11 @@ "require": { "php": "~7.2 || ~8.0", "firebase/php-jwt": "^5.2|~6.0", - "illuminate/cache": "~6.0|~7.0|~8.0|~9.0|~10.0", - "illuminate/contracts": "~6.0|~7.0|~8.0|~9.0|~10.0", - "illuminate/config": "~6.0|~7.0|~8.0|~9.0|~10.0", - "illuminate/http": "~6.0|~7.0|~8.0|~9.0|~10.0", - "illuminate/routing": "~6.0|~7.0|~8.0|~9.0|~10.0", + "illuminate/cache": "~6.0|~7.0|~8.0|~9.0|~10.0|~11.0", + "illuminate/contracts": "~6.0|~7.0|~8.0|~9.0|~10.0|~11.0", + "illuminate/config": "~6.0|~7.0|~8.0|~9.0|~10.0|~11.0", + "illuminate/http": "~6.0|~7.0|~8.0|~9.0|~10.0|~11.0", + "illuminate/routing": "~6.0|~7.0|~8.0|~9.0|~10.0|~11.0", "nesbot/carbon": "^2.0", "guzzlehttp/guzzle": "~6.0|~7.0" }, From b21046c568b67322539efa02429afa04cad90c0a Mon Sep 17 00:00:00 2001 From: Kristher Vidal <57001550+kristher1619@users.noreply.github.com> Date: Thu, 14 Mar 2024 05:48:03 +0800 Subject: [PATCH 2/5] Add missing callback function in Forrest Facade (#340) Thanks @kristher1619 ! --- src/Omniphx/Forrest/Client.php | 10 +++++----- .../Forrest/Providers/Laravel/Facades/Forrest.php | 6 ++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Omniphx/Forrest/Client.php b/src/Omniphx/Forrest/Client.php index 263d260..754859e 100644 --- a/src/Omniphx/Forrest/Client.php +++ b/src/Omniphx/Forrest/Client.php @@ -46,7 +46,7 @@ * @method string|array compactLayouts(string $resource, array $options = []) * @method string|array flexiPage(string $resource, array $options = []) * @method string|array knowledgeManagement(string $resource, array $options = []) - * @method string|array sobjects(string $resource, array $options = []) + * @method string|array sobjects(string $resource = "", array $options = []) * @method string|array actions(string $resource, array $options = []) * @method string|array support(string $resource, array $options = []) * @@ -212,13 +212,13 @@ private function handleRequest() } else { $this->setFormatter($this->settings['defaults']['format']); } - + if (isset($this->options['headers'])) { $this->parameters['headers'] = array_replace_recursive($this->formatter->setHeaders(), $this->options['headers']); } else { $this->parameters['headers'] = $this->formatter->setHeaders(); } - + if (isset($this->options['body'])) { if ($this->parameters['headers']['Content-Type'] == $this->formatter->getDefaultMIMEType()) { $this->parameters['body'] = $this->formatter->setBody($this->options['body']); @@ -228,13 +228,13 @@ private function handleRequest() } else { unset($this->parameters['body']); } - + if (isset($this->options['query'])) { $this->parameters['query'] = http_build_query($this->options['query']); } else { unset($this->parameters['query']); } - + if (isset($this->options['json'])) { $this->parameters['json'] = $this->options['json']; } else { diff --git a/src/Omniphx/Forrest/Providers/Laravel/Facades/Forrest.php b/src/Omniphx/Forrest/Providers/Laravel/Facades/Forrest.php index ad9e6ae..fdf6644 100644 --- a/src/Omniphx/Forrest/Providers/Laravel/Facades/Forrest.php +++ b/src/Omniphx/Forrest/Providers/Laravel/Facades/Forrest.php @@ -51,12 +51,10 @@ * @method static string|array compactLayouts(string $resource, array $options = []) * @method static string|array flexiPage(string $resource, array $options = []) * @method static string|array knowledgeManagement(string $resource, array $options = []) - * @method static string|array sobjects(string $resource, array $options = []) + * @method static string|array sobjects(string $resource = "", array $options = []) * @method static string|array actions(string $resource, array $options = []) * @method static string|array support(string $resource, array $options = []) - * @method static \GuzzleHttp\ClientInterface getClient() - * @method static string getInstanceURL() - * @method static string getBaseUrl() + * @method static \Omniphx\Forrest\Interfaces\RedirectInterface callback() */ class Forrest extends Facade { From 96cbd606dcd496ce626da0353133c35ca6f49082 Mon Sep 17 00:00:00 2001 From: Patrick Nomad <100162685+patricknomad@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:49:45 -0400 Subject: [PATCH 3/5] Add sandbox capability to OAuthJWT (#333) Thanks @patricknomad! Sorry for taking a while to get this merged in --- src/Omniphx/Forrest/Authentications/OAuthJWT.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Omniphx/Forrest/Authentications/OAuthJWT.php b/src/Omniphx/Forrest/Authentications/OAuthJWT.php index 9d18042..61013c6 100644 --- a/src/Omniphx/Forrest/Authentications/OAuthJWT.php +++ b/src/Omniphx/Forrest/Authentications/OAuthJWT.php @@ -21,24 +21,24 @@ public static function getJWT($iss, $aud, $sub, $privateKey) return JWT::encode($payload, $privateKey, 'RS256'); } - public function authenticate($url = null) + public function authenticate($fullInstanceUrl = null) { - $domain = $url ?? $this->credentials['loginURL'] . '/services/oauth2/token'; - $username = $this->credentials['username']; - // OAuth Client ID + $fullInstanceUrl = $fullInstanceUrl ?? $this->getInstanceURL() . '/services/oauth2/token'; + $consumerKey = $this->credentials['consumerKey']; - // Private Key + $loginUrl = $this->credentials['loginURL']; + $username = $this->credentials['username']; $privateKey = $this->credentials['privateKey']; // Generate the form parameters - $assertion = static::getJWT($consumerKey, $domain, $username, $privateKey); + $assertion = static::getJWT($consumerKey, $loginUrl, $username, $privateKey); $parameters = [ 'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer', 'assertion' => $assertion ]; // \Psr\Http\Message\ResponseInterface - $response = $this->httpClient->request('post', $domain, ['form_params' => $parameters]); + $response = $this->httpClient->request('post', $fullInstanceUrl, ['form_params' => $parameters]); $authToken = json_decode($response->getBody()->getContents(), true); From f67932d3270b250f5042a977ccb4baefd647c313 Mon Sep 17 00:00:00 2001 From: Zack Carlson Date: Fri, 22 Mar 2024 13:39:19 -0500 Subject: [PATCH 4/5] updates --- .../Forrest/Formatters/CsvFormatter.php | 132 +++++++++--------- .../Formatters/CsvHeadersFormatter.php | 69 +++++++++ 2 files changed, 132 insertions(+), 69 deletions(-) create mode 100644 src/Omniphx/Forrest/Formatters/CsvHeadersFormatter.php diff --git a/src/Omniphx/Forrest/Formatters/CsvFormatter.php b/src/Omniphx/Forrest/Formatters/CsvFormatter.php index 5fb6c3d..757305b 100644 --- a/src/Omniphx/Forrest/Formatters/CsvFormatter.php +++ b/src/Omniphx/Forrest/Formatters/CsvFormatter.php @@ -1,69 +1,63 @@ -tokenRepository = $tokenRepository; - $this->settings = $settings; - } - - public function setHeaders() - { - $accessToken = $this->tokenRepository->get()['access_token']; - $tokenType = $this->tokenRepository->get()['token_type']; - - $this->headers['Accept'] = $this->getDefaultAcceptMIMEType(); - $this->headers['Content-Type'] = $this->getDefaultMIMEType(); - $this->headers['Authorization'] = "$tokenType $accessToken"; - - $this->setCompression(); - - return $this->headers; - } - - private function setCompression() - { - if (!$this->settings['defaults']['compression']) return; - - $this->headers['Accept-Encoding'] = $this->settings['defaults']['compressionType']; - $this->headers['Content-Encoding'] = $this->settings['defaults']['compressionType']; - } - - public function setBody($data) - { - return $data; - } - - public function formatResponse($response) - { - $body = $response->getBody(); - $header = $response->getHeaders(); - $contents = (string) $body; - - return [ - 'header' => $header, - 'body' => $contents, - - ]; - } - - public function getDefaultMIMEType() - { - return $this->mimeType; - } - - public function getDefaultAcceptMIMEType() - { - return $this->acceptMimeType; - } -} +tokenRepository = $tokenRepository; + $this->settings = $settings; + } + + public function setHeaders() + { + $accessToken = $this->tokenRepository->get()['access_token']; + $tokenType = $this->tokenRepository->get()['token_type']; + + $this->headers['Accept'] = $this->getDefaultAcceptMIMEType(); + $this->headers['Content-Type'] = $this->getDefaultMIMEType(); + $this->headers['Authorization'] = "$tokenType $accessToken"; + + $this->setCompression(); + + return $this->headers; + } + + private function setCompression() + { + if (!$this->settings['defaults']['compression']) return; + + $this->headers['Accept-Encoding'] = $this->settings['defaults']['compressionType']; + $this->headers['Content-Encoding'] = $this->settings['defaults']['compressionType']; + } + + public function setBody($data) + { + return $data; + } + + public function formatResponse($response) + { + $body = $response->getBody(); + $contents = (string) $body; + return $contents; + } + + public function getDefaultMIMEType() + { + return $this->mimeType; + } + + public function getDefaultAcceptMIMEType() + { + return $this->acceptMimeType; + } +} \ No newline at end of file diff --git a/src/Omniphx/Forrest/Formatters/CsvHeadersFormatter.php b/src/Omniphx/Forrest/Formatters/CsvHeadersFormatter.php new file mode 100644 index 0000000..5fb6c3d --- /dev/null +++ b/src/Omniphx/Forrest/Formatters/CsvHeadersFormatter.php @@ -0,0 +1,69 @@ +tokenRepository = $tokenRepository; + $this->settings = $settings; + } + + public function setHeaders() + { + $accessToken = $this->tokenRepository->get()['access_token']; + $tokenType = $this->tokenRepository->get()['token_type']; + + $this->headers['Accept'] = $this->getDefaultAcceptMIMEType(); + $this->headers['Content-Type'] = $this->getDefaultMIMEType(); + $this->headers['Authorization'] = "$tokenType $accessToken"; + + $this->setCompression(); + + return $this->headers; + } + + private function setCompression() + { + if (!$this->settings['defaults']['compression']) return; + + $this->headers['Accept-Encoding'] = $this->settings['defaults']['compressionType']; + $this->headers['Content-Encoding'] = $this->settings['defaults']['compressionType']; + } + + public function setBody($data) + { + return $data; + } + + public function formatResponse($response) + { + $body = $response->getBody(); + $header = $response->getHeaders(); + $contents = (string) $body; + + return [ + 'header' => $header, + 'body' => $contents, + + ]; + } + + public function getDefaultMIMEType() + { + return $this->mimeType; + } + + public function getDefaultAcceptMIMEType() + { + return $this->acceptMimeType; + } +} From faa6e76fc040972cef2bfdcfb209d49ec04360c1 Mon Sep 17 00:00:00 2001 From: Zack Carlson Date: Fri, 22 Mar 2024 13:53:26 -0500 Subject: [PATCH 5/5] updates --- src/Omniphx/Forrest/Formatters/CsvHeadersFormatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Omniphx/Forrest/Formatters/CsvHeadersFormatter.php b/src/Omniphx/Forrest/Formatters/CsvHeadersFormatter.php index 5fb6c3d..9d61e40 100644 --- a/src/Omniphx/Forrest/Formatters/CsvHeadersFormatter.php +++ b/src/Omniphx/Forrest/Formatters/CsvHeadersFormatter.php @@ -4,7 +4,7 @@ use Omniphx\Forrest\Interfaces\FormatterInterface; -class CsvFormatter implements FormatterInterface +class CsvHeadersFormatter implements FormatterInterface { protected $tokenRepository; protected $settings;