使用JWT创建PostMan GET请求

时间:2018-08-01 12:59:58

标签: rest spring-boot jwt postman restful-authentication

我是使用PostMan的新手;通常我使用curl:

这个获得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"

和另外一个使用之前获得的JTW

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"

我正在使用它来生成令牌

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

但是在postMan Signature方法中,我没有找到HS512

enter image description here

1 个答案:

答案 0 :(得分:2)

我认为这可以解决您的问题。

转到身份验证标签,然后选择承载者令牌

enter image description here

添加您的令牌

enter image description here

添加标题 Content-Type:Application / json ,如有必要:

enter image description here

发送您的请求。

如果您计划自动化获取访问令牌并在其他请求中使用,则建议阅读有关邮递员测试和变量的信息:https://medium.com/@codebyjeff/using-postman-environment-variables-auth-tokens-ea9c4fe9d3d7