/** * Everything should succeed, even though there is no accessToken. * * @test * @covers Simgroep\Oauth1Service\Service::isValidRequest * @covers Simgroep\Oauth1Service\Service::buildSignature * @covers Simgroep\Oauth1Service\Service::getDetails */ public function validRequestSignatureWithMissingOptionalAccessToken() { $this->request->expects($this->any())->method('getRequestParameters')->will($this->returnValue(array('foo' => 'bar'))); $this->request->expects($this->any())->method('getRequestMethod')->will($this->returnValue('GET')); $this->request->expects($this->any())->method('getRequestUri')->will($this->returnValue('http://example.org/test')); $this->request->header->expects($this->any())->method('offsetGet')->will($this->returnCallback(function ($key) { $returnValues = array('version' => '1.0', 'signature_method' => 'HMAC-SHA1', 'signature' => '7mA56+DuwfTQwWExdBQDaE2EwH4=', 'consumer_key' => 'consumerKey', 'token' => '', 'nonce' => '9c7e78fc42a259ee7ec5b600543e2495', 'timestamp' => '1234567890'); return $returnValues[$key]; })); $this->consumerProvider->expects($this->any())->method('getSecret')->will($this->returnValue('consumerSecret')); $this->object->setAccessTokenRequired(false); $this->assertTrue($this->object->isValidRequest()); $this->assertEquals('Unknown error.', $this->object->getError()); $details = $this->object->getDetails(); $this->assertArrayHasKey('consumerToken', $details); $this->assertArrayHasKey('accessToken', $details); $this->assertEquals('consumerKey', $details['consumerToken']); $this->assertEquals('', $details['accessToken']); }
* Example usage of service. * * The variables in $_SERVER represent what you might get in a typical application */ require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/ConsumerProvider.php'; require __DIR__ . '/TokenProvider.php'; $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['HTTP_HOST'] = 'example.org'; $_SERVER['REQUEST_URI'] = '/test'; $_SERVER['HTTP_AUTHORIZATION'] = 'OAuth oauth_consumer_key="consumerKey", oauth_nonce="7e17b4754c0b43078688a1fd5565b762", oauth_signature="rElCV6n%2FCeexrlLnR0w67NFMTf4%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1380629569", oauth_token="tokenKey", oauth_version="1.0"'; use Simgroep\Oauth1Service\Service; use Simgroep\Oauth1Service\Request; use Simgroep\Oauth1Service\SymfonyRequest; use Simgroep\Oauth1Service\Zf1Request; try { $request = new Request(); # or: #$request = new SymfonyRequest(/* instance of Symfony\Component\HttpFoundation\Request */); # or #$request = new Zf1Request(/* instance of Zend_Controller_Request_Http */); $os = new Service($request, new ConsumerProvider(), new TokenProvider()); $valid = $os->isValidRequest(); if ($valid === true) { print_r($os->getDetails()); } else { print_r($os->getError()); } } catch (\Simgroep\Oauth1Service\Exception $e) { echo $e->getMessage(); }