Using Security to integrate JWT in SpringBoot2
After running, execute the command to get TOKEN
curl -H "Content-Type: application/json" -X POST -d '{"username":"admin","password":"123456"}' http://127.0.0.1:8889/login
will get a JSON containing TOKEN
{
"result": "....",
"message": "",
"status": 0
}
Use the TOKEN value obtained above to obtain user information
curl -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN值" http://127.0.0.1:8080/users
Return result:
{
"result":["freewolf","tom","jerry"],
"message":"",
"status":0
}
Then everything is normal, and then you can customize it, integrate the database or something
Pay special attention to cross-domain issues
The cross-domain configuration of SpringBoot2
is based on JSON, so all front-end requests with TOKEN will have two requests, one is the preflight request method is OPTIONS, and the other is the real request, so it needs to be set in Security Release all OPTIONS requests in