Skip to content

Commit

Permalink
Mod: Adds GET query parameters to token oauth signature
Browse files Browse the repository at this point in the history
  • Loading branch information
kelenakamura committed Apr 17, 2020
1 parent 79fba7e commit 11538f9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
35 changes: 23 additions & 12 deletions src/Models/Oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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());
Expand All @@ -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();
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/Services/RestletService.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function getMethod()
*/
public function setMethod($method)
{
$this->method = $method;
$this->method = strtoupper($method);
}

/**
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 11538f9

Please sign in to comment.