- WIP on adding of HttpFactory and work on authorization from Ulmus/User too
This commit is contained in:
parent
1241e188e9
commit
16cd95abe2
|
@ -1,17 +1,46 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Lean\Factory\HttpFactory;
|
use Lean\Factory\HttpFactory;
|
||||||
use \Ulmus\User\Middleware\AuthorizeMiddleware;
|
|
||||||
|
use Ulmus\User\{Entity,
|
||||||
|
Lib\Authenticate,
|
||||||
|
Middleware\HeaderAuthenticationMiddleware,
|
||||||
|
Middleware\PostRequestAuthenticationMiddleware,
|
||||||
|
Authorize\PostRequestAuthentication};
|
||||||
|
|
||||||
|
use Picea\Picea;
|
||||||
|
|
||||||
|
use Storage\{ Cookie, Session };
|
||||||
|
|
||||||
use function DI\{get, autowire, create};
|
use function DI\{get, autowire, create};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
AuthorizeMiddleware::class => create(AuthorizeMiddleware::class)->constructor(get('authorize.error')),
|
Authenticate::class => create(Authenticate::class)->constructor(get(Session::class), get(Cookie::class), get('authentication.method')),
|
||||||
|
|
||||||
|
HeaderAuthenticationMiddleware::class => create(HeaderAuthenticationMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authorize.error')),
|
||||||
|
|
||||||
|
PostRequestAuthentication::class => create(PostRequestAuthentication::class)->constructor(get(\Ulmus\User\Lib\Authenticate::class), "email", "email", "password"),
|
||||||
|
|
||||||
|
PostRequestAuthenticationMiddleware::class => create(PostRequestAuthenticationMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authentication.error'), get(PostRequestAuthentication::class)),
|
||||||
|
|
||||||
|
'authentication.method' => null,
|
||||||
|
|
||||||
'authorize.error' => function($c) {
|
'authorize.error' => function($c) {
|
||||||
return HttpFactory::createJsonResponse([
|
return function(array $errorData) {
|
||||||
'api.error' => "Authorization failed",
|
return HttpFactory::createJsonResponse($errorData + [
|
||||||
'api.datetime' => ( new \DateTime )->format(\DateTime::ATOM),
|
'api.error' => "Authorization failed",
|
||||||
]);
|
'api.datetime' => (new \DateTime)->format(\DateTime::ATOM),
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
'authentication.error' => function($c, Picea $picea) {
|
||||||
|
return function($message) use ($picea) {
|
||||||
|
return HttpFactory::createHtmlResponse($picea->renderHtml('lean/error/500', [
|
||||||
|
'title' => "Authentication failed",
|
||||||
|
'subtitle' => "",
|
||||||
|
'message' => $message,
|
||||||
|
]));
|
||||||
|
};
|
||||||
},
|
},
|
||||||
];
|
];
|
|
@ -8,7 +8,7 @@ use Mcnd\CLI\CliMiddleware;
|
||||||
|
|
||||||
use Notes\CLI\CommandFetcher;
|
use Notes\CLI\CommandFetcher;
|
||||||
|
|
||||||
use Lean\Lean;
|
use Lean\{ Factory, Lean };
|
||||||
|
|
||||||
return [
|
return [
|
||||||
CommandFetcher::class => function($c) {
|
CommandFetcher::class => function($c) {
|
||||||
|
@ -27,7 +27,7 @@ return [
|
||||||
|
|
||||||
'cli.response:default' => function($c) {
|
'cli.response:default' => function($c) {
|
||||||
return function() {
|
return function() {
|
||||||
return new \Laminas\Diactoros\Response\TextResponse("This is the default response from CLI middleware which indicates that no command were registered for this application.\n");
|
return Factory\HttpFactory::createTextResponse("This is the default response from CLI middleware which indicates that no command were registered for this application.\n");
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -2,19 +2,17 @@
|
||||||
|
|
||||||
use function DI\autowire, DI\create, DI\get;
|
use function DI\autowire, DI\create, DI\get;
|
||||||
|
|
||||||
use Laminas\Diactoros\Response\HtmlResponse;
|
|
||||||
|
|
||||||
use Cronard\CronardMiddleware,
|
use Cronard\CronardMiddleware,
|
||||||
Notes\Cronard\TaskFetcher;
|
Notes\Cronard\TaskFetcher;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
use Lean\Lean;
|
use Lean\{ Factory, Lean };
|
||||||
|
|
||||||
return [
|
return [
|
||||||
CronardMiddleware::class => function($c) {
|
CronardMiddleware::class => function($c) {
|
||||||
$cronardMiddleware = new CronardMiddleware($c, getenv('CRON_KEY'), function() : ResponseInterface {
|
$cronardMiddleware = new CronardMiddleware($c, getenv('CRON_KEY'), function() : ResponseInterface {
|
||||||
return new HtmlResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s')));
|
return Factory\HttpFactory::createHtmlResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s')));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php")->fromAnnotations($c->get(TaskFetcher::class));
|
return $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php")->fromAnnotations($c->get(TaskFetcher::class));
|
||||||
|
|
|
@ -26,7 +26,7 @@ return [
|
||||||
Event\EventDefinition::class => function($c) {
|
Event\EventDefinition::class => function($c) {
|
||||||
return new Event\EventDefinition([
|
return new Event\EventDefinition([
|
||||||
new class() implements RoutingCompileRoutes {
|
new class() implements RoutingCompileRoutes {
|
||||||
public function execute(Routing $routing, Route|\Notes\Route\Annotation\Method\Route $attribute) : void
|
public function execute(Routing $routing, Route $attribute) : void
|
||||||
{
|
{
|
||||||
if (null !== ($name = $attribute->name ?? null)) {
|
if (null !== ($name = $attribute->name ?? null)) {
|
||||||
$routing->extension->registerRoute($name, $attribute->getRoute(), $attribute->class, $attribute->classMethod, $attribute->methods ?? (array)$attribute->method);
|
$routing->extension->registerRoute($name, $attribute->getRoute(), $attribute->class, $attribute->classMethod, $attribute->methods ?? (array)$attribute->method);
|
||||||
|
@ -35,7 +35,7 @@ return [
|
||||||
},
|
},
|
||||||
|
|
||||||
new class() implements RoutingMapRoutes {
|
new class() implements RoutingMapRoutes {
|
||||||
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route|\Notes\Route\Annotation\Method\Route $attribute) : void
|
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void
|
||||||
{
|
{
|
||||||
$class = $attribute->class;
|
$class = $attribute->class;
|
||||||
$method = $attribute->classMethod;
|
$method = $attribute->classMethod;
|
||||||
|
|
|
@ -3,29 +3,16 @@
|
||||||
use function DI\autowire, DI\create, DI\get;
|
use function DI\autowire, DI\create, DI\get;
|
||||||
|
|
||||||
use League\Route\Strategy\ApplicationStrategy,
|
use League\Route\Strategy\ApplicationStrategy,
|
||||||
League\Route\Http\Exception\NotFoundException,
|
|
||||||
League\Route\Router;
|
League\Route\Router;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseFactoryInterface,
|
use Psr\Container\ContainerInterface;
|
||||||
Psr\Container\ContainerInterface,
|
|
||||||
Psr\Http\Message\ResponseInterface,
|
|
||||||
Psr\Http\Message\ServerRequestInterface,
|
|
||||||
Psr\Http\Server\MiddlewareInterface,
|
|
||||||
Psr\Http\Server\RequestHandlerInterface,
|
|
||||||
Psr\SimpleCache\CacheInterface;
|
|
||||||
|
|
||||||
use TheBugs\JavascriptMiddleware;
|
|
||||||
|
|
||||||
use Cronard\CronardMiddleware;
|
use Cronard\CronardMiddleware;
|
||||||
|
|
||||||
use Tuupola\Middleware\HttpBasicAuthentication;
|
|
||||||
|
|
||||||
use Notes\Route\RouteFetcher;
|
use Notes\Route\RouteFetcher;
|
||||||
|
|
||||||
use Notes\Breadcrumb\Breadcrumb;
|
use Notes\Breadcrumb\Breadcrumb;
|
||||||
|
|
||||||
use Ulmus\User\Lib\Authenticate;
|
|
||||||
|
|
||||||
use Storage\SessionMiddleware;
|
use Storage\SessionMiddleware;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -2,18 +2,10 @@
|
||||||
|
|
||||||
use function DI\autowire, DI\create, DI\get;
|
use function DI\autowire, DI\create, DI\get;
|
||||||
|
|
||||||
use Laminas\Diactoros\Response\HtmlResponse;
|
|
||||||
|
|
||||||
use TheBugs\JavascriptMiddleware;
|
use TheBugs\JavascriptMiddleware;
|
||||||
|
|
||||||
|
|
||||||
use Cronard\CronardMiddleware,
|
|
||||||
Notes\Cronard\TaskFetcher;
|
|
||||||
|
|
||||||
use Lean\Lean;
|
use Lean\Lean;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
|
|
||||||
use Storage\Cookie,
|
use Storage\Cookie,
|
||||||
Storage\Session,
|
Storage\Session,
|
||||||
Storage\SessionMiddleware;
|
Storage\SessionMiddleware;
|
||||||
|
|
|
@ -22,29 +22,15 @@ use TheBugs\Email\{ EmailConfiguration, MailerInterface, SwiftMailer };
|
||||||
use Taxus\{ Taxus, PermissionGrantInterface };
|
use Taxus\{ Taxus, PermissionGrantInterface };
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Entity\User::class => autowire(Entity\User::class),
|
\Ulmus\User\Entity\UserInterface::class => autowire(Entity\User::class),
|
||||||
|
|
||||||
Authenticate::class => create(Authenticate::class)->constructor(get(Session::class), get(Cookie::class), get('authentication.method')),
|
|
||||||
|
|
||||||
SecurityHandler::class => create(SecurityHandler::class)->constructor(function() {
|
SecurityHandler::class => create(SecurityHandler::class)->constructor(function() {
|
||||||
return new RedirectResponse(getenv("URL_BASE")."/login");
|
return Lean\Factory\HttpFactory::createRedirectResponse(getenv("URL_BASE")."/login");
|
||||||
}, get('authentication.unauthorize'), get(Taxus::class)),
|
}, get('authentication.unauthorize'), get(Taxus::class)),
|
||||||
|
|
||||||
'authentication.method' => null,
|
|
||||||
|
|
||||||
'authentication.error' => function($c, Picea $picea) {
|
|
||||||
return function($message) use ($picea) {
|
|
||||||
return new HtmlResponse($picea->renderHtml('lean/error/500', [
|
|
||||||
'title' => "",
|
|
||||||
'subtitle' => "",
|
|
||||||
'message' => $message,
|
|
||||||
]));
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
'authentication.unauthorize' => function($c, Picea $picea) {
|
'authentication.unauthorize' => function($c, Picea $picea) {
|
||||||
return function($message) use ($picea) {
|
return function($message) use ($picea) {
|
||||||
return new HtmlResponse($picea->renderHtml('lean/error/401', [
|
return Lean\Factory\HttpFactory::createHtmlResponse($picea->renderHtml('lean/error/401', [
|
||||||
'title' => "",
|
'title' => "",
|
||||||
'subtitle' => "",
|
'subtitle' => "",
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
|
|
|
@ -6,5 +6,5 @@ use Lean\Routing;
|
||||||
use Notes\Route\Attribute\Method\Route;
|
use Notes\Route\Attribute\Method\Route;
|
||||||
|
|
||||||
interface RoutingCompileRoutes {
|
interface RoutingCompileRoutes {
|
||||||
public function execute(Routing $routing, Route|\Notes\Route\Annotation\Method\Route $attribute) : void;
|
public function execute(Routing $routing, Route $attribute) : void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,5 +8,5 @@ use Psr\Container\ContainerInterface;
|
||||||
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
||||||
|
|
||||||
interface RoutingMapRoutes {
|
interface RoutingMapRoutes {
|
||||||
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route|\Notes\Route\Annotation\Method\Route $attribute) : void;
|
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue