Ejemplo n.º 1
0
 /**
  * Tests \OAuth2\Server\Server->grantAccessToken() with successful Auth code grant, but without redreict_uri in the input
  */
 public function testGrantAccessTokenWithGrantAuthCodeSuccessWithoutRedirect()
 {
     $inputData = array('grant_type' => \OAuth2\Server\Server::GRANT_TYPE_AUTH_CODE, 'client_id' => 'my_little_app', 'client_secret' => 'b', 'code' => 'foo');
     $storedToken = array('redirect_uri' => 'http://www.example.com', 'client_id' => 'my_little_app', 'expires' => time() + 60);
     $mockStorage = $this->createBaseMock('\\OAuth2\\Grant\\GrantCodeInterface');
     $mockStorage->expects($this->any())->method('getAuthCode')->will($this->returnValue($storedToken));
     // Successful token grant will return a JSON encoded token:
     $this->expectOutputRegex('/{"access_token":".*","expires_in":\\d+,"token_type":"bearer"/');
     $this->fixture = new \OAuth2\Server\Server($mockStorage);
     $this->fixture->setVariable(\OAuth2\Server\Server::CONFIG_ENFORCE_INPUT_REDIRECT, false);
     $this->fixture->grantAccessToken($inputData, array());
 }
Ejemplo n.º 2
0
 /**
  * Tests \OAuth2\Server\Server->grantAccessToken() with Auth code grant
  *
  */
 public function testGrantAccessTokenWithGrantAuthCodeMandatoryParams()
 {
     $mockStorage = $this->createBaseMock('OAuth2\\Grant\\GrantCodeInterface');
     $inputData = array('grant_type' => \OAuth2\Server\Server::GRANT_TYPE_AUTH_CODE, 'client_id' => 'a', 'client_secret' => 'b');
     $fakeAuthCode = array('client_id' => $inputData['client_id'], 'redirect_uri' => '/foo', 'expires' => time() + 60);
     $fakeAccessToken = array('access_token' => 'abcde');
     // Ensure redirect URI and auth-code is mandatory
     try {
         $this->fixture = new \OAuth2\Server\Server($mockStorage);
         $this->fixture->setVariable(\OAuth2\Server\Server::CONFIG_ENFORCE_INPUT_REDIRECT, true);
         // Only required when this is set
         $this->fixture->grantAccessToken($inputData + array('code' => 'foo'), array());
         $this->fail('The expected exception \\OAuth2\\Exception\\ServerException was not thrown');
     } catch (\OAuth2\Exception\ServerException $e) {
         $this->assertEquals(\OAuth2\Server\Server::ERROR_INVALID_REQUEST, $e->getMessage());
     }
     try {
         $this->fixture = new \OAuth2\Server\Server($mockStorage);
         $this->fixture->grantAccessToken($inputData + array('redirect_uri' => 'foo'), array());
         $this->fail('The expected exception \\OAuth2\\Exception\\ServerException was not thrown');
     } catch (\OAuth2\Exception\ServerException $e) {
         $this->assertEquals(\OAuth2\Server\Server::ERROR_INVALID_REQUEST, $e->getMessage());
     }
 }