Create a PostMan GET Request with JWT

2019-04-15 12:41发布

问题:

I am new using PostMan; normally I use curl:

this one to get the JTW

curl -X POST -H "X-Requested-With: XMLHttpRequest" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{ "username": "peris","password": "3nRam0nD3L3s0l1v3s" }' "http://139.152.231.107:1133/canPeris/auth"

and this other one using the JTW obtained before

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer eyJhbGciJIUzUxMiJ9.eyJzdWIiOiJsb3Blei5hbnRvbmlvODVAZ21haWwuY29tIiwiZXhwIjoxNTkwMDQ3NTg4LCJpYXQiOjE1Mh9.3vlQBgfA22ffJZqNic2lVSHiMR6YudlCFoldfwzdk-clz6_XyOvCVTrMihXtYBaJuPI515zTwAnaQBV_h4yquA"  "http://139.152.231.107:1133/canPeris/api/v1/users/3/menus/vegans"

I am using this to generate the token

return io.jsonwebtoken.Jwts.builder()
            .setClaims(claims)
            .setSubject(subject)
            .setIssuedAt(createdDate)
            .setExpiration(expirationDate)
            .signWith(SignatureAlgorithm.HS512, secret)
            .compact();

but in the postMan Signature method I haven't found the HS512

回答1:

I think this can solve your problem.

Goto to Auth tab and select Bearer Token:

Add your Token:

Add the header Content-Type: Application/json, if necessary:

Send your request.

If you planing automate the access token acquisition and use in another request, I recommend read about postman tests and variables: https://medium.com/@codebyjeff/using-postman-environment-variables-auth-tokens-ea9c4fe9d3d7