You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/jwt.md
+23-9Lines changed: 23 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,10 @@
1
1
# JWT Authentication
2
2
3
-
> [JSON Web Token (JWT)](https://jwt.io/) is a JSON-based open standard ([RFC 7519](https://tools.ietf.org/html/rfc7519)) for creating access tokens that assert some number of claims. For example, a server could generate a token that has the claim "logged in as admin" and provide that to a client. The client could then use that token to prove that he/she is logged in as admin.
4
-
> The tokens are signed by the server's key, so the server is able to verify that the token is legitimate. The tokens are designed to be compact, URL-safe and usable especially in web browser single sign-on (SSO) context.
3
+
> [JSON Web Token (JWT)](https://jwt.io/) is a JSON-based open standard ([RFC 7519](https://tools.ietf.org/html/rfc7519)) for creating access tokens that assert
4
+
> some number of claims. For example, a server could generate a token that has the claim "logged in as admin" and
5
+
> provide that to a client. The client could then use that token to prove that he/she is logged in as admin.
6
+
> The tokens are signed by the server's key, so the server is able to verify that the token is legitimate. The tokens
7
+
> are designed to be compact, URL-safe and usable especially in web browser single sign-on (SSO) context.
@@ -14,11 +17,17 @@ API Platform allows to easily add a JWT-based authentication to your API using [
14
17
We begin by installing the bundle:
15
18
16
19
```console
17
-
docker compose exec php \
18
-
composer require lexik/jwt-authentication-bundle
20
+
composer require lexik/jwt-authentication-bundle
19
21
```
22
+
Then we need to generate the public and private keys used for signing JWT tokens.
20
23
21
-
Then we need to generate the public and private keys used for signing JWT tokens. If you're using the [API Platform distribution](../symfony/index.md), you may run this from the project's root directory:
24
+
You can generate them by using this command:
25
+
26
+
```console
27
+
php bin/console lexik:jwt:generate-keypair
28
+
```
29
+
30
+
Or if you're using the [API Platform distribution with Symfony](../symfony/index.md), you may run this from the project's root directory:
Note that the `setfacl` command relies on the `acl` package. This is installed by default when using the API Platform docker distribution but may need to be installed in your working environment in order to execute the `setfacl` command.
42
+
Note that the `setfacl` command relies on the `acl` package. This is installed by default when using the API Platform
43
+
docker distribution but may need to be installed in your working environment in order to execute the `setfacl` command.
34
44
35
-
This takes care of keypair creation (including using the correct passphrase to encrypt the private key), and setting the correct permissions on the keys allowing the web server to read them.
45
+
This takes care of keypair creation (including using the correct passphrase to encrypt the private key), and setting the
46
+
correct permissions on the keys allowing the web server to read them.
36
47
37
-
Since these keys are created by the `root` user from a container, your host user will not be able to read them during the `docker compose build caddy` process. Add the `config/jwt/` folder to the `api/.dockerignore` file so that they are skipped from the result image.
48
+
If you want the keys to be auto generated in `dev` environment, see an example in the
49
+
[docker-entrypoint script of api-platform/demo](https://github.com/api-platform/demo/blob/a03ce4fb1f0e072c126e8104e42a938bb840bffc/api/docker/php/docker-entrypoint.sh#L16-L17).
38
50
39
-
If you want the keys to be auto generated in `dev` environment, see an example in the [docker-entrypoint script of api-platform/demo](https://github.com/api-platform/demo/blob/master/api/docker/php/docker-entrypoint.sh).
51
+
Since these keys are created by the `root` user from a container, your host user will not be able to read them during
52
+
the `docker compose build caddy` process. Add the `config/jwt/` folder to the `api/.dockerignore` file so that they are
53
+
skipped from the result image.
40
54
41
55
The keys should not be checked in to the repository (i.e. it's in `api/.gitignore`). However, note that a JWT token could
42
56
only pass signature validation against the same pair of keys it was signed with. This is especially relevant in a production
Copy file name to clipboardExpand all lines: core/mongodb.md
+3-4Lines changed: 3 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ the legacy [mongo](https://secure.php.net/manual/en/book.mongo.php) extension.
18
18
19
19
If the `mongodb` PHP extension is not installed yet, [install it beforehand](https://secure.php.net/manual/en/mongodb.installation.pecl.php).
20
20
21
-
If you are using the [API Platform Distribution](../symfony/index.md), modify the `Dockerfile` to add the extension:
21
+
Or if you are using the [API Platform Distribution with Symfony](../symfony/index.md), modify the `Dockerfile` to add the extension:
22
22
23
23
```diff
24
24
# api/Dockerfile
@@ -64,12 +64,11 @@ services:
64
64
# ...
65
65
```
66
66
67
-
Once the extension is installed, to enable the MongoDB support, require the [Doctrine MongoDB ODM bundle](https://github.com/doctrine/DoctrineMongoDBBundle)
67
+
In all cases, enable the MongoDB support by requiring the [Doctrine MongoDB ODM bundle](https://github.com/doctrine/DoctrineMongoDBBundle)
68
68
package using Composer:
69
69
70
70
```console
71
-
docker compose exec php \
72
-
composer require doctrine/mongodb-odm-bundle
71
+
composer require doctrine/mongodb-odm-bundle
73
72
```
74
73
75
74
Execute the contrib recipe to have it already configured.
0 commit comments