vrudas / spring-framework-examples

An educational project with Spring Framework examples. Used for lectures at courses.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring Logo

Spring Framework Examples

An educational project with Spring Framework examples. Used for lectures at courses.

Related links

Spring Security 6 Migration links

Important information

Example 21 - JWT Instructions

Please note that IntelliJ IDEA HTTP Client was used to perform requests in code snippets

Please follow the steps to perform a demo of how to get a JWT token for an existing user:

  • Perform login action
POST http://localhost:8080/login?username=user&password=user
Accept: application/json
  • Extract the generated Bearer token from a response header Authorization: Bearer <token>
HTTP/1.1 200
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ1c2VyIiwiZXhwIjoxNjc4ODM2OTY1fQ.Afagk8no-r2kUiDOdtjWMT06gYPHkrhCoOSoK5_X6k8BC8Lr6k5rB-9gyoE72-lkd0rx1sEPET-3Uf7KP-7BrQ
X-Content-Type-Options: nosniff
X-XSS-Protection: 0
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Length: 0
Date: Tue, 14 Mar 2023 23:35:05 GMT
Keep-Alive: timeout=60
Connection: keep-alive

<Response body is empty>
  • Use the generated Bearer token to perform the call to an endpoint by providing the Authorization: Bearer <token> header
GET http://localhost:8080/users/me
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ1c2VyIiwiZXhwIjoxNjc4ODM1NjE5fQ.cRZ1ob4XZfG5RnU0jl2kdPihc9Ln-BlEOe7hbuwZJWp-UuQSGukI_57pWrBcdaCWPN-8luCF08YWU74tUErOFg

Contribution statistic

Repobeats analytics image

About

An educational project with Spring Framework examples. Used for lectures at courses.

License:MIT License


Languages

Language:Java 93.2%Language:HTML 6.8%