README.adoc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. = JWT Login Sample
  2. This sample demonstrates how to accept JWTs without using a separate authorization server.
  3. This approach is useful in REST APIs when a user would like to locally authenticate with a username and password and then use a JWT thereafter.
  4. [[usage]]
  5. To use the application, first run it:
  6. ```bash
  7. ./gradlew :servlet:spring-boot:java:jwt:login:bootRun
  8. ```
  9. If you `POST` to the `/token` endpoint with the user `user/password`:
  10. ```bash
  11. curl -XPOST user:password@localhost:8080/token
  12. ```
  13. Then the application responds with something similar to the following:
  14. ```bash
  15. eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJzZWxmIiwic3ViIjoidXNlciIsImV4cCI6MTYwNDA0MzA1MSwiaWF0IjoxNjA0MDA3MDUxfQ.yDF_JgSwl5sk21CF7AE1AYbYzRd5YYqe3MIgSWpgN0t2UqsjaaEDhmmICKizt-_0iZy8nkEpNnvgqv5bOHDhs7AXlYS1pg8dgPKuyfkhyVIKa3DhuGyb7tFjwJxHpr128BXf1Dbq-p7Njy46tbKsZhP5zGTjdXlqlAhR4Bl5Fxaxr7D0gdTVBVTlUp9DCy6l-pTBpsvHxShkjXJ0GHVpIZdB-c2e_K9PfTW5MDPcHekG9djnWPSEy-fRvKzTsyVFhdy-X3NXQWWkjFv9bNarV-bhxMlzqhujuaeXJGEqUZlkhBxTsqFr1N7XVcmhs3ECdjEyun2fUSge4BoC7budsQ
  16. ```
  17. So, next, request the token and export it:
  18. ```bash
  19. export TOKEN=`curl -XPOST user:password@localhost:8080/token`
  20. ```
  21. Finally, request `/`, including the bearer token for authentication:
  22. ```bash
  23. curl -H "Authorization: Bearer $TOKEN" localhost:8080 && echo
  24. ```
  25. You should see a response like:
  26. ```bash
  27. Hello, user!
  28. ```