Dav: implements JWT extraction from the URL, and add the access_token in dav urls

This commit is contained in:
2023-09-14 21:54:30 +02:00
parent 482c494034
commit ff05f9f48a
10 changed files with 193 additions and 39 deletions

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocStoreBundle\Security\Guard;
use Lexik\Bundle\JWTAuthenticationBundle\TokenExtractor\TokenExtractorInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
final readonly class DavOnUrlTokenExtractor implements TokenExtractorInterface
{
public function __construct(
private LoggerInterface $logger,
) {}
public function extract(Request $request): string|false
{
$uri = $request->getRequestUri();
$segments = array_values(
array_filter(
explode('/', $uri),
fn ($item) => '' !== trim($item)
)
);
if (2 > count($segments)) {
$this->logger->info("not enough segment for parsing URL");
return false;
}
if ('dav' !== $segments[0]) {
$this->logger->info("the first segment of the url must be DAV");
return false;
}
return $segments[1];
}
}