Search in sources :

Example 1 with InvalidClaimException

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;
    }
}
Also used : JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) TokenExpiredException(com.auth0.jwt.exceptions.TokenExpiredException) TokenVerifier(com.example.compute.signedmetadata.token.TokenVerifier) DecodedGoogleJWTWrapper(com.example.compute.signedmetadata.token.DecodedGoogleJWTWrapper) SignatureVerificationException(com.auth0.jwt.exceptions.SignatureVerificationException) InvalidClaimException(com.auth0.jwt.exceptions.InvalidClaimException) AlgorithmMismatchException(com.auth0.jwt.exceptions.AlgorithmMismatchException)

Aggregations

AlgorithmMismatchException (com.auth0.jwt.exceptions.AlgorithmMismatchException)1 InvalidClaimException (com.auth0.jwt.exceptions.InvalidClaimException)1 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)1 SignatureVerificationException (com.auth0.jwt.exceptions.SignatureVerificationException)1 TokenExpiredException (com.auth0.jwt.exceptions.TokenExpiredException)1 DecodedGoogleJWTWrapper (com.example.compute.signedmetadata.token.DecodedGoogleJWTWrapper)1 TokenVerifier (com.example.compute.signedmetadata.token.TokenVerifier)1