https://github.com/rikeda71/springboot-restapi-with-jwt
Example Codes of Rest API with SpringBoot + SpringSecurity + JWT
https://github.com/rikeda71/springboot-restapi-with-jwt
jwt spring-boot
Last synced: about 1 month ago
JSON representation
Example Codes of Rest API with SpringBoot + SpringSecurity + JWT
- Host: GitHub
- URL: https://github.com/rikeda71/springboot-restapi-with-jwt
- Owner: rikeda71
- Created: 2020-05-17T15:35:18.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-21T14:22:17.000Z (about 6 years ago)
- Last Synced: 2025-01-22T02:34:38.790Z (over 1 year ago)
- Topics: jwt, spring-boot
- Language: Java
- Size: 68.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SpringBoot-RestAPI-with-JWT
The Example of Rest API with SpringBoot + SpringSecurity + JWT(Json Web Token)
## Usage
- start up web app
```shell-script
$ docker-compose up -d
$ ./mvnw sprint-boot:run
```
- authorize
```shell-script
$ curl -v -X POST -d '{"name": "user1", "password": "password"}' "http://localhost:8080/login"
{"userId":null,"name":"user1", "token":"ey..."} <- copy token
```
- request with authorization
```shell-script
$ curl -XPATCH -H "Authorization: Bearer ..."(... is encoded token copied the previous step) -H "Content-type: application/json" -d '{"name": "user2","password": "password2"}' 'http://localhost:8080/services/v1/user/1'
```
- request auth user information (Example of using @AuthenticationPrincipal)
```shell script
curl -XGET -H "Authorization: Bearer ey..." 'http://localhost:8080/auth'
{"userId":2,"name":"user1","createdAt":"2020-05-17T13:04:30.88","updatedAt":"2020-05-17T13:04:30.88","lockVersion":0,"deleteFlag":false}
```