Skip to content

Commit cebb9f1

Browse files
SerosTavoNiievez
authored andcommitted
Add resetFormatsAfterRequest issue test
1 parent 51ae6ba commit cebb9f1

File tree

17 files changed

+181
-11
lines changed

17 files changed

+181
-11
lines changed

.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ MAILER_DSN=null://null
1818
###> symfony/notifier ###
1919
NOTIFIER_DSN=null://null
2020
###< symfony/notifier ###
21+
22+
###> lexik/jwt-authentication-bundle ###
23+
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
24+
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
25+
JWT_PASSPHRASE=b406fa29adfd637669a87d0d0e0032139731110641fcf3ac692c3fde392a9566
26+
###< lexik/jwt-authentication-bundle ###

.github/workflows/symfony.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,8 @@ jobs:
5555
- name: Load Doctrine fixtures
5656
run: php bin/console doctrine:fixtures:load --quiet
5757

58+
- name: Generate JWT keypair
59+
run: php bin/console lexik:jwt:generate-keypair
60+
5861
- name: Run functional tests
5962
run: vendor/bin/codecept run Functional

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ yarn-error.log
3434
/phpunit.xml
3535
.phpunit.result.cache
3636
###< phpunit/phpunit ###
37+
38+
###> lexik/jwt-authentication-bundle ###
39+
/config/jwt/*.pem
40+
###< lexik/jwt-authentication-bundle ###

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ Lastly, if you just want to see the module in action and run the tests yourself
2424
```shell
2525
composer update
2626
```
27-
3. Update database schema and load Doctrine fixtures
27+
3. Update database schema, load Doctrine fixtures and generate JWT keypair
2828
```shell
2929
php bin/console doctrine:schema:update --force
3030

3131
php bin/console doctrine:fixtures:load --quiet
32+
33+
php bin/console lexik:jwt:generate-keypair
3234
```
3335

3436
Then, go to the project directory and run:

composer.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"php": ">=8.2.0",
1515
"ext-ctype": "*",
1616
"ext-iconv": "*",
17+
"api-platform/symfony": "^4.0",
1718
"doctrine/doctrine-bundle": "^2.18",
19+
"lexik/jwt-authentication-bundle": "^3.1",
1820
"symfony/apache-pack": "^1.0",
1921
"symfony/console": "6.4.*",
2022
"symfony/dotenv": "6.4.*",
@@ -32,34 +34,37 @@
3234
},
3335
"require-dev": {
3436
"codeception/codeception": "^5.3",
35-
"codeception/lib-innerbrowser": "^3.1",
3637
"codeception/module-asserts": "^3.2",
3738
"codeception/module-doctrine": "^3.3",
3839
"codeception/module-phpbrowser": "^4.0",
40+
"codeception/module-rest": "^3.4",
3941
"codeception/module-symfony": "^3.8 | *@dev",
4042
"doctrine/doctrine-fixtures-bundle": "^4.3",
4143
"friendsofphp/php-cs-fixer": "^3.94",
4244
"phpmd/phpmd": "^2.15",
4345
"roave/security-advisories": "dev-latest",
4446
"squizlabs/php_codesniffer": "^4.0",
47+
"phpstan/phpdoc-parser": "^1.25",
48+
"phpunit/phpunit": "^10.5",
4549
"symfony/debug-bundle": "6.4.*",
4650
"symfony/twig-bundle": "6.4.*",
4751
"symfony/var-dumper": "6.4.*",
4852
"symfony/web-profiler-bundle": "6.4.*",
4953
"vlucas/phpdotenv": "^5.6"
5054
},
5155
"config": {
56+
"allow-plugins": {
57+
"php-http/discovery": true,
58+
"symfony/flex": true,
59+
"symfony/runtime": true
60+
},
5261
"optimize-autoloader": true,
5362
"preferred-install": {
5463
"*": "dist"
5564
},
5665
"sort-packages": true,
5766
"platform": {
5867
"php": "8.2.0"
59-
},
60-
"allow-plugins": {
61-
"symfony/flex": true,
62-
"symfony/runtime": true
6368
}
6469
},
6570
"autoload": {
@@ -102,7 +107,8 @@
102107
],
103108
"post-create-project-cmd": [
104109
"@php bin/console doctrine:schema:update --force",
105-
"@php bin/console doctrine:fixtures:load --quiet"
110+
"@php bin/console doctrine:fixtures:load --quiet",
111+
"@php bin/console lexik:jwt:generate-keypair"
106112
]
107113
},
108114
"conflict": {

config/bundles.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
99
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
1010
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
11+
ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
12+
Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
1113
];

config/packages/api_platform.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Config\ApiPlatformConfig;
6+
7+
return static function (ApiPlatformConfig $apiPlatformConfig): void {
8+
$apiPlatformConfig->title('Hello API Platform');
9+
$apiPlatformConfig->version('1.0.0');
10+
$apiPlatformConfig->formats('jsonld', ['mime_types' => ['application/ld+json']]);
11+
$apiPlatformConfig->formats('json', ['mime_types' => ['application/json']]);
12+
$defaults = $apiPlatformConfig->defaults();
13+
$defaults->stateless(true);
14+
$defaults->cacheHeaders(['vary' => ['Content-Type', 'Authorization', 'Origin']]);
15+
$apiPlatformConfig->doctrine(['enabled' => false]);
16+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Config\LexikJwtAuthenticationConfig;
6+
7+
return static function (LexikJwtAuthenticationConfig $lexikJwtAuthenticationConfig): void {
8+
$lexikJwtAuthenticationConfig->secretKey('%env(resolve:JWT_SECRET_KEY)%')
9+
->publicKey('%env(resolve:JWT_PUBLIC_KEY)%')
10+
->passPhrase('%env(JWT_PASSPHRASE)%');
11+
};

config/packages/security.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919
->pattern('^/(_(profiler|wdt)|css|images|js)/')
2020
->security(false);
2121

22+
$apiFirewall = $security->firewall('api');
23+
$apiFirewall
24+
->pattern('^/api')
25+
->stateless(true)
26+
->provider('app_user_provider')
27+
->jwt();
28+
$apiFirewall->jsonLogin([
29+
'check_path' => '/api/login',
30+
'success_handler' => 'lexik_jwt_authentication.handler.authentication_success',
31+
'failure_handler' => 'lexik_jwt_authentication.handler.authentication_failure',
32+
]);
33+
2234
$mainFirewall = $security->firewall('main');
2335
$mainFirewall
2436
->lazy(true)
@@ -27,7 +39,7 @@
2739
$mainFirewall->logout(['path' => 'app_logout']);
2840
$mainFirewall->rememberMe(['secret' => '%env(APP_SECRET)%']);
2941

30-
$security->accessControl([
31-
'path' => '^/dashboard', 'roles' => 'ROLE_USER',
32-
]);
42+
$security->accessControl(['path' => '^/api/login', 'roles' => 'PUBLIC_ACCESS']);
43+
$security->accessControl(['path' => '^/api', 'roles' => 'IS_AUTHENTICATED_FULLY']);
44+
$security->accessControl(['path' => '^/dashboard', 'roles' => 'ROLE_USER']);
3345
};

config/packages/uid.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Config\FrameworkConfig;
6+
7+
return static function (FrameworkConfig $framework): void {
8+
$uid = $framework->uid();
9+
$uid->defaultUuidVersion(7);
10+
$uid->timeBasedUuidVersion(7);
11+
};

0 commit comments

Comments
 (0)