add autodeploy and add basic auth for file uploader
Some checks failed
Deploy back2 / deploy (push) Failing after 46s

This commit is contained in:
2026-04-02 19:42:04 +03:00
parent ad4a3367c3
commit b36cf07635
10 changed files with 244 additions and 56 deletions

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class EnsureFileUploadBasicAuth
{
public function handle(Request $request, Closure $next): Response
{
$authorizedUsers = config('file_links.upload_basic_auth_users', []);
$username = (string) $request->getUser();
$password = (string) $request->getPassword();
foreach ($authorizedUsers as $authorizedUser) {
$validUsername = isset($authorizedUser['username']) && hash_equals((string) $authorizedUser['username'], $username);
$validPassword = isset($authorizedUser['password']) && hash_equals((string) $authorizedUser['password'], $password);
if ($validUsername && $validPassword) {
return $next($request);
}
}
return $this->unauthorizedResponse($request);
}
private function unauthorizedResponse(Request $request): Response
{
if ($request->expectsJson()) {
return new JsonResponse(['message' => 'Unauthorized'], Response::HTTP_UNAUTHORIZED, [
'WWW-Authenticate' => 'Basic realm="File Upload"',
]);
}
return response('Unauthorized', Response::HTTP_UNAUTHORIZED, [
'WWW-Authenticate' => 'Basic realm="File Upload"',
]);
}
}