Skip to content

Commit 087014d

Browse files
arunnethuesalanpoulaindunglas
authored
docs: update jwt.md for Symfony 5.3 compatibility (#1429)
* Update jwt.md for Symfony 5.3 compatibility update doc for Symfony 5.3 compatibility, due to use deprecated code app does not work and return warnings - New in version 5.3: The password_hashers option was introduced in Symfony 5.3. In previous versions it was called encoders. - Deprecated since version 5.3: Guard authenticators are deprecated since Symfony 5.3 in favor of the new authenticator-based system. Reference: https://symfony.com/doc/current/security.html#c-hashing-passwords https://symfony.com/doc/current/security.html#guard-authenticators * Apply suggestions from code review Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> * docs: use PUBLIC_ACCESS Co-authored-by: Alan Poulain <contact@alanpoulain.eu> Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
1 parent 0f42f22 commit 087014d

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

core/jwt.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ Then update the security configuration:
6464
```yaml
6565
# api/config/packages/security.yaml
6666
security:
67-
encoders:
68-
App\Entity\User:
69-
algorithm: auto
67+
# https://symfony.com/doc/current/security.html#c-hashing-passwords
68+
password_hashers:
69+
App\Entity\User: 'auto'
7070

71+
# https://symfony.com/doc/current/security/authenticator_manager.html
72+
enable_authenticator_manager: true
7173
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
7274
providers:
7375
# used to reload user from session & other features (e.g. switch_user)
@@ -90,13 +92,11 @@ security:
9092
password_path: password
9193
success_handler: lexik_jwt_authentication.handler.authentication_success
9294
failure_handler: lexik_jwt_authentication.handler.authentication_failure
93-
guard:
94-
authenticators:
95-
- lexik_jwt_authentication.jwt_token_authenticator
95+
jwt: ~
9696

9797
access_control:
98-
- { path: ^/docs, roles: IS_AUTHENTICATED_ANONYMOUSLY } # Allows accessing the Swagger UI
99-
- { path: ^/authentication_token, roles: IS_AUTHENTICATED_ANONYMOUSLY }
98+
- { path: ^/docs, roles: PUBLIC_ACCESS } # Allows accessing the Swagger UI
99+
- { path: ^/authentication_token, roles: PUBLIC_ACCESS }
100100
- { path: ^/, roles: IS_AUTHENTICATED_FULLY }
101101
```
102102
@@ -122,10 +122,12 @@ If your API uses a [path prefix](https://symfony.com/doc/current/routing/externa
122122
```yaml
123123
# api/config/packages/security.yaml
124124
security:
125-
encoders:
126-
App\Entity\User:
127-
algorithm: auto
128-
125+
# https://symfony.com/doc/current/security.html#c-hashing-passwords
126+
password_hashers:
127+
App\Entity\User: 'auto'
128+
129+
# https://symfony.com/doc/current/security/authenticator_manager.html
130+
enable_authenticator_manager: true
129131
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
130132
providers:
131133
# used to reload user from session & other features (e.g. switch_user)
@@ -143,9 +145,7 @@ security:
143145
stateless: true
144146
anonymous: true
145147
provider: app_user_provider
146-
guard:
147-
authenticators:
148-
- lexik_jwt_authentication.jwt_token_authenticator
148+
jwt: ~
149149
main:
150150
anonymous: true
151151
json_login:
@@ -156,8 +156,8 @@ security:
156156
failure_handler: lexik_jwt_authentication.handler.authentication_failure
157157
158158
access_control:
159-
- { path: ^/docs, roles: IS_AUTHENTICATED_ANONYMOUSLY } # Allows accessing API documentations and Swagger UI
160-
- { path: ^/authentication_token, roles: IS_AUTHENTICATED_ANONYMOUSLY }
159+
- { path: ^/docs, roles: PUBLIC_ACCESS } # Allows accessing API documentations and Swagger UI
160+
- { path: ^/authentication_token, roles: PUBLIC_ACCESS }
161161
- { path: ^/, roles: IS_AUTHENTICATED_FULLY }
162162
```
163163

@@ -319,7 +319,7 @@ class AuthenticationTest extends ApiTestCase
319319
$user = new User();
320320
$user->setEmail('test@example.com');
321321
$user->setPassword(
322-
self::$container->get('security.password_encoder')->encodePassword($user, '$3CR3T')
322+
self::$container->get('security.user_password_hasher')->hashPassword($user, '$3CR3T')
323323
);
324324
325325
$manager = self::$container->get('doctrine')->getManager();

0 commit comments

Comments
 (0)