/** * {@inheritDoc} */ public function preSend(RequestInterface $request) { $params = $this->getParametersToSign($request); $req = OAuth1\Request\Request::fromConsumerAndToken($this->consumer, $this->token, $request->getMethod(), $request->getUrl(), $params); $req->signRequest($this->signature, $this->consumer, $this->token); $request->addHeader($req->toHeader()); }
public function testHttpUrlCanBeNormalized() { $request = new Request('foo', 'bar', array('oauth_consumer_key' => 'bar')); $this->assertEquals('http://bar', $request->getNormalizedHttpUrl()); $request = new Request('foo', 'example.com:80', array('oauth_consumer_key' => 'bar')); $this->assertEquals('http://example.com', $request->getNormalizedHttpUrl()); $request = new Request('foo', 'example.com:81', array('oauth_consumer_key' => 'bar')); $this->assertEquals('http://example.com:81', $request->getNormalizedHttpUrl()); $request = new Request('foo', 'https://example.com', array('oauth_consumer_key' => 'bar')); $this->assertEquals('https://example.com', $request->getNormalizedHttpUrl()); $request = new Request('foo', 'https://example.com:443', array('oauth_consumer_key' => 'bar')); $this->assertEquals('https://example.com', $request->getNormalizedHttpUrl()); $request = new Request('foo', 'http://example.com/foobar', array('oauth_consumer_key' => 'bar')); $this->assertEquals('http://example.com/foobar', $request->getNormalizedHttpUrl()); $request = new Request('foo', 'example.org:80/foobar', array('oauth_consumer_key' => 'bar')); $this->assertEquals('http://example.org/foobar', $request->getNormalizedHttpUrl()); }
/** * Helper function to set up the request. * * @param JacobKiers\OAuth\Consumer\ConsumerInterface $consumer * @param JacobKiers\OAuth\Token\TokenInterface $token * @param string $http_method * @param string $http_url * @param array $parameters * * @return JacobKiers\OAuth\Request\RequestInterface */ public static function fromConsumerAndToken(ConsumerInterface $consumer, TokenInterface $token, $http_method, $http_url, array $parameters = null) { $parameters = $parameters ? $parameters : array(); $defaults = array('oauth_nonce' => Request::generateNonce(), 'oauth_timestamp' => Request::generateTimestamp(), 'oauth_consumer_key' => $consumer->getKey()); if ($token->getKey()) { $defaults['oauth_token'] = $token->getKey(); } $parameters = array_merge($defaults, $parameters); return new Request($http_method, $http_url, $parameters); }