Skip to content

Commit c9bc7ab

Browse files
authored
feat: add user documentation (#1654)
1 parent 24814ce commit c9bc7ab

File tree

4 files changed

+302
-18
lines changed

4 files changed

+302
-18
lines changed

core/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Here is the fully featured REST API you'll get in minutes:
3333
* Advanced [serialization](serialization.md) thanks to the Symfony Serializer Component (groups support, relation embedding, max depth...)
3434
* Automatic routes registration
3535
* Automatic entrypoint generation giving access to all resources
36+
* [User](user.md) support
3637
* [JWT](jwt.md) and [OAuth](https://oauth.net/) support
3738
* Files and `\DateTime` and serialization and deserialization
3839

core/jwt.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ We begin by installing the bundle:
1515

1616
```console
1717
docker compose exec php \
18-
composer require jwt-auth
18+
composer require lexik/jwt-authentication-bundle
1919
```
2020

2121
Then we need to generate the public and private keys used for signing JWT tokens. If you're using the [API Platform distribution](../distribution/index.md), you may run this from the project's root directory:
@@ -69,7 +69,7 @@ security:
6969
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
7070
providers:
7171
# used to reload user from session & other features (e.g. switch_user)
72-
app_user_provider:
72+
users:
7373
entity:
7474
class: App\Entity\User
7575
property: email
@@ -80,27 +80,28 @@ security:
8080
security: false
8181
main:
8282
stateless: true
83-
provider: app_user_provider
83+
provider: users
8484
json_login:
85-
check_path: /authentication_token
85+
check_path: auth # The name in routes.yaml is enough for mapping
8686
username_path: email
8787
password_path: password
8888
success_handler: lexik_jwt_authentication.handler.authentication_success
8989
failure_handler: lexik_jwt_authentication.handler.authentication_failure
9090
jwt: ~
9191

9292
access_control:
93-
- { path: ^/docs, roles: PUBLIC_ACCESS } # Allows accessing the Swagger UI
94-
- { path: ^/authentication_token, roles: PUBLIC_ACCESS }
93+
- { path: ^/$, roles: PUBLIC_ACCESS } # Allows accessing the Swagger UI
94+
- { path: ^/docs, roles: PUBLIC_ACCESS } # Allows accessing the Swagger UI docs
95+
- { path: ^/auth, roles: PUBLIC_ACCESS }
9596
- { path: ^/, roles: IS_AUTHENTICATED_FULLY }
9697
```
9798
98-
You must also declare the route used for `/authentication_token`:
99+
You must also declare the route used for `/auth`:
99100

100101
```yaml
101102
# api/config/routes.yaml
102-
authentication_token:
103-
path: /authentication_token
103+
auth:
104+
path: /auth
104105
methods: ['POST']
105106
```
106107

@@ -126,7 +127,7 @@ security:
126127
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
127128
providers:
128129
# used to reload user from session & other features (e.g. switch_user)
129-
app_user_provider:
130+
users:
130131
entity:
131132
class: App\Entity\User
132133
property: email
@@ -138,19 +139,20 @@ security:
138139
api:
139140
pattern: ^/api/
140141
stateless: true
141-
provider: app_user_provider
142+
provider: users
142143
jwt: ~
143144
main:
144145
json_login:
145-
check_path: /authentication_token
146+
check_path: auth # The name in routes.yaml is enough for mapping
146147
username_path: email
147148
password_path: password
148149
success_handler: lexik_jwt_authentication.handler.authentication_success
149150
failure_handler: lexik_jwt_authentication.handler.authentication_failure
150151
151152
access_control:
152-
- { path: ^/docs, roles: PUBLIC_ACCESS } # Allows accessing API documentations and Swagger UI
153-
- { path: ^/authentication_token, roles: PUBLIC_ACCESS }
153+
- { path: ^/$, roles: PUBLIC_ACCESS } # Allows accessing the Swagger UI
154+
- { path: ^/docs, roles: PUBLIC_ACCESS } # Allows accessing API documentations and Swagger UI docs
155+
- { path: ^/auth, roles: PUBLIC_ACCESS }
154156
- { path: ^/, roles: IS_AUTHENTICATED_FULLY }
155157
```
156158

@@ -162,8 +164,6 @@ lexik_jwt_authentication:
162164
secret_key: '%env(resolve:JWT_SECRET_KEY)%'
163165
public_key: '%env(resolve:JWT_PUBLIC_KEY)%'
164166
pass_phrase: '%env(JWT_PASSPHRASE)%'
165-
166-
user_identity_field: email # Or the field you have setted using make:user
167167
```
168168

169169
## Documenting the Authentication Mechanism with Swagger/Open API
@@ -286,7 +286,7 @@ final class JwtDecorator implements OpenApiFactoryInterface
286286
security: [],
287287
),
288288
);
289-
$openApi->getPaths()->addPath('/authentication_token', $pathItem);
289+
$openApi->getPaths()->addPath('/auth', $pathItem);
290290
291291
return $openApi;
292292
}
@@ -339,7 +339,7 @@ class AuthenticationTest extends ApiTestCase
339339
$manager->flush();
340340
341341
// retrieve a token
342-
$response = $client->request('POST', '/authentication_token', [
342+
$response = $client->request('POST', '/auth', [
343343
'headers' => ['Content-Type' => 'application/json'],
344344
'json' => [
345345
'email' => '[email protected]',

0 commit comments

Comments
 (0)