Skip to content

Commit 9a724c3

Browse files
Merge pull request #40 from cvigorsICBF/2.2.x
Add Body Parsing Middleware reference
2 parents 6e6dea0 + 56bf478 commit 9a724c3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/book/v1/authorization-server.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ use Mezzio\Authentication\OAuth2;
2020

2121
$app->post('/oauth2/token', OAuth2\TokenEndpointHandler::class);
2222
```
23+
## Parsing JSON payloads in the token endpoint
24+
To enable the token endpoint to handle the POST requests in JSON, the [Body Parsing Middleware](https://docs.mezzio.dev/mezzio/v3/features/helpers/body-parse/) helper must be included in the application.
25+
26+
For example:
27+
28+
```php
29+
use Mezzio\Authentication\OAuth2;
30+
use Mezzio\Helper\BodyParams\BodyParamsMiddleware;
31+
32+
$app->post('/oauth2/token', [
33+
BodyParamsMiddleware::class,
34+
OAuth2\TokenEndpointHandler::class
35+
], 'auth.token');
36+
```
37+
WARNING: Do not pipe the body parsing middleware as generic middleware.
38+
This ensures that the content body is only parsed when it is actually expected.
2339

2440
## Add the authorization endpoint
2541

0 commit comments

Comments
 (0)