https://github.com/making/demo-jwt
Demo Spring Security + JWT
https://github.com/making/demo-jwt
Last synced: 12 months ago
JSON representation
Demo Spring Security + JWT
- Host: GitHub
- URL: https://github.com/making/demo-jwt
- Owner: making
- Created: 2020-02-24T16:34:26.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T20:18:06.000Z (about 3 years ago)
- Last Synced: 2025-04-06T07:43:11.156Z (about 1 year ago)
- Language: Java
- Homepage: https://demo-jwt.apps.pcfone.io
- Size: 104 KB
- Stars: 19
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Demo using JWT in Spring Security
This app demonstrates standalone JWT authorization in Spring Security using [OAuth 2.0 Resource Server feature](https://docs.spring.io/spring-security/site/docs/5.2.2.RELEASE/reference/htmlsingle/#oauth2resourceserver).
Actually it mimics OAuth2's Resource Owner Password Credentials flow.
```
ACCESS_TOKEN=$(curl -s localhost:8080/oauth/token -d grant_type=password -d username=demo -d password=demo | jq -r .access_token)
TODO_ID=$(curl -s localhost:8080/todos -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "Content-Type: application/json" -d '{"todoTitle": "Demo"}' | jq -r .todoId)
curl -s localhost:8080/todos -H "Authorization: Bearer ${ACCESS_TOKEN}"
curl -s localhost:8080/todos/${TODO_ID} -H "Authorization: Bearer ${ACCESS_TOKEN}"
curl -s -X PUT localhost:8080/todos/${TODO_ID} -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "Content-Type: application/json" -d '{"finished": "true"}'
curl -s -X DELETE localhost:8080/todos/${TODO_ID} -H "Authorization: Bearer ${ACCESS_TOKEN}"
curl -s localhost:8080/todos -H "Authorization: Bearer ${ACCESS_TOKEN}"
```