个人学习

身份验证之JWT

2020-03-17  本文已影响0人  Coding测试

什么是(JWT)JSON Web Token ?

{  "alg": "HS256", "typ": "JWT" }
{
  "iss": "www.baidu.com",
  "sub": "you",
  "aud": "me",
  "name": "456",
  "admin": true,
  "iat": 1584091337,
  "exp": 1784091337,
}
HMACSHA256( base64UrlEncode(header) + "." + base64UrlEncode(payload), secret)
 @Test
public void getToken() {
        //client-id  
        String clientId = "";
        //client-secret  
        String clientSecret = "";
        //系统地址
        String url = "https://xxx.com";
        //接口地址
        String api = "/api/xxx";

        Map<String, Object> requestMap = new HashMap<>();
        long timestamp = System.currentTimeMillis();
        String rand = UUID.randomUUID().toString();

        String sigin = this.tokenSignature(timestamp + "", rand, clientId, clientSecret);
        requestMap.put("timestamp", timestamp);
        requestMap.put("rand", rand);
        requestMap.put("clientId", clientId);
        requestMap.put("signature", sigin);
        url = url + api;
        String resultStr = HxHttpClient.postJson(url, requestMap);
        System.out.println(resultStr);
    }
上一篇下一篇

猜你喜欢

热点阅读