Skip to content

Commit

Permalink
Add getter
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Feb 13, 2014
1 parent fd1ca9c commit 7f4cf56
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/ZfrOAuth2/Server/AuthorizationServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public function __construct(ClientService $clientService, array $grants)
$grant->setAuthorizationServer($this);
}

$this->grants[$grant::GRANT_TYPE] = $grant;
$this->grants[$grant->getType()] = $grant;

if (null !== $grant::GRANT_RESPONSE_TYPE) {
$this->responseTypes[$grant::GRANT_RESPONSE_TYPE] = $grant;
if ($responseType = $grant->getResponseType()) {
$this->responseTypes[$responseType] = $grant;
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/ZfrOAuth2/Server/Grant/AbstractGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,20 @@ protected function populateToken(

$token->setScopes($scopes ?: []);
}

/**
* {@inheritDoc}
*/
public function getType()
{
return static::GRANT_TYPE;
}

/**
* {@inheritDoc}
*/
public function getResponseType()
{
return static::GRANT_RESPONSE_TYPE;
}
}
14 changes: 14 additions & 0 deletions src/ZfrOAuth2/Server/Grant/GrantInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ public function createAuthorizationResponse(Request $request, Client $client, To
*/
public function createTokenResponse(Request $request, Client $client = null, TokenOwnerInterface $owner = null);

/**
* Get the grant type
*
* @return string
*/
public function getType();

/**
* Get the grant response type
*
* @return string|null
*/
public function getResponseType();

/**
* Does this authorization grant allow public clients?
*
Expand Down
17 changes: 12 additions & 5 deletions tests/ZfrOAuth2Test/Server/AuthorizationServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ class AuthorizationServerTest extends \PHPUnit_Framework_TestCase
public function testCanCheckAndGetForGrants()
{
$clientService = $this->getMock('ZfrOAuth2\Server\Service\ClientService', [], [], '', false);
$grant = $this->getMock('ZfrOAuth2\Server\Grant\PasswordGrant', [], [], '', false);
$grant = new PasswordGrant(
$this->getMock('ZfrOAuth2\Server\Service\TokenService', [], [], '', false),
$this->getMock('ZfrOAuth2\Server\Service\TokenService', [], [], '', false),
function() {}
);

$authorizationServer = new AuthorizationServer($clientService, [$grant]);

Expand All @@ -50,7 +54,11 @@ public function testCanCheckAndGetForGrants()
public function testCanCheckAndGetForResponseType()
{
$clientService = $this->getMock('ZfrOAuth2\Server\Service\ClientService', [], [], '', false);
$grant = $this->getMock('ZfrOAuth2\Server\Grant\AuthorizationGrant', [], [], '', false);
$grant = new AuthorizationGrant(
$this->getMock('ZfrOAuth2\Server\Service\TokenService', [], [], '', false),
$this->getMock('ZfrOAuth2\Server\Service\TokenService', [], [], '', false),
$this->getMock('ZfrOAuth2\Server\Service\TokenService', [], [], '', false)
);

$authorizationServer = new AuthorizationServer($clientService, [$grant]);

Expand Down Expand Up @@ -98,11 +106,10 @@ public function testThrowExceptionIfPrivateClientDoesNotHaveSecret()
$request = new HttpRequest();
$request->getPost()->set('grant_type', 'client_credentials');

$grantType = $this->getMock('ZfrOAuth2\Server\Grant\ClientCredentialsGrant', [], [], '', false);
$grantType->expects($this->once())->method('allowPublicClients')->will($this->returnValue(false));
$grant = new ClientCredentialsGrant($this->getMock('ZfrOAuth2\Server\Service\TokenService', [], [], '', false));

$clientService = $this->getMock('ZfrOAuth2\Server\Service\ClientService', [], [], '', false);
$authorizationServer = new AuthorizationServer($clientService, [$grantType]);
$authorizationServer = new AuthorizationServer($clientService, [$grant]);

$response = $authorizationServer->handleTokenRequest($request);
$body = json_decode($response->getBody(), true);
Expand Down

0 comments on commit 7f4cf56

Please sign in to comment.