mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Dav: implements JWT extraction from the URL, and add the access_token in dav urls
This commit is contained in:
@@ -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];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user