use of com.auth0.jwt.exceptions.TokenExpiredException in project java-docs-samples by GoogleCloudPlatform.
the class VerifyingInstance method verifyToken.
void verifyToken(String token) {
TokenVerifier gtv = new TokenVerifier();
// Following are examples how to handle verification failure.
try {
DecodedGoogleJWTWrapper decodedJwt = gtv.verifyWithAudience(audience, token);
System.out.println("Project id : " + decodedJwt.getProjectId());
System.out.println("Project number : " + decodedJwt.getProjectNumber());
// This are examples how to handle exceptions, which indicate verification failure.
} catch (AlgorithmMismatchException e) {
// We assume that downloaded certs are RSA256, this exception will happen if this changes.
throw e;
} catch (SignatureVerificationException e) {
// Could not verify signature of a token, possibly someone provided forged token.
throw e;
} catch (TokenExpiredException e) {
// We encountered old token, possibly replay attack.
throw e;
} catch (InvalidClaimException e) {
// Different Audience for token and for verification, possibly token for other verifier.
throw e;
} catch (JWTVerificationException e) {
// - InvalidClaimException
throw e;
}
}
use of com.auth0.jwt.exceptions.TokenExpiredException in project neubbs by nuitcoder.
the class SecretUtil method decryptUserInfoToken.
/**
* 解密用户信息 Token
* - 解密 JWT 生成的用户信息 Token, 获取 UserDO 对象
*
* @param token 密文 token
* @return UserDO 用户信息对象(包含 id,name,rank,state 属性)
*/
public static UserDO decryptUserInfoToken(String token) {
checkParamNotNull(token);
DecodedJWT decodedJWT;
try {
// decrypt HS256
JWTVerifier verifier = JWT.require(Algorithm.HMAC256(SetConst.JWT_TOKEN_SECRET_KEY)).build();
// decoding Base64
decodedJWT = verifier.verify(token);
} catch (UnsupportedEncodingException | TokenExpiredException e) {
throw new UtilClassException(ApiMessage.UNKNOWN_ERROR).log(LogWarnEnum.UC10);
}
// Get User information(id, name, rank ,state)
UserDO user = new UserDO();
user.setId(decodedJWT.getClaim(ParamConst.ID).asInt());
user.setName(decodedJWT.getClaim(ParamConst.NAME).asString());
user.setRank(decodedJWT.getClaim(ParamConst.RANK).asString());
user.setState(decodedJWT.getClaim(ParamConst.STATE).asInt());
return user;
}
Aggregations