mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-23 05:29:52 +05:30
template renderer holds template related information
This commit is contained in:
parent
25f93071ea
commit
ee91072455
@ -18,73 +18,25 @@ use League\Plates\Engine;
|
|||||||
abstract class AbstractAuthorizeGrant extends AbstractGrant
|
abstract class AbstractAuthorizeGrant extends AbstractGrant
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var null|\League\OAuth2\Server\TemplateRenderer\RendererInterface
|
* @var \League\OAuth2\Server\TemplateRenderer\RendererInterface
|
||||||
*/
|
*/
|
||||||
protected $templateRenderer;
|
protected $templateRenderer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var null|string
|
* Retrieve template renderer.
|
||||||
*/
|
|
||||||
protected $loginTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var null|string
|
|
||||||
*/
|
|
||||||
protected $authorizeTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
*
|
*
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function renderLoginTemplate(array $data = [])
|
|
||||||
{
|
|
||||||
return $this->getTemplateRenderer()->render($this->getLoginTemplate(), $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function renderAuthorizeTemplate(array $data = [])
|
|
||||||
{
|
|
||||||
return $this->getTemplateRenderer()->render($this->getAuthorizeTemplate(), $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \League\OAuth2\Server\TemplateRenderer\RendererInterface
|
* @return \League\OAuth2\Server\TemplateRenderer\RendererInterface
|
||||||
*/
|
*/
|
||||||
protected function getTemplateRenderer()
|
protected function getTemplateRenderer()
|
||||||
{
|
{
|
||||||
if (!$this->templateRenderer instanceof RendererInterface) {
|
if (!$this->templateRenderer instanceof RendererInterface) {
|
||||||
$this->templateRenderer = new PlatesRenderer(new Engine(__DIR__ . '/../ResponseTypes/DefaultTemplates'));
|
$this->templateRenderer = new PlatesRenderer(
|
||||||
|
new Engine(__DIR__ . '/../TemplateRenderer/DefaultTemplates'),
|
||||||
|
'login_user',
|
||||||
|
'authorize_client'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->templateRenderer;
|
return $this->templateRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getLoginTemplate()
|
|
||||||
{
|
|
||||||
if (empty($this->loginTemplate)) {
|
|
||||||
$this->loginTemplate = 'login_user';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->loginTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getAuthorizeTemplate()
|
|
||||||
{
|
|
||||||
if (empty($this->authorizeTemplate)) {
|
|
||||||
$this->authorizeTemplate = 'authorize_client';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->authorizeTemplate;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface;
|
|||||||
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
|
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
|
||||||
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
|
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
|
||||||
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
|
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
|
||||||
use League\OAuth2\Server\TemplateRenderer\RendererInterface;
|
use League\OAuth2\Server\TemplateRenderer\AbstractRenderer;
|
||||||
use League\OAuth2\Server\Utils\KeyCrypt;
|
use League\OAuth2\Server\Utils\KeyCrypt;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Zend\Diactoros\Response;
|
use Zend\Diactoros\Response;
|
||||||
@ -29,26 +29,20 @@ class AuthCodeGrant extends AbstractAuthorizeGrant
|
|||||||
* @param \League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface $refreshTokenRepository
|
* @param \League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface $refreshTokenRepository
|
||||||
* @param \League\OAuth2\Server\Repositories\UserRepositoryInterface $userRepository
|
* @param \League\OAuth2\Server\Repositories\UserRepositoryInterface $userRepository
|
||||||
* @param \DateInterval $authCodeTTL
|
* @param \DateInterval $authCodeTTL
|
||||||
* @param string|null $loginTemplate
|
* @param \League\OAuth2\Server\TemplateRenderer\AbstractRenderer|null $templateRenderer
|
||||||
* @param string|null $authorizeTemplate
|
|
||||||
* @param \League\OAuth2\Server\TemplateRenderer\RendererInterface|null $templateRenderer
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AuthCodeRepositoryInterface $authCodeRepository,
|
AuthCodeRepositoryInterface $authCodeRepository,
|
||||||
RefreshTokenRepositoryInterface $refreshTokenRepository,
|
RefreshTokenRepositoryInterface $refreshTokenRepository,
|
||||||
UserRepositoryInterface $userRepository,
|
UserRepositoryInterface $userRepository,
|
||||||
\DateInterval $authCodeTTL,
|
\DateInterval $authCodeTTL,
|
||||||
$loginTemplate = null,
|
AbstractRenderer $templateRenderer = null
|
||||||
$authorizeTemplate = null,
|
|
||||||
RendererInterface $templateRenderer = null
|
|
||||||
) {
|
) {
|
||||||
$this->setAuthCodeRepository($authCodeRepository);
|
$this->setAuthCodeRepository($authCodeRepository);
|
||||||
$this->setRefreshTokenRepository($refreshTokenRepository);
|
$this->setRefreshTokenRepository($refreshTokenRepository);
|
||||||
$this->setUserRepository($userRepository);
|
$this->setUserRepository($userRepository);
|
||||||
$this->authCodeTTL = $authCodeTTL;
|
$this->authCodeTTL = $authCodeTTL;
|
||||||
$this->refreshTokenTTL = new \DateInterval('P1M');
|
$this->refreshTokenTTL = new \DateInterval('P1M');
|
||||||
$this->loginTemplate = $loginTemplate;
|
|
||||||
$this->authorizeTemplate = $authorizeTemplate;
|
|
||||||
$this->templateRenderer = $templateRenderer;
|
$this->templateRenderer = $templateRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +138,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant
|
|||||||
|
|
||||||
// The user hasn't logged in yet so show a login form
|
// The user hasn't logged in yet so show a login form
|
||||||
if ($userId === null) {
|
if ($userId === null) {
|
||||||
$html = $this->renderLoginTemplate([
|
$html = $this->getTemplateRenderer()->renderLogin([
|
||||||
'error' => $loginError,
|
'error' => $loginError,
|
||||||
'postback_uri' => (string) $postbackUri->withQuery($queryString),
|
'postback_uri' => (string) $postbackUri->withQuery($queryString),
|
||||||
]);
|
]);
|
||||||
@ -154,7 +148,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant
|
|||||||
|
|
||||||
// The user hasn't approved the client yet so show an authorize form
|
// The user hasn't approved the client yet so show an authorize form
|
||||||
if ($userId !== null && $userHasApprovedClient === null) {
|
if ($userId !== null && $userHasApprovedClient === null) {
|
||||||
$html = $this->renderAuthorizeTemplate([
|
$html = $this->getTemplateRenderer()->renderAuthorize([
|
||||||
'client' => $client,
|
'client' => $client,
|
||||||
'scopes' => $scopes,
|
'scopes' => $scopes,
|
||||||
'postback_uri' => (string) $postbackUri->withQuery($queryString),
|
'postback_uri' => (string) $postbackUri->withQuery($queryString),
|
||||||
|
@ -8,7 +8,7 @@ use League\OAuth2\Server\Entities\Interfaces\UserEntityInterface;
|
|||||||
use League\OAuth2\Server\Exception\OAuthServerException;
|
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||||
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
|
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
|
||||||
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
|
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
|
||||||
use League\OAuth2\Server\TemplateRenderer\RendererInterface;
|
use League\OAuth2\Server\TemplateRenderer\AbstractRenderer;
|
||||||
use League\OAuth2\Server\Utils\KeyCrypt;
|
use League\OAuth2\Server\Utils\KeyCrypt;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Zend\Diactoros\Response;
|
use Zend\Diactoros\Response;
|
||||||
@ -18,20 +18,12 @@ class ImplicitGrant extends AbstractAuthorizeGrant
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param \League\OAuth2\Server\Repositories\UserRepositoryInterface $userRepository
|
* @param \League\OAuth2\Server\Repositories\UserRepositoryInterface $userRepository
|
||||||
* @param string|null $loginTemplate
|
* @param \League\OAuth2\Server\TemplateRenderer\AbstractRenderer|null $templateRenderer
|
||||||
* @param string|null $authorizeTemplate
|
|
||||||
* @param \League\OAuth2\Server\TemplateRenderer\RendererInterface|null $templateRenderer
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(UserRepositoryInterface $userRepository, AbstractRenderer $templateRenderer = null)
|
||||||
UserRepositoryInterface $userRepository,
|
{
|
||||||
$loginTemplate = null,
|
|
||||||
$authorizeTemplate = null,
|
|
||||||
RendererInterface $templateRenderer = null
|
|
||||||
) {
|
|
||||||
$this->setUserRepository($userRepository);
|
$this->setUserRepository($userRepository);
|
||||||
$this->refreshTokenTTL = new \DateInterval('P1M');
|
$this->refreshTokenTTL = new \DateInterval('P1M');
|
||||||
$this->loginTemplate = $loginTemplate;
|
|
||||||
$this->authorizeTemplate = $authorizeTemplate;
|
|
||||||
$this->templateRenderer = $templateRenderer;
|
$this->templateRenderer = $templateRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +136,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant
|
|||||||
|
|
||||||
// The user hasn't logged in yet so show a login form
|
// The user hasn't logged in yet so show a login form
|
||||||
if ($userId === null) {
|
if ($userId === null) {
|
||||||
$html = $this->renderLoginTemplate([
|
$html = $this->getTemplateRenderer()->renderLogin([
|
||||||
'error' => $loginError,
|
'error' => $loginError,
|
||||||
'postback_uri' => (string) $postbackUri->withQuery($queryString),
|
'postback_uri' => (string) $postbackUri->withQuery($queryString),
|
||||||
]);
|
]);
|
||||||
@ -154,7 +146,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant
|
|||||||
|
|
||||||
// The user hasn't approved the client yet so show an authorize form
|
// The user hasn't approved the client yet so show an authorize form
|
||||||
if ($userId !== null && $userHasApprovedClient === null) {
|
if ($userId !== null && $userHasApprovedClient === null) {
|
||||||
$html = $this->renderAuthorizeTemplate([
|
$html = $this->getTemplateRenderer()->renderAuthorize([
|
||||||
'client' => $client,
|
'client' => $client,
|
||||||
'scopes' => $scopes,
|
'scopes' => $scopes,
|
||||||
'postback_uri' => (string) $postbackUri->withQuery($queryString),
|
'postback_uri' => (string) $postbackUri->withQuery($queryString),
|
||||||
|
70
src/TemplateRenderer/AbstractRenderer.php
Normal file
70
src/TemplateRenderer/AbstractRenderer.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Base template renderer.
|
||||||
|
*
|
||||||
|
* @author Julián Gutiérrez <juliangut@gmail.com>
|
||||||
|
* @copyright Copyright (c) Alex Bilbie
|
||||||
|
* @license http://mit-license.org/
|
||||||
|
*
|
||||||
|
* @link https://github.com/thephpleague/oauth2-server
|
||||||
|
*/
|
||||||
|
namespace League\OAuth2\Server\TemplateRenderer;
|
||||||
|
|
||||||
|
abstract class AbstractRenderer
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $loginTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $authorizeTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PlatesRenderer constructor.
|
||||||
|
*
|
||||||
|
* @param string $loginTemplate
|
||||||
|
* @param string $authorizeTemplate
|
||||||
|
*/
|
||||||
|
public function __construct($loginTemplate, $authorizeTemplate)
|
||||||
|
{
|
||||||
|
$this->loginTemplate = $loginTemplate;
|
||||||
|
$this->authorizeTemplate = $authorizeTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render login template.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function renderLogin(array $data = [])
|
||||||
|
{
|
||||||
|
return $this->render($this->loginTemplate, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render authorize template.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function renderAuthorize(array $data = [])
|
||||||
|
{
|
||||||
|
return $this->render($this->authorizeTemplate, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render template.
|
||||||
|
*
|
||||||
|
* @param string $template
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
abstract protected function render($template, array $data = []);
|
||||||
|
}
|
@ -10,9 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
namespace League\OAuth2\Server\TemplateRenderer;
|
namespace League\OAuth2\Server\TemplateRenderer;
|
||||||
|
|
||||||
use Mustache_Engine;
|
class MustacheRenderer extends AbstractRenderer
|
||||||
|
|
||||||
class MustacheRenderer implements RendererInterface
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Mustache_Engine
|
* @var \Mustache_Engine
|
||||||
@ -20,12 +18,16 @@ class MustacheRenderer implements RendererInterface
|
|||||||
private $engine;
|
private $engine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TwigRenderer constructor.
|
* PlatesRenderer constructor.
|
||||||
*
|
*
|
||||||
* @param \Mustache_Engine $engine
|
* @param \Mustache_Engine $engine
|
||||||
|
* @param string $loginTemplate
|
||||||
|
* @param string $authorizeTemplate
|
||||||
*/
|
*/
|
||||||
public function __construct(Mustache_Engine $engine)
|
public function __construct(\Mustache_Engine $engine, $loginTemplate, $authorizeTemplate)
|
||||||
{
|
{
|
||||||
|
parent::__construct($loginTemplate, $authorizeTemplate);
|
||||||
|
|
||||||
$this->engine = $engine;
|
$this->engine = $engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ namespace League\OAuth2\Server\TemplateRenderer;
|
|||||||
|
|
||||||
use League\Plates\Engine;
|
use League\Plates\Engine;
|
||||||
|
|
||||||
class PlatesRenderer implements RendererInterface
|
class PlatesRenderer extends AbstractRenderer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \League\Plates\Engine
|
* @var \League\Plates\Engine
|
||||||
@ -23,16 +23,20 @@ class PlatesRenderer implements RendererInterface
|
|||||||
* PlatesRenderer constructor.
|
* PlatesRenderer constructor.
|
||||||
*
|
*
|
||||||
* @param \League\Plates\Engine $engine
|
* @param \League\Plates\Engine $engine
|
||||||
|
* @param string $loginTemplate
|
||||||
|
* @param string $authorizeTemplate
|
||||||
*/
|
*/
|
||||||
public function __construct(Engine $engine)
|
public function __construct(Engine $engine, $loginTemplate, $authorizeTemplate)
|
||||||
{
|
{
|
||||||
|
parent::__construct($loginTemplate, $authorizeTemplate);
|
||||||
|
|
||||||
$this->engine = $engine;
|
$this->engine = $engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function render($template, array $data = [])
|
protected function render($template, array $data = [])
|
||||||
{
|
{
|
||||||
if ($this->engine->getFileExtension()) {
|
if ($this->engine->getFileExtension()) {
|
||||||
$template = preg_replace(sprintf('/\.%s$/', $this->engine->getFileExtension()), '', $template);
|
$template = preg_replace(sprintf('/\.%s$/', $this->engine->getFileExtension()), '', $template);
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Template renderer Interface.
|
|
||||||
*
|
|
||||||
* @author Julián Gutiérrez <juliangut@gmail.com>
|
|
||||||
* @copyright Copyright (c) Alex Bilbie
|
|
||||||
* @license http://mit-license.org/
|
|
||||||
*
|
|
||||||
* @link https://github.com/thephpleague/oauth2-server
|
|
||||||
*/
|
|
||||||
namespace League\OAuth2\Server\TemplateRenderer;
|
|
||||||
|
|
||||||
interface RendererInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param string $template
|
|
||||||
* @param array $data
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function render($template, array $data = []);
|
|
||||||
}
|
|
@ -10,9 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
namespace League\OAuth2\Server\TemplateRenderer;
|
namespace League\OAuth2\Server\TemplateRenderer;
|
||||||
|
|
||||||
use Smarty;
|
class SmartyRenderer extends AbstractRenderer
|
||||||
|
|
||||||
class SmartyRenderer implements RendererInterface
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Smarty class.
|
* Smarty class.
|
||||||
@ -22,17 +20,23 @@ class SmartyRenderer implements RendererInterface
|
|||||||
private $smarty;
|
private $smarty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* PlatesRenderer constructor.
|
||||||
|
*
|
||||||
* @param \Smarty $smarty
|
* @param \Smarty $smarty
|
||||||
|
* @param string $loginTemplate
|
||||||
|
* @param string $authorizeTemplate
|
||||||
*/
|
*/
|
||||||
public function __construct(Smarty $smarty)
|
public function __construct(\Smarty $smarty, $loginTemplate, $authorizeTemplate)
|
||||||
{
|
{
|
||||||
|
parent::__construct($loginTemplate, $authorizeTemplate);
|
||||||
|
|
||||||
$this->smarty = $smarty;
|
$this->smarty = $smarty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function render($template, array $data = [])
|
protected function render($template, array $data = [])
|
||||||
{
|
{
|
||||||
$this->smarty->assign($data);
|
$this->smarty->assign($data);
|
||||||
|
|
||||||
|
@ -10,9 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
namespace League\OAuth2\Server\TemplateRenderer;
|
namespace League\OAuth2\Server\TemplateRenderer;
|
||||||
|
|
||||||
use Twig_Environment;
|
class TwigRenderer extends AbstractRenderer
|
||||||
|
|
||||||
class TwigRenderer implements RendererInterface
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Twig_Environment
|
* @var \Twig_Environment
|
||||||
@ -20,19 +18,23 @@ class TwigRenderer implements RendererInterface
|
|||||||
private $environment;
|
private $environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TwigRenderer constructor.
|
* PlatesRenderer constructor.
|
||||||
*
|
*
|
||||||
* @param \Twig_Environment $environment
|
* @param \Twig_Environment $environment
|
||||||
|
* @param string $loginTemplate
|
||||||
|
* @param string $authorizeTemplate
|
||||||
*/
|
*/
|
||||||
public function __construct(Twig_Environment $environment)
|
public function __construct(\Twig_Environment $environment, $loginTemplate, $authorizeTemplate)
|
||||||
{
|
{
|
||||||
|
parent::__construct($loginTemplate, $authorizeTemplate);
|
||||||
|
|
||||||
$this->environment = $environment;
|
$this->environment = $environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function render($template, array $data = [])
|
protected function render($template, array $data = [])
|
||||||
{
|
{
|
||||||
return $this->environment->loadTemplate($template)->render($data);
|
return $this->environment->loadTemplate($template)->render($data);
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->getMock(AuthCodeRepositoryInterface::class),
|
$this->getMock(AuthCodeRepositoryInterface::class),
|
||||||
$this->getMock(RefreshTokenRepositoryInterface::class),
|
$this->getMock(RefreshTokenRepositoryInterface::class),
|
||||||
$this->getMock(UserRepositoryInterface::class),
|
$this->getMock(UserRepositoryInterface::class),
|
||||||
new \DateInterval('PT10M'),
|
new \DateInterval('PT10M')
|
||||||
'foo/bar.php',
|
|
||||||
'foo/bar.php'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals('authorization_code', $grant->getIdentifier());
|
$this->assertEquals('authorization_code', $grant->getIdentifier());
|
||||||
@ -77,9 +75,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->getMock(AuthCodeRepositoryInterface::class),
|
$this->getMock(AuthCodeRepositoryInterface::class),
|
||||||
$this->getMock(RefreshTokenRepositoryInterface::class),
|
$this->getMock(RefreshTokenRepositoryInterface::class),
|
||||||
$userRepositoryMock,
|
$userRepositoryMock,
|
||||||
new \DateInterval('PT10M'),
|
new \DateInterval('PT10M')
|
||||||
'',
|
|
||||||
''
|
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
||||||
@ -134,9 +130,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->getMock(AuthCodeRepositoryInterface::class),
|
$this->getMock(AuthCodeRepositoryInterface::class),
|
||||||
$this->getMock(RefreshTokenRepositoryInterface::class),
|
$this->getMock(RefreshTokenRepositoryInterface::class),
|
||||||
$userRepositoryMock,
|
$userRepositoryMock,
|
||||||
new \DateInterval('PT10M'),
|
new \DateInterval('PT10M')
|
||||||
'',
|
|
||||||
''
|
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
||||||
@ -196,9 +190,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->getMock(AuthCodeRepositoryInterface::class),
|
$this->getMock(AuthCodeRepositoryInterface::class),
|
||||||
$this->getMock(RefreshTokenRepositoryInterface::class),
|
$this->getMock(RefreshTokenRepositoryInterface::class),
|
||||||
$userRepositoryMock,
|
$userRepositoryMock,
|
||||||
new \DateInterval('PT10M'),
|
new \DateInterval('PT10M')
|
||||||
'',
|
|
||||||
''
|
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
||||||
@ -365,9 +357,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->getMock(AuthCodeRepositoryInterface::class),
|
$this->getMock(AuthCodeRepositoryInterface::class),
|
||||||
$this->getMock(RefreshTokenRepositoryInterface::class),
|
$this->getMock(RefreshTokenRepositoryInterface::class),
|
||||||
$userRepositoryMock,
|
$userRepositoryMock,
|
||||||
new \DateInterval('PT10M'),
|
new \DateInterval('PT10M')
|
||||||
'',
|
|
||||||
''
|
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
||||||
@ -417,9 +407,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->getMock(AuthCodeRepositoryInterface::class),
|
$this->getMock(AuthCodeRepositoryInterface::class),
|
||||||
$this->getMock(RefreshTokenRepositoryInterface::class),
|
$this->getMock(RefreshTokenRepositoryInterface::class),
|
||||||
$userRepositoryMock,
|
$userRepositoryMock,
|
||||||
new \DateInterval('PT10M'),
|
new \DateInterval('PT10M')
|
||||||
'',
|
|
||||||
''
|
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
||||||
|
@ -18,22 +18,14 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
public function testGetIdentifier()
|
public function testGetIdentifier()
|
||||||
{
|
{
|
||||||
$grant = new ImplicitGrant(
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
$this->getMock(UserRepositoryInterface::class),
|
|
||||||
'foo/bar.php',
|
|
||||||
'foo/bar.php'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals('implicit', $grant->getIdentifier());
|
$this->assertEquals('implicit', $grant->getIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanRespondToRequest()
|
public function testCanRespondToRequest()
|
||||||
{
|
{
|
||||||
$grant = new ImplicitGrant(
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
$this->getMock(UserRepositoryInterface::class),
|
|
||||||
'foo/bar.php',
|
|
||||||
'foo/bar.php'
|
|
||||||
);
|
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[],
|
[],
|
||||||
@ -65,7 +57,7 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
|
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
|
||||||
$accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf();
|
$accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf();
|
||||||
|
|
||||||
$grant = new ImplicitGrant($userRepositoryMock, 'foo', 'foo');
|
$grant = new ImplicitGrant($userRepositoryMock);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
||||||
@ -106,11 +98,7 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRespondToAuthorizationRequestMissingClientId()
|
public function testRespondToAuthorizationRequestMissingClientId()
|
||||||
{
|
{
|
||||||
$grant = new ImplicitGrant(
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
$this->getMock(UserRepositoryInterface::class),
|
|
||||||
'foo/bar.php',
|
|
||||||
'foo/bar.php'
|
|
||||||
);
|
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
||||||
|
|
||||||
@ -151,11 +139,7 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
||||||
$clientRepositoryMock->method('getClientEntity')->willReturn($client);
|
$clientRepositoryMock->method('getClientEntity')->willReturn($client);
|
||||||
|
|
||||||
$grant = new ImplicitGrant(
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
$this->getMock(UserRepositoryInterface::class),
|
|
||||||
'foo/bar.php',
|
|
||||||
'foo/bar.php'
|
|
||||||
);
|
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
||||||
@ -205,11 +189,7 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$userEntity = new UserEntity();
|
$userEntity = new UserEntity();
|
||||||
$userRepositoryMock->method('getUserEntityByUserCredentials')->willReturn($userEntity);
|
$userRepositoryMock->method('getUserEntityByUserCredentials')->willReturn($userEntity);
|
||||||
|
|
||||||
$grant = new ImplicitGrant(
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
$this->getMock(UserRepositoryInterface::class),
|
|
||||||
'foo/bar.php',
|
|
||||||
'foo/bar.php'
|
|
||||||
);
|
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
||||||
@ -265,11 +245,7 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$userEntity = new UserEntity();
|
$userEntity = new UserEntity();
|
||||||
$userRepositoryMock->method('getUserEntityByUserCredentials')->willReturn($userEntity);
|
$userRepositoryMock->method('getUserEntityByUserCredentials')->willReturn($userEntity);
|
||||||
|
|
||||||
$grant = new ImplicitGrant(
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
$this->getMock(UserRepositoryInterface::class),
|
|
||||||
'foo/bar.php',
|
|
||||||
'foo/bar.php'
|
|
||||||
);
|
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
||||||
|
Loading…
Reference in New Issue
Block a user