Skip to content

Commit

Permalink
Merge pull request #294 from calcinai/remove-request-member
Browse files Browse the repository at this point in the history
Removed member property for request in OAuth client
  • Loading branch information
calcinai authored May 29, 2018
2 parents 84ff5e2 + 045c509 commit f661b3b
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/XeroPHP/Remote/OAuth/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ class Client

private $config;

/**
* @var Request $request
*/
private $request;

/*
* "Cached" parameters - will change between signings.
*/
Expand Down Expand Up @@ -62,10 +57,8 @@ public function __construct(array $config)
*/
public function sign(Request $request)
{
$this->request = $request;

$oauth_params = $this->getOAuthParams();
$oauth_params['oauth_signature'] = $this->getSignature();
$oauth_params['oauth_signature'] = $this->getSignature($request);

//put it where it needs to go in the request
switch ($this->config['signature_location']) {
Expand Down Expand Up @@ -137,29 +130,30 @@ private function getOAuthParams()
* Not all mechanisms use all of the parameters, but for
* consistency, pass the same constructor to each one.
*
* @param Request $request
* @return string
* @throws Exception
*/
private function getSignature()
private function getSignature(Request $request)
{
switch ($this->getSignatureMethod()) {
case self::SIGNATURE_RSA_SHA1:
$signature = RSASHA1::generateSignature(
$this->config,
$this->getSBS(),
$this->getSBS($request),
$this->getSigningSecret()
);
break;
case self::SIGNATURE_HMAC_SHA1:
$signature = HMACSHA1::generateSignature(
$this->config,
$this->getSBS(),
$this->getSBS($request),
$this->getSigningSecret()
);
break;
case self::SIGNATURE_PLAINTEXT:
$signature = PLAINTEXT::generateSignature(
$this->config, $this->getSBS(),
$this->config, $this->getSBS($request),
$this->getSigningSecret()
);
break;
Expand All @@ -178,24 +172,24 @@ private function getSignature()
* ordered by key, then concatenated with the method and URL
* GET&https%3A%2F%2Fapi.xero.com%2Fapi.xro%2F2.0%2FContacts&oauth_consumer etc.
*
* @param Request $request
* @return string
*/
public function getSBS()
public function getSBS(Request $request)
{
$oauth_params = $this->getOAuthParams();
$request_params = $this->request->getParameters();

$sbs_params = array_merge($request_params, $oauth_params);
$sbs_params = array_merge($request->getParameters(), $oauth_params);
//Params need sorting so signing order is the same
ksort($sbs_params);
$sbs_string = Helpers::flattenAssocArray($sbs_params, '%s=%s', '&', true);

$url = $this->request->getUrl()->getFullURL();
$url = $request->getUrl()->getFullURL();

//Every second thing seems to need escaping!
return sprintf(
'%s&%s&%s',
$this->request->getMethod(),
$request->getMethod(),
Helpers::escape($url),
Helpers::escape($sbs_string)
);
Expand Down

0 comments on commit f661b3b

Please sign in to comment.