You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.0 KiB
36 lines
1.0 KiB
3 years ago
|
package com.eco.plugin.xx.jbsync.utils;
|
||
|
|
||
|
import com.auth0.jwt.JWT;
|
||
|
import com.auth0.jwt.JWTVerifier;
|
||
|
import com.auth0.jwt.algorithms.Algorithm;
|
||
|
import com.auth0.jwt.exceptions.JWTVerificationException;
|
||
|
import com.auth0.jwt.interfaces.DecodedJWT;
|
||
|
|
||
|
import java.util.Date;
|
||
|
|
||
|
public class JWTUtils {
|
||
|
|
||
|
/**
|
||
|
* 校验token是否有效
|
||
|
* @param token
|
||
|
* @param secret
|
||
|
* @return
|
||
|
*/
|
||
|
public static boolean verify(String token,String secret){
|
||
|
boolean result = true;
|
||
|
token = token.replace("Bearer ","");
|
||
|
DecodedJWT decode = JWT.decode(token);
|
||
|
int jwtTimeout = 60000;
|
||
|
try {
|
||
|
Date date = decode.getIssuedAt();
|
||
|
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(secret)).acceptIssuedAt((long)(jwtTimeout / 1000)).build();
|
||
|
jwtVerifier.verify(token);
|
||
|
} catch (JWTVerificationException e) {
|
||
|
FRUtils.FRLogInfo("verifyToken exception :"+e.getMessage());
|
||
|
result = false;
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
}
|