mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-20 14:36:52 +00:00
Initial import
This commit is contained in:
commit
2295a33590
884 changed files with 93939 additions and 0 deletions
41
php/src/Middleware/AuthMiddleware.php
Normal file
41
php/src/Middleware/AuthMiddleware.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace AIO\Middleware;
|
||||
|
||||
use AIO\Auth\AuthManager;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
|
||||
class AuthMiddleware
|
||||
{
|
||||
private AuthManager $authManager;
|
||||
|
||||
public function __construct(AuthManager $authManager) {
|
||||
$this->authManager = $authManager;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
$publicRoutes = [
|
||||
'/api/auth/login',
|
||||
'/api/auth/getlogin',
|
||||
'/login',
|
||||
'/setup',
|
||||
'/',
|
||||
];
|
||||
|
||||
if(!in_array($request->getUri()->getPath(), $publicRoutes)) {
|
||||
if(!$this->authManager->IsAuthenticated()) {
|
||||
$response = new Response();
|
||||
return $response
|
||||
->withHeader('Location', '/')
|
||||
->withStatus(302);
|
||||
}
|
||||
}
|
||||
|
||||
$response = $handler->handle($request);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue