0x00.背景

博主最近打算用spring boot + oauth2 + jwt构建一套sso单点登录零碎,查看材料的时候,很多例子给的都是curl -user username:password url这种形式的测试,博主打算转换成postman发动申请,查了些材料才晓得怎么改写

0x01.crul申请数据

  • 申请脚本
curl --request POST  --user android-client:android-client  --url http://localhost:8090/oauth/token  --header 'Content-Type: application/x-www-form-urlencoded'  --data 'username=customer_one&grant_type=password&password=customer_one'
  • 响应后果

0x02.转换成Postman

  • --user android-client:android-client :对应的Authorization。

  • --data :对应申请Body。

  • 响应后果

0x03.Authorization如何转换?

  • Basic前面字符串是Base64.encode("user:pwd")后的。
@Testpublic void encodeAuthTest() { String token = "android-client:android-client"; Base64.Encoder encoder = Base64.getEncoder(); byte[] bytes = encoder.encode(token.getBytes());System.out.println(new String(bytes)); //YW5kcm9pZC1jbGllbnQ6YW5kcm9pZC1jbGllbnQ=}

0x04.完