Skip to content

Commit 3ce2a79

Browse files
SerosTavoNiievez
authored andcommitted
Add resetFormatsAfterRequest issue test
1 parent 6b01ba3 commit 3ce2a79

File tree

17 files changed

+174
-6
lines changed

17 files changed

+174
-6
lines changed

.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ DATABASE_URL=sqlite:///%kernel.project_dir%/var/test.db3
1414
###> symfony/mailer ###
1515
MAILER_DSN=null://null
1616
###< symfony/mailer ###
17+
18+
###> lexik/jwt-authentication-bundle ###
19+
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
20+
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
21+
JWT_PASSPHRASE=b406fa29adfd637669a87d0d0e0032139731110641fcf3ac692c3fde392a9566
22+
###< 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: 5 additions & 1 deletion
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.11",
19+
"lexik/jwt-authentication-bundle": "^3.1",
1820
"symfony/apache-pack": "^1.0",
1921
"symfony/console": "6.4.*",
2022
"symfony/dotenv": "6.4.*",
@@ -34,6 +36,7 @@
3436
"codeception/module-asserts": "^3.2",
3537
"codeception/module-doctrine": "^3.1",
3638
"codeception/module-phpbrowser": "^3.0",
39+
"codeception/module-rest": "^3.4",
3740
"codeception/module-symfony": "^3.2 | *@dev",
3841
"doctrine/doctrine-fixtures-bundle": "^3.5",
3942
"friendsofphp/php-cs-fixer": "^3.46",
@@ -102,7 +105,8 @@
102105
],
103106
"post-create-project-cmd": [
104107
"@php bin/console doctrine:schema:update --force",
105-
"@php bin/console doctrine:fixtures:load --quiet"
108+
"@php bin/console doctrine:fixtures:load --quiet",
109+
"@php bin/console lexik:jwt:generate-keypair"
106110
]
107111
},
108112
"conflict": {

config/bundles.php

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

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)