use of com.auth0.android.jwt.Claim in project data-transfer-project by google.
the class JWTTokenManager method getJobIdFromToken.
@Override
public UUID getJobIdFromToken(String token) {
try {
DecodedJWT jwt = verifier.verify(token);
// Token is verified, get claim
Claim claim = jwt.getClaim(JWTTokenManager.ID_CLAIM_KEY);
if (claim.isNull()) {
return null;
}
return claim.isNull() ? null : UUID.fromString(claim.asString());
} catch (JWTVerificationException exception) {
logger.debug("Error verifying token: {}", exception);
throw new RuntimeException("Error verifying token: " + token);
}
}
use of com.auth0.android.jwt.Claim in project data-transfer-project by google.
the class JWTTokenManager method getJobIdFromToken.
@Override
public UUID getJobIdFromToken(String token) {
try {
DecodedJWT jwt = verifier.verify(token);
// Token is verified, get claim
Claim claim = jwt.getClaim(JWTTokenManager.ID_CLAIM_KEY);
if (claim.isNull()) {
return null;
}
return claim.isNull() ? null : UUID.fromString(claim.asString());
} catch (JWTVerificationException exception) {
monitor.debug(() -> "Error verifying token", exception);
throw new RuntimeException("Error verifying token: " + token);
}
}
use of com.auth0.android.jwt.Claim in project conWasteJiNing by Yingjie-tian.
the class JwtUtils method verifyToken.
/**
* 解密jwt
* @param token
* @return
* @throws RuntimeException
*/
public static Map<String, String> verifyToken(String token) throws RuntimeException {
Algorithm algorithm = null;
try {
// 使用HMAC256进行加密
algorithm = Algorithm.HMAC256(SECRET);
} catch (IllegalArgumentException | UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
// 解密
JWTVerifier verifier = JWT.require(algorithm).withIssuer(ISSUER).build();
DecodedJWT jwt = verifier.verify(token);
Map<String, Claim> map = jwt.getClaims();
Map<String, String> resultMap = new HashMap<>();
map.forEach((k, v) -> resultMap.put(k, v.asString()));
return resultMap;
}
use of com.auth0.android.jwt.Claim in project opencast by opencast.
the class JWTVerifierTest method testVerifySymmetric.
@Test
public void testVerifySymmetric() {
// Valid JWT + valid claim constraints
DecodedJWT decodedJWT = JWTVerifier.verify(generator.generateValidSymmetricJWT(), generator.getSecret(), generator.generateValidClaimConstraints());
assertEquals(generator.getUsername(), decodedJWT.getClaim("username").asString());
// Valid JWT + invalid claim constraints
assertThrows(JWTVerificationException.class, () -> JWTVerifier.verify(generator.generateValidSymmetricJWT(), generator.getSecret(), generator.generateInvalidClaimConstraints()));
// Valid JWT + invalid secret
assertThrows(JWTVerificationException.class, () -> JWTVerifier.verify(generator.generateValidSymmetricJWT(), "abc", generator.generateValidClaimConstraints()));
// Invalid JWT
assertThrows(JWTVerificationException.class, () -> JWTVerifier.verify(generator.generateExpiredSymmetricJWT(), generator.getSecret(), generator.generateValidClaimConstraints()));
}
use of com.auth0.android.jwt.Claim in project opencast by opencast.
the class JWTVerifier method verify.
/**
* Verifies a given JWT string with a secret and given claim constraints.
*
* @param token The JWT string.
* @param secret The secret.
* @param claimConstraints The claim constraints.
* @return The decoded and verified JWT.
* @throws JWTVerificationException If the JWT cannot be verified successfully.
*/
public static DecodedJWT verify(String token, String secret, List<String> claimConstraints) throws JWTVerificationException {
Assert.notNull(token, "A token must be set");
Assert.isTrue(StringUtils.isNotBlank(secret), "A secret must be set");
DecodedJWT jwt = JWT.decode(token);
return verify(jwt, claimConstraints, AlgorithmBuilder.buildAlgorithm(jwt, secret));
}
Aggregations