58 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| use Lean\Factory\HttpFactoryInterface;
 | |
| 
 | |
| use Ulmus\User\{
 | |
|     Authorize\HeaderAuthentication,
 | |
|     Entity,
 | |
|     Lib\Authenticate,
 | |
|     Lib\Authorize,
 | |
|     Middleware\AuthenticationMiddleware,
 | |
|     Middleware\HeaderAuthenticationMiddleware,
 | |
|     Middleware\PostRequestAuthenticationMiddleware,
 | |
|     Authorize\PostRequestAuthentication
 | |
| };
 | |
| 
 | |
| use Storage\{ Cookie, Session };
 | |
| use Psr\Container\ContainerInterface;
 | |
| use Picea\Picea;
 | |
| 
 | |
| use function DI\{get, autowire, create};
 | |
| 
 | |
| return [
 | |
|     Authorize::class => create(Authorize::class)->constructor(get(Entity\UserInterface::class), get(Session::class), get(Cookie::class), get('authentication.method')),
 | |
| 
 | |
|     Authenticate::class => create(Authenticate::class)->constructor(get(Entity\UserInterface::class), get(Session::class), get(Cookie::class), get('authentication.method')),
 | |
| 
 | |
|     AuthenticationMiddleware::class => create(AuthenticationMiddleware::class)->constructor(get(Authorize::class), get('authorize.error')),
 | |
| 
 | |
|     HeaderAuthentication::class => autowire(HeaderAuthentication::class),
 | |
| 
 | |
|     HeaderAuthenticationMiddleware::class => create(HeaderAuthenticationMiddleware::class)->constructor(get(HeaderAuthentication::class)),
 | |
| 
 | |
|     PostRequestAuthentication::class => create(PostRequestAuthentication::class)->constructor("email", "email", "password"),
 | |
| 
 | |
|     PostRequestAuthenticationMiddleware::class => create(PostRequestAuthenticationMiddleware::class)->constructor(get(PostRequestAuthentication::class)),
 | |
| 
 | |
|     'authentication.method' => null,
 | |
| 
 | |
|     'authorize.error' => function(ContainerInterface $c) {
 | |
|         return function(array $errorData) use ($c) {
 | |
|             return $c->get(HttpFactoryInterface::class)::createJsonResponse($errorData + [
 | |
| 
 | |
|                 'api.error' => "Authorization failed",
 | |
|                 'api.datetime' => (new \DateTime)->format(\DateTime::ATOM),
 | |
|             ], 403);
 | |
|         };
 | |
|     },
 | |
| 
 | |
|     'authentication.error' => function($c, Picea $picea) {
 | |
|         return function($message) use ($c, $picea) {
 | |
|             return $c->get(HttpFactoryInterface::class)::createHtmlResponse($picea->renderHtml('lean/error/500', [
 | |
|                 'title' => "Authentication failed",
 | |
|                 'subtitle' => "",
 | |
|                 'message' => $message,
 | |
|             ]), 401);
 | |
|         };
 | |
|     },
 | |
| ]; |