Skip to content

Commit

Permalink
Merge pull request #4 from dotkernel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
n3vrax authored Mar 15, 2017
2 parents c1420b0 + 13a8b7f commit 6bc006f
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 152 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## 0.2.0 - 2017-03-15

Updating package to support ZE2 and other DotKernel dependencies updates

### Changed
* Updated factories to typehint against PSR11 container
* UnauthorizedHandler changed to a valid ZE2 error handler

### Added
* Middleware now implement PSR15 MiddlewareInterface

### Deprecated
* Nothing

### Removed
* Nothing

### Fixed
* Nothing


## 0.1.1 - 2017-03-10

### Added
Expand Down
26 changes: 21 additions & 5 deletions authentication-web.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,33 @@ return [
'dot_authentication' => [
//this package's specific configuration template
'web' => [
//change next two only if you changed the default login/logout routes
'login_route' => ['route_name' => 'login', 'route_params' => [], 'query_params' => []],
'logout_route' => ['route_name' => 'logout', 'route_params' => []],
'login_route' => [
'route_name' => 'login',
'route_params' => [],
'query_params' => [],
'fragment_id' => null,
'options' => []
],

'logout_route' => [
'route_name' => 'logout',
'route_params' => [],
//...
],

//template name to use for the login form
'login_template' => 'app::login',

//where to redirect after login success
'after_login_route' => ['route_name' => 'my-account', 'route_params' => []],
'after_login_route' => [
'route_name' => 'home',
'route_params' => []
],
//where to redirect after logging out
'after_logout_route' => ['route_name' => 'login', 'route_params' => []],
'after_logout_route' => [
'route_name' => 'login',
'route_params' => []
],

//enable the wanted url feature, to login to the previously requested uri after login
'enable_wanted_url' => true,
Expand Down
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@
"require": {
"php": "^7.1",
"psr/http-message": "^1.0",
"container-interop/container-interop": "^1.1",
"http-interop/http-middleware": "^0.4.1",
"zendframework/zend-servicemanager": "^3.3.0",

"dotkernel/dot-authentication": "^0.1",
"dotkernel/dot-event": "^0.1",
"dotkernel/dot-helpers": "^0.1",
"dotkernel/dot-flashmessenger": "^0.1"
"dotkernel/dot-event": "^0.2",
"dotkernel/dot-helpers": "^0.2",
"dotkernel/dot-flashmessenger": "^0.2"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
"squizlabs/php_codesniffer": "^2.3",

"zendframework/zend-stdlib": "^3.1",
"zendframework/zend-diactoros": "^1.3",
"zendframework/zend-expressive-template": "^1.0"
"zendframework/zend-expressive-template": "^1.0",
"zendframework/zend-expressive": "^2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -39,7 +41,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "0.2-dev"
"dev-master": "0.2-dev",
"dev-develop": "0.3-dev"
}
}
}
26 changes: 12 additions & 14 deletions src/Action/LoginAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
use Dot\Authentication\Web\Options\WebAuthenticationOptions;
use Dot\Authentication\Web\Utils;
use Dot\FlashMessenger\FlashMessengerInterface;
use Dot\Helpers\Route\RouteOptionHelper;
use Dot\Helpers\Route\RouteHelper;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\HtmlResponse;
Expand All @@ -32,15 +34,15 @@
* Class LoginAction
* @package Dot\Authentication\Web\Action
*/
class LoginAction implements AuthenticationEventListenerInterface
class LoginAction implements MiddlewareInterface, AuthenticationEventListenerInterface
{
use DispatchAuthenticationEventTrait;
use AuthenticationEventListenerTrait;

/** @var AuthenticationInterface */
protected $authentication;

/** @var RouteOptionHelper */
/** @var RouteHelper */
protected $routeHelper;

/** @var WebAuthenticationOptions */
Expand All @@ -62,14 +64,14 @@ class LoginAction implements AuthenticationEventListenerInterface
* LoginAction constructor.
* @param AuthenticationInterface $authentication
* @param TemplateRendererInterface $template
* @param RouteOptionHelper $routeHelper
* @param RouteHelper $routeHelper
* @param WebAuthenticationOptions $options
* @param FlashMessengerInterface $flashMessenger
*/
public function __construct(
AuthenticationInterface $authentication,
TemplateRendererInterface $template,
RouteOptionHelper $routeHelper,
RouteHelper $routeHelper,
WebAuthenticationOptions $options,
FlashMessengerInterface $flashMessenger
) {
Expand All @@ -82,17 +84,13 @@ public function __construct(

/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable|null $next
* @param DelegateInterface $delegate
* @return ResponseInterface
*/
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next = null
): ResponseInterface {
public function process(ServerRequestInterface $request, DelegateInterface $delegate): ResponseInterface
{
if ($this->authentication->hasIdentity()) {
return new RedirectResponse($this->routeHelper->getUri($this->options->getAfterLoginRoute()));
return new RedirectResponse($this->routeHelper->generateUri($this->options->getAfterLoginRoute()));
}

$this->request = $request;
Expand Down Expand Up @@ -142,7 +140,7 @@ public function __invoke(
if (empty($error)) {
$this->dispatchEvent(AuthenticationEvent::EVENT_AUTHENTICATION_SUCCESS, $params);

$uri = $this->routeHelper->getUri($this->options->getAfterLoginRoute());
$uri = $this->routeHelper->generateUri($this->options->getAfterLoginRoute());
if ($this->options->isEnableWantedUrl()) {
$params = $request->getQueryParams();
$wantedUrlName = $this->options->getWantedUrlName();
Expand Down
28 changes: 13 additions & 15 deletions src/Action/LogoutAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
use Dot\Authentication\Web\Event\AuthenticationEventListenerTrait;
use Dot\Authentication\Web\Event\DispatchAuthenticationEventTrait;
use Dot\Authentication\Web\Options\WebAuthenticationOptions;
use Dot\Helpers\Route\RouteOptionHelper;
use Dot\Helpers\Route\RouteHelper;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\RedirectResponse;
Expand All @@ -24,15 +26,15 @@
* Class LogoutAction
* @package Dot\Authentication\Web\Action
*/
class LogoutAction implements AuthenticationEventListenerInterface
class LogoutAction implements MiddlewareInterface, AuthenticationEventListenerInterface
{
use AuthenticationEventListenerTrait;
use DispatchAuthenticationEventTrait;

/** @var AuthenticationInterface */
protected $authentication;

/** @var RouteOptionHelper */
/** @var RouteHelper */
protected $routeHelper;

/** @var WebAuthenticationOptions */
Expand All @@ -41,12 +43,12 @@ class LogoutAction implements AuthenticationEventListenerInterface
/**
* LogoutActionFactory constructor.
* @param AuthenticationInterface $authentication
* @param RouteOptionHelper $routeHelper
* @param RouteHelper $routeHelper
* @param WebAuthenticationOptions $options
*/
public function __construct(
AuthenticationInterface $authentication,
RouteOptionHelper $routeHelper,
RouteHelper $routeHelper,
WebAuthenticationOptions $options
) {
$this->authentication = $authentication;
Expand All @@ -56,17 +58,13 @@ public function __construct(

/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable|null $next
* @return RedirectResponse|ResponseInterface
* @param DelegateInterface $delegate
* @return ResponseInterface
*/
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next = null
): ResponseInterface {
public function process(ServerRequestInterface $request, DelegateInterface $delegate): ResponseInterface
{
if (!$this->authentication->hasIdentity()) {
return new RedirectResponse($this->routeHelper->getUri($this->options->getAfterLogoutRoute()));
return new RedirectResponse($this->routeHelper->generateUri($this->options->getAfterLogoutRoute()));
}
$event = $this->dispatchEvent(AuthenticationEvent::EVENT_BEFORE_LOGOUT, [
'request' => $request,
Expand All @@ -83,7 +81,7 @@ public function __invoke(
'authenticationService' => $this->authentication
]);

$uri = $this->routeHelper->getUri($this->options->getAfterLogoutRoute());
$uri = $this->routeHelper->generateUri($this->options->getAfterLogoutRoute());
return new RedirectResponse($uri);
}
}
37 changes: 1 addition & 36 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,8 @@ public function __invoke(): array
return [
'dependencies' => $this->getDependenciesConfig(),

'middleware_pipeline' => [
'error' => [
'middleware' => [
UnauthorizedHandler::class,
],
'error' => true,
'priority' => -10000,
],
],

//default routes
'routes' => [
'login_route' => [
'name' => 'login',
'path' => '/login',
'middleware' => LoginAction::class,
'allowed_methods' => ['GET', 'POST']
],
'logout_route' => [
'name' => 'logout',
'path' => '/logout',
'middleware' => LogoutAction::class,
'allowed_methods' => ['GET']
],
],

'dot_authentication' => [
'web' => [
'event_listeners' => [],

'login_route' => ['route_name' => 'login'],
'logout_route' => ['route_name' => 'logout'],

'messages_options' => [
'messages' => [],
],
]
'web' => []
]
];
}
Expand Down
Loading

0 comments on commit 6bc006f

Please sign in to comment.