Compare commits
1 Commits
bugfix/upl
...
feature/oa
Author | SHA1 | Date | |
---|---|---|---|
3a841be03e
|
@ -7,8 +7,8 @@ xdebug_enabled: false
|
||||
additional_hostnames: []
|
||||
additional_fqdns: []
|
||||
database:
|
||||
type: postgres
|
||||
version: "17"
|
||||
type: mariadb
|
||||
version: "10.11"
|
||||
use_dns_when_possible: true
|
||||
composer_version: "2"
|
||||
web_environment: []
|
||||
|
@ -7,10 +7,10 @@ on:
|
||||
- main
|
||||
jobs:
|
||||
build:
|
||||
runs-on: remote
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: https://git.simonis.lol/actions/checkout@v4
|
||||
- uses: https://git.simonis.lol/actions/login@v1
|
||||
- uses: actions/checkout@v4
|
||||
- uses: docker/login-action@v1
|
||||
with:
|
||||
registry: git.simonis.lol
|
||||
username: ${{ vars.DOCKER_USER }}
|
||||
|
@ -7,6 +7,7 @@
|
||||
"php": ">=8.2",
|
||||
"ext-ctype": "*",
|
||||
"ext-iconv": "*",
|
||||
"knpuniversity/oauth2-client-bundle": "^2.18",
|
||||
"symfony/apache-pack": "^1.0",
|
||||
"symfony/asset-mapper": "^7.1",
|
||||
"symfony/console": "7.1.*",
|
||||
@ -15,16 +16,15 @@
|
||||
"symfony/flex": "^2",
|
||||
"symfony/form": "^7.1",
|
||||
"symfony/framework-bundle": "7.1.*",
|
||||
"symfony/mime": "7.1.*",
|
||||
"symfony/runtime": "7.1.*",
|
||||
"symfony/security-bundle": "7.1.*",
|
||||
"symfony/stimulus-bundle": "^2.22",
|
||||
"symfony/twig-bundle": "7.1.*",
|
||||
"symfony/ux-icons": "^2.22",
|
||||
"symfony/yaml": "7.1.*",
|
||||
"symfonycasts/tailwind-bundle": "^0.6.1",
|
||||
"twig/extra-bundle": "^2.12|^3.0",
|
||||
"twig/twig": "^2.12|^3.0",
|
||||
"ext-fileinfo": "*"
|
||||
"twig/twig": "^2.12|^3.0"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
|
1419
composer.lock
generated
1419
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -8,4 +8,6 @@ return [
|
||||
Symfonycasts\TailwindBundle\SymfonycastsTailwindBundle::class => ['all' => true],
|
||||
Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true],
|
||||
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
|
||||
KnpU\OAuth2ClientBundle\KnpUOAuth2ClientBundle::class => ['all' => true],
|
||||
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
|
||||
];
|
||||
|
10
config/packages/knpu_oauth2_client.yaml
Normal file
10
config/packages/knpu_oauth2_client.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
knpu_oauth2_client:
|
||||
clients:
|
||||
auth:
|
||||
type: generic
|
||||
provider_class: App\Service\Security\Provider
|
||||
|
||||
client_id: '%env(AUTHENTIK_CLIENT_ID)%'
|
||||
client_secret: '%env(AUTHENTIK_CLIENT_SECRET)%'
|
||||
redirect_route: auth_callback
|
||||
redirect_params: {}
|
45
config/packages/security.yaml
Normal file
45
config/packages/security.yaml
Normal file
@ -0,0 +1,45 @@
|
||||
security:
|
||||
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
|
||||
password_hashers:
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
|
||||
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
|
||||
providers:
|
||||
app_user_provider:
|
||||
entity:
|
||||
class: App\Entity\User
|
||||
property: email
|
||||
firewalls:
|
||||
dev:
|
||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||
security: false
|
||||
main:
|
||||
lazy: true
|
||||
provider: app_user_provider
|
||||
custom_authenticators:
|
||||
- App\Security\Authenticator
|
||||
|
||||
# activate different ways to authenticate
|
||||
# https://symfony.com/doc/current/security.html#the-firewall
|
||||
|
||||
# https://symfony.com/doc/current/security/impersonating_user.html
|
||||
# switch_user: true
|
||||
|
||||
# Easy way to control access for large sections of your site
|
||||
# Note: Only the *first* access control that matches will be used
|
||||
access_control:
|
||||
# - { path: ^/admin, roles: ROLE_ADMIN }
|
||||
# - { path: ^/profile, roles: ROLE_USER }
|
||||
- { path: /, roles: ROLE_USER }
|
||||
|
||||
when@test:
|
||||
security:
|
||||
password_hashers:
|
||||
# By default, password hashers are resource intensive and take time. This is
|
||||
# important to generate secure password hashes. In tests however, secure hashes
|
||||
# are not important, waste resources and increase test times. The following
|
||||
# reduces the work factor to the lowest possible values.
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
|
||||
algorithm: auto
|
||||
cost: 4 # Lowest possible value for bcrypt
|
||||
time_cost: 3 # Lowest possible value for argon
|
||||
memory_cost: 10 # Lowest possible value for argon
|
3
config/routes/security.yaml
Normal file
3
config/routes/security.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
_security_logout:
|
||||
resource: security.route_loader.logout
|
||||
type: service
|
19
src/Controller/AuthenticationController.php
Normal file
19
src/Controller/AuthenticationController.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class AuthenticationController extends AbstractController
|
||||
{
|
||||
#[Route(path: '/auth/callback', name: 'auth_callback', methods: Request::METHOD_GET)]
|
||||
public function __invoke(ClientRegistry $clientRegistry): Response
|
||||
{
|
||||
$clientRegistry->getClient('auth')->fetchUser();
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ class HomeController extends AbstractController
|
||||
|
||||
return $this->render('home.html.twig', [
|
||||
'content' => $fileSystemService->getDirs($dirs),
|
||||
'fileForm' => $this->createForm(UploadFileForm::class, data: ['dirs' => $dirs]),
|
||||
'fileForm' => $this->createForm(UploadFileForm::class),
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Service\FileSystemService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class ServeFileController extends AbstractController
|
||||
{
|
||||
public function __construct(private FileSystemService $fileSystemService)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route("/serve/{filePath}", name: "serve_file")]
|
||||
public function __invoke(string $filePath): BinaryFileResponse
|
||||
{
|
||||
$file = $this->fileSystemService->getFile($filePath);
|
||||
$path = $file->getPath() . '/' . $file->getName();
|
||||
|
||||
$response = new BinaryFileResponse($path);
|
||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $file->getName());
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
@ -13,24 +13,17 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class UploadController extends AbstractController
|
||||
{
|
||||
#[Route(
|
||||
path: '/upload/{dirs?}',
|
||||
name: 'app_upload',
|
||||
requirements: ['dirs' => '.+'],
|
||||
defaults: ['dirs' => ''],
|
||||
methods: Request::METHOD_POST,
|
||||
)]
|
||||
#[Route(path: '/upload', name: 'app_upload', methods: Request::METHOD_POST)]
|
||||
public function __invoke(
|
||||
FileSystemService $fileSystemService,
|
||||
Request $request,
|
||||
string $dirs,
|
||||
): Response
|
||||
{
|
||||
$fileData = new UploadedFileData(dir: $dirs);
|
||||
$fileData = new UploadedFileData();
|
||||
$form = $this->createForm(UploadFileForm::class, $fileData)->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$fileSystemService->uploadFile($fileData);
|
||||
$fileSystemService->uploadFile($fileData->files);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('app_home');
|
||||
|
21
src/Entity/User.php
Normal file
21
src/Entity/User.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
|
||||
|
||||
class User implements ResourceOwnerInterface
|
||||
{
|
||||
private int $id;
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return ['id' => $this->id];
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ class UploadFileForm extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->setAction($this->urlGenerator->generate('app_upload', ['dirs' => $options['data']['dirs']]))
|
||||
->setAction($this->urlGenerator->generate('app_upload'))
|
||||
->add('files', FileType::class, [
|
||||
'attr' => ['class' => 'hidden'],
|
||||
'multiple' => true,
|
||||
|
@ -14,7 +14,6 @@ readonly class DirContent
|
||||
private string $type,
|
||||
private string $path,
|
||||
private string $content,
|
||||
private string $mimeType,
|
||||
) {
|
||||
}
|
||||
|
||||
@ -25,8 +24,7 @@ readonly class DirContent
|
||||
$fileInfo->getSize() ?? 0,
|
||||
$fileInfo->getType() ?? 'N/A',
|
||||
$fileInfo->getPath(),
|
||||
$content,
|
||||
mime_content_type($fileInfo->getPath() . '/' . $fileInfo->getFilename()),
|
||||
$content
|
||||
);
|
||||
}
|
||||
|
||||
@ -59,11 +57,6 @@ readonly class DirContent
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function getMimeType(): string
|
||||
{
|
||||
return $this->mimeType;
|
||||
}
|
||||
|
||||
private function getHumanReadableSize(): string
|
||||
{
|
||||
$bytes = $this->size;
|
||||
|
@ -6,13 +6,8 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
class UploadedFileData
|
||||
{
|
||||
public function __construct(
|
||||
/**
|
||||
* @var UploadedFile[] $files
|
||||
*/
|
||||
public array $files = [],
|
||||
|
||||
public string $dir = '',
|
||||
) {
|
||||
}
|
||||
public array $files;
|
||||
}
|
33
src/Security/Authenticator.php
Normal file
33
src/Security/Authenticator.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Security;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator;
|
||||
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
|
||||
|
||||
class Authenticator extends AbstractAuthenticator
|
||||
{
|
||||
public function supports(Request $request): ?bool
|
||||
{
|
||||
return $request->attributes->get('_route') === 'auth_callback';
|
||||
}
|
||||
|
||||
public function authenticate(Request $request): Passport
|
||||
{
|
||||
}
|
||||
|
||||
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
|
||||
{
|
||||
// TODO: Implement onAuthenticationSuccess() method.
|
||||
}
|
||||
|
||||
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
|
||||
{
|
||||
// TODO: Implement onAuthenticationFailure() method.
|
||||
}
|
||||
}
|
@ -3,13 +3,11 @@
|
||||
namespace App\Service;
|
||||
|
||||
use App\Objects\DirContent;
|
||||
use App\Objects\UploadedFileData;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
class FileSystemService
|
||||
{
|
||||
@ -37,11 +35,13 @@ class FileSystemService
|
||||
return $contents;
|
||||
}
|
||||
|
||||
public function uploadFile(UploadedFileData $files): void
|
||||
/**
|
||||
* @param UploadedFile[] $files
|
||||
*/
|
||||
public function uploadFile(array $files): void
|
||||
{
|
||||
dd($files);
|
||||
foreach ($files->files as $file) {
|
||||
$this->filesystem->dumpFile($files->dir . $this->getTotalPath($file->getClientOriginalName()), $file->getContent());
|
||||
foreach ($files as $file) {
|
||||
$this->filesystem->dumpFile($this->getTotalPath($file->getClientOriginalName()), $file->getContent());
|
||||
}
|
||||
}
|
||||
|
||||
|
43
src/Service/Security/Provider.php
Normal file
43
src/Service/Security/Provider.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Security;
|
||||
|
||||
use League\OAuth2\Client\Provider\AbstractProvider;
|
||||
use League\OAuth2\Client\Provider\GenericResourceOwner;
|
||||
use League\OAuth2\Client\Token\AccessToken;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class Provider extends AbstractProvider
|
||||
{
|
||||
|
||||
public function getBaseAuthorizationUrl(): string
|
||||
{
|
||||
return 'https://oauth.simonis.lol/application/o/authorize/';
|
||||
}
|
||||
|
||||
public function getBaseAccessTokenUrl(array $params): string
|
||||
{
|
||||
return 'https://oauth.simonis.lol/application/o/token/';
|
||||
}
|
||||
|
||||
public function getResourceOwnerDetailsUrl(AccessToken $token)
|
||||
{
|
||||
return 'https://oauth.simonis.lol/application/o/userinfo/';
|
||||
}
|
||||
|
||||
protected function getDefaultScopes(): array
|
||||
{
|
||||
return ['email', 'profile', 'openid'];
|
||||
}
|
||||
|
||||
protected function checkResponse(ResponseInterface $response, $data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function createResourceOwner(array $response, AccessToken $token)
|
||||
{
|
||||
dd($response);
|
||||
}
|
||||
}
|
25
symfony.lock
25
symfony.lock
@ -1,4 +1,16 @@
|
||||
{
|
||||
"knpuniversity/oauth2-client-bundle": {
|
||||
"version": "2.18",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes-contrib",
|
||||
"branch": "main",
|
||||
"version": "1.20",
|
||||
"ref": "1ff300d8c030f55c99219cc55050b97a695af3f6"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/knpu_oauth2_client.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/apache-pack": {
|
||||
"version": "1.0",
|
||||
"recipe": {
|
||||
@ -82,6 +94,19 @@
|
||||
"config/routes.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/security-bundle": {
|
||||
"version": "7.1",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "6.4",
|
||||
"ref": "2ae08430db28c8eb4476605894296c82a642028f"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/security.yaml",
|
||||
"config/routes/security.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/stimulus-bundle": {
|
||||
"version": "2.22",
|
||||
"recipe": {
|
||||
|
@ -15,11 +15,7 @@
|
||||
</a>
|
||||
|
||||
<div class="mt-6 text-gray-700 overflow-auto max-h-96">
|
||||
{% if file.mimeType starts with 'image' %}
|
||||
<img src="{{ path('serve_file', {filePath: file.name}) }}" alt="">
|
||||
{% else %}
|
||||
<p class="whitespace-pre-wrap leading-relaxed break-all text-balance">{{ file.content|raw }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
@ -3,7 +3,7 @@
|
||||
{% block title %}Home{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<center class="container mt-5 mx-auto">
|
||||
<center class="container mt-5">
|
||||
{% include '_partials/_table.html.twig' %}
|
||||
</center>
|
||||
{% endblock %}
|
Reference in New Issue
Block a user