From 11538f98d17ecb0ff6309ca31da5a2847737cf6b Mon Sep 17 00:00:00 2001 From: Kele Nakamura Date: Fri, 17 Apr 2020 14:42:45 -0700 Subject: [PATCH] Mod: Adds GET query parameters to token oauth signature --- src/Models/Oauth.php | 35 ++++++++++++++++++++++----------- src/Services/RestletService.php | 4 ++-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/Models/Oauth.php b/src/Models/Oauth.php index 1e20a59..cdd2e1c 100644 --- a/src/Models/Oauth.php +++ b/src/Models/Oauth.php @@ -3,7 +3,7 @@ class Oauth { protected $oauth_nonce, $oauth_timestamp, $oauth_signature_method, $oauth_version; - protected $url, $arrConfig, $strScriptId, $strMethod; + protected $url, $arrConfig, $strScriptId, $strMethod, $arrData; protected $baseString, $signatureString, $oauthSignature, $oauthHeader; /** @@ -126,7 +126,7 @@ public function getOauthHeader() return $this->oauthHeader; } - public function __construct($arrConfig, $strScriptId, $strMethod) + public function __construct($arrConfig, $strScriptId, $strMethod, $arrData) { $this->setOauthNonce(md5(mt_rand())); $this->setOauthTimestamp(time()); @@ -136,6 +136,7 @@ public function __construct($arrConfig, $strScriptId, $strMethod) $sigMeth = array_key_exists('signatureAlgorithm', $arrConfig) ? $arrConfig['signatureAlgorithm'] : 'HMAC-SHA256'; $this->setOauthSignatureMethod($sigMeth); $this->setStrMethod($strMethod); + $this->arrData = $arrData; $this->setBaseString(); $this->setSignatureString(); @@ -146,17 +147,27 @@ public function __construct($arrConfig, $strScriptId, $strMethod) public function setBaseString() { + $arr = [ + 'deploy' => 1, + 'oauth_consumer_key' => $this->getArrConfig()['consumerKey'], + 'oauth_nonce' => $this->getOauthNonce(), + 'oauth_signature_method' => $this->getOauthSignatureMethod(), + 'oauth_timestamp' => $this->getOauthTimestamp(), + 'oauth_token' => $this->getArrConfig()['token'], + 'oauth_version' => $this->getOauthVersion(), + 'realm' => $this->getArrConfig()['account'], + 'script' => $this->getStrScriptId() + ]; + if ($this->getStrMethod() === 'GET') { + $arr = array_merge($arr, $this->arrData); + ksort($arr); + $arrOut = []; + foreach ($arr as $k => $v) { + $arrOut[] = "$k=$v"; + } + } $this->baseString=$this->getStrMethod()."&" . urlencode($this->getArrConfig()['host']) . "&" . - urlencode("deploy=1" - . "&oauth_consumer_key=" . $this->getArrConfig()['consumerKey'] - . "&oauth_nonce=" . $this->getOauthNonce() - . "&oauth_signature_method=" . $this->getOauthSignatureMethod() - . "&oauth_timestamp=" . $this->getOauthTimestamp() - . "&oauth_token=" . $this->getArrConfig()['token'] - . "&oauth_version=" . $this->getOauthVersion() - . "&realm=" . $this->getArrConfig()['account'] - . "&script=" . $this->getStrScriptId() - ); + urlencode(implode('&', $arrOut)); } public function setSignatureString() diff --git a/src/Services/RestletService.php b/src/Services/RestletService.php index 710625c..75f5d2a 100644 --- a/src/Services/RestletService.php +++ b/src/Services/RestletService.php @@ -113,7 +113,7 @@ public function getMethod() */ public function setMethod($method) { - $this->method = $method; + $this->method = strtoupper($method); } /** @@ -238,7 +238,7 @@ public function callWithNlAuth() public function callWithToken() { $RESTlet = $this->arrConfig['host'].'?script='.$this->getStrScriptId().'&deploy=1&realm='.$this->getArrConfig()['account']; - $this->oauth = new Oauth($this->getArrConfig(), $this->getStrScriptId(), $this->getMethod()); + $this->oauth = new Oauth($this->getArrConfig(), $this->getStrScriptId(), $this->getMethod(), $this->getArrData()); $tokenHeaders = [ 'Content-Type' => 'application/json', 'Authorization' => $this->oauth->getOauthHeader()