Skip to content

Commit e132e04

Browse files
committed
docs(authentication): show curl response as output
1 parent 797976a commit e132e04

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

content/security/authentication.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ Let's go ahead and test our routes using cURL again. You can test with any of th
348348
```bash
349349
$ # POST to /auth/login
350350
$ curl -X POST http://localhost:3000/auth/login -d '{"username": "john", "password": "changeme"}' -H "Content-Type: application/json"
351-
$ # result -> {"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."}
351+
{"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."}
352352
$ # Note: above JWT truncated
353353
```
354354

@@ -445,15 +445,15 @@ Ensure the app is running, and test the routes using `cURL`.
445445
```bash
446446
$ # GET /profile
447447
$ curl http://localhost:3000/auth/profile
448-
$ # result -> {"statusCode":401,"message":"Unauthorized"}
448+
{"statusCode":401,"message":"Unauthorized"}
449449

450450
$ # POST /auth/login
451451
$ curl -X POST http://localhost:3000/auth/login -d '{"username": "john", "password": "changeme"}' -H "Content-Type: application/json"
452-
$ # result -> {"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2Vybm..."}
452+
{"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2Vybm..."}
453453

454454
$ # GET /profile using access_token returned from previous step as bearer code
455455
$ curl http://localhost:3000/auth/profile -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2Vybm..."
456-
$ # result -> {"sub":1,"username":"john","iat":...,"exp":...}
456+
{"sub":1,"username":"john","iat":...,"exp":...}
457457
```
458458

459459
Note that in the `AuthModule`, we configured the JWT to have an expiration of `60 seconds`. This is too short an expiration, and dealing with the details of token expiration and refresh is beyond the scope of this article. However, we chose that to demonstrate an important quality of JWTs. If you wait 60 seconds after authenticating before attempting a `GET /auth/profile` request, you'll receive a `401 Unauthorized` response. This is because `@nestjs/jwt` automatically checks the JWT for its expiration time, saving you the trouble of doing so in your application.

0 commit comments

Comments
 (0)