use of com.auth0.jwt.exceptions.InvalidClaimException 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;
}
}
Aggregations