- WIP on adding of HttpFactory and work on authorization from Ulmus/User too
This commit is contained in:
1 parent
1241e188e9
commit
16cd95abe2
9 files changed
+47
-55
No files matched your search
@@ -1,17 +1,46 @@
|
||||
<?php
|
||||
|
||||
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};
|
||||
|
||||
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) {
|
||||
return HttpFactory::createJsonResponse([
|
||||
'api.error' => "Authorization failed",
|
||||
'api.datetime' => ( new \DateTime )->format(\DateTime::ATOM),
|
||||
]);
|
||||
return function(array $errorData) {
|
||||
return HttpFactory::createJsonResponse($errorData + [
|
||||
'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,
|
||||
]));
|
||||
};
|
||||
},
|
||||
];
|
||||
Reference in new issue
Block a user