49 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| use Lean\Factory\HttpFactory;
 | |
| 
 | |
| use Ulmus\User\{Entity,
 | |
|     Lib\Authenticate,
 | |
|     Lib\Authorize,
 | |
|     Middleware\HeaderAuthenticationMiddleware,
 | |
|     Middleware\PostRequestAuthenticationMiddleware,
 | |
|     Authorize\PostRequestAuthentication};
 | |
| 
 | |
| use Picea\Picea;
 | |
| 
 | |
| use Storage\{ Cookie, Session };
 | |
| 
 | |
| use function DI\{get, autowire, create};
 | |
| 
 | |
| return [
 | |
|     Authenticate::class => create(Authenticate::class)->constructor(get(Entity\UserInterface::class), get(Session::class), get(Cookie::class), get('authentication.method')),
 | |
| 
 | |
|     Authorize::class => create(Authorize::class)->constructor(get(Entity\UserInterface::class), get(Session::class), get(Cookie::class), get('authentication.method')),
 | |
| 
 | |
|     HeaderAuthenticationMiddleware::class => create(HeaderAuthenticationMiddleware::class)->constructor(get(Authorize::class), get(Entity\UserInterface::class), get('authorize.error')),
 | |
| 
 | |
|     PostRequestAuthentication::class => create(PostRequestAuthentication::class)->constructor(get(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 function(array $errorData) {
 | |
|             return HttpFactory::createJsonResponse($errorData + [
 | |
|                 'api.error' => "Authorization failed",
 | |
|                 'api.datetime' => (new \DateTime)->format(\DateTime::ISO8601),
 | |
|             ], 403);
 | |
|         };
 | |
|     },
 | |
| 
 | |
|     '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,
 | |
|             ]), 401);
 | |
|         };
 | |
|     },
 | |
| ]; |