Skip to content

Commit

Permalink
Fix to latest master
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Jan 14, 2014
1 parent a937844 commit 4ea4ab8
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 58 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@ return [
]
];
```

You can also pass a service key, that will be pulled from the service manager, if you need to inject dependencies.
1 change: 1 addition & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'ZfrOAuth2\Server\AuthorizationServer' => 'ZfrOAuth2Module\Server\Factory\AuthorizationServerFactory',
'ZfrOAuth2\Server\ResourceServer' => 'ZfrOAuth2Module\Server\Factory\ResourceServerFactory',
'ZfrOAuth2\Server\Service\ClientService' => 'ZfrOAuth2Module\Server\Factory\ClientServiceFactory',
'ZfrOAuth2\Server\Service\ScopeService' => 'ZfrOAuth2Module\Server\Factory\ScopeServiceFactory',
'ZfrOAuth2Module\Server\Authentication\Adapter\AccessTokenAdapter' => 'ZfrOAuth2Module\Server\Factory\AccessTokenAdapterFactory',
'ZfrOAuth2Module\Server\Options\ModuleOptions' => 'ZfrOAuth2Module\Server\Factory\ModuleOptionsFactory',
'ZfrOAuth2Module\Server\Grant\GrantPluginManager' => 'ZfrOAuth2Module\Server\Factory\GrantPluginManagerFactory',
Expand Down
5 changes: 0 additions & 5 deletions config/zfr_oauth2_server.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ return [
// 'access_token_ttl' => 3600,
// 'refresh_token_ttl' => 86400,

/**
* Default scopes to use when a token is generated, if none is specified
*/
'default_scopes' => [],

/**
* Registered grants for this server
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ public function createService(ServiceLocatorInterface $serviceLocator)
/* @var \Doctrine\Common\Persistence\ObjectManager $objectManager */
$objectManager = $serviceLocator->get($options->getObjectManager());
$tokenRepository = $objectManager->getRepository('ZfrOAuth2\Server\Entity\AccessToken');
$scopeRepository = $objectManager->getRepository('ZfrOAuth2\Server\Entity\Scope');

$accessTokenService = new TokenService($objectManager, $tokenRepository, $scopeRepository);
/* @var \ZfrOAuth2Module\Server\Service\ScopeService $scopeService */
$scopeService = $serviceLocator->get('ZfrOAuth2\Server\Service\ScopeService');

$accessTokenService = new TokenService($objectManager, $tokenRepository, $scopeService);
$accessTokenService->setTokenTTL($options->getAccessTokenTtl());
$accessTokenService->setDefaultScopes($options->getDefaultScopes());

return $accessTokenService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ public function createService(ServiceLocatorInterface $serviceLocator)
/* @var \Doctrine\Common\Persistence\ObjectManager $objectManager */
$objectManager = $serviceLocator->get($options->getObjectManager());
$tokenRepository = $objectManager->getRepository('ZfrOAuth2\Server\Entity\AuthorizationCode');
$scopeRepository = $objectManager->getRepository('ZfrOAuth2\Server\Entity\Scope');

$authorizationCodeService = new TokenService($objectManager, $tokenRepository, $scopeRepository);
/* @var \ZfrOAuth2Module\Server\Service\ScopeService $scopeService */
$scopeService = $serviceLocator->get('ZfrOAuth2\Server\Service\ScopeService');

$authorizationCodeService = new TokenService($objectManager, $tokenRepository, $scopeService);
$authorizationCodeService->setTokenTTL($options->getAuthorizationCodeTtl());
$authorizationCodeService->setDefaultScopes($options->getDefaultScopes());

return $authorizationCodeService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ public function createService(ServiceLocatorInterface $serviceLocator)
/* @var \Doctrine\Common\Persistence\ObjectManager $objectManager */
$objectManager = $serviceLocator->get($options->getObjectManager());
$tokenRepository = $objectManager->getRepository('ZfrOAuth2\Server\Entity\RefreshToken');
$scopeRepository = $objectManager->getRepository('ZfrOAuth2\Server\Entity\Scope');

$refreshTokenService = new TokenService($objectManager, $tokenRepository, $scopeRepository);
/* @var \ZfrOAuth2Module\Server\Service\ScopeService $scopeService */
$scopeService = $serviceLocator->get('ZfrOAuth2\Server\Service\ScopeService');

$refreshTokenService = new TokenService($objectManager, $tokenRepository, $scopeService);
$refreshTokenService->setTokenTTL($options->getRefreshTokenTtl());
$refreshTokenService->setDefaultScopes($options->getDefaultScopes());

return $refreshTokenService;
}
Expand Down
45 changes: 45 additions & 0 deletions src/ZfrOAuth2Module/Server/Factory/ScopeServiceFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/

namespace ZfrOAuth2Module\Server\Factory;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfrOAuth2\Server\Service\ScopeService;

/**
* @author Michaël Gallego <mic.gallego@gmail.com>
* @licence MIT
*/
class ScopeServiceFactory implements FactoryInterface
{
/**
* {@inheritDoc}
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
/* @var \ZfrOAuth2Module\Server\Options\ModuleOptions $options */
$options = $serviceLocator->get('ZfrOAuth2Module\Server\Options\ModuleOptions');

/* @var \Doctrine\Common\Persistence\ObjectManager $objectManager */
$objectManager = $serviceLocator->get($options->getObjectManager());
$scopeRepository = $objectManager->getRepository('ZfrOAuth2\Server\Entity\Scope');

return new ScopeService($objectManager, $scopeRepository);
}
}
27 changes: 0 additions & 27 deletions src/ZfrOAuth2Module/Server/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ class ModuleOptions extends AbstractOptions
*/
protected $refreshTokenTtl = 86400;

/**
* Default scopes to use when a token is generated
*
* @var array
*/
protected $defaultScopes = [];

/**
* Set the owner callable
*
Expand Down Expand Up @@ -166,26 +159,6 @@ public function getRefreshTokenTtl()
return $this->refreshTokenTtl;
}

/**
* Set the default scopes to use when generating a token
*
* @param array $defaultScopes
*/
public function setDefaultScopes(array $defaultScopes)
{
$this->defaultScopes = $defaultScopes;
}

/**
* Get the default scopes to use when generating a token
*
* @return array
*/
public function getDefaultScopes()
{
return $this->defaultScopes;
}

/**
* Set the callable used to validate a user (or service name)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public function testCanCreateFromFactory()
->with('ZfrOAuth2\Server\Entity\AccessToken')
->will($this->returnValue($this->getMock('Doctrine\Common\Persistence\ObjectRepository')));

$objectManager->expects($this->at(1))
->method('getRepository')
->with('ZfrOAuth2\Server\Entity\Scope')
->will($this->returnValue($this->getMock('Doctrine\Common\Persistence\ObjectRepository')));
$serviceManager->setService(
'ZfrOAuth2\Server\Service\ScopeService',
$this->getMock('ZfrOAuth2\Server\Service\ScopeService', [], [], '', false)
);

$factory = new AccessTokenServiceFactory();
$service = $factory->createService($serviceManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public function testCanCreateFromFactory()
->with('ZfrOAuth2\Server\Entity\AuthorizationCode')
->will($this->returnValue($this->getMock('Doctrine\Common\Persistence\ObjectRepository')));

$objectManager->expects($this->at(1))
->method('getRepository')
->with('ZfrOAuth2\Server\Entity\Scope')
->will($this->returnValue($this->getMock('Doctrine\Common\Persistence\ObjectRepository')));
$serviceManager->setService(
'ZfrOAuth2\Server\Service\ScopeService',
$this->getMock('ZfrOAuth2\Server\Service\ScopeService', [], [], '', false)
);

$factory = new AuthorizationCodeServiceFactory();
$service = $factory->createService($serviceManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public function testCanCreateFromFactory()
->with('ZfrOAuth2\Server\Entity\RefreshToken')
->will($this->returnValue($this->getMock('Doctrine\Common\Persistence\ObjectRepository')));

$objectManager->expects($this->at(1))
->method('getRepository')
->with('ZfrOAuth2\Server\Entity\Scope')
->will($this->returnValue($this->getMock('Doctrine\Common\Persistence\ObjectRepository')));
$serviceManager->setService(
'ZfrOAuth2\Server\Service\ScopeService',
$this->getMock('ZfrOAuth2\Server\Service\ScopeService', [], [], '', false)
);

$factory = new RefreshTokenServiceFactory();
$service = $factory->createService($serviceManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@ public function testSettersAndGetters()
'authorization_code_ttl' => 300,
'access_token_ttl' => 3000,
'refresh_token_ttl' => 30000,
'default_scopes' => ['read'],
'owner_callable' => $callable,
'grants' => [
'ZfrOAuth2\Server\Grant\ClientCredentialsGrant'
]
'grants' => ['ZfrOAuth2\Server\Grant\ClientCredentialsGrant']
]);

$this->assertEquals('my_object_manager', $options->getObjectManager());
$this->assertEquals(300, $options->getAuthorizationCodeTtl());
$this->assertEquals(3000, $options->getAccessTokenTtl());
$this->assertEquals(30000, $options->getRefreshTokenTtl());
$this->assertEquals(['read'], $options->getDefaultScopes());
$this->assertSame($callable, $options->getOwnerCallable());
$this->assertEquals(['ZfrOAuth2\Server\Grant\ClientCredentialsGrant'], $options->getGrants());
}
Expand Down

0 comments on commit 4ea4ab8

Please sign in to comment.