vertx-auth
vertx-auth copied to clipboard
What for method throws unnecessary runtime exception?
AccessToken interface of the vert.x-auth-oauth2 library has a method named expired. Its implementation (OAuth2TokenImpl) delegates token expiration checking to JWT.
I want to check token expiration and refresh it if necessary, but JWT throws a RuntimeException instead of returning true if now() time is more then expiration time.
https://github.com/vert-x3/vertx-auth/blob/de01ad72cae94cdc8d4f7b4440b0ab0476a3a51a/vertx-jwt/src/main/java/io/vertx/ext/jwt/JWT.java#L318
The intention is evidently to provide the reason why the JWT is expired, however, I agree that it's awkward.
JWTAuthProviderImpl has this strange block which will never return because isExpired() cannot return true:
https://github.com/vert-x3/vertx-auth/blob/a6c7e40e561c52eea68f0e2acada269fa94f7b34/vertx-auth-jwt/src/main/java/io/vertx/ext/auth/jwt/impl/JWTAuthProviderImpl.java#L124-L127
Instead, the whole thing is wrapped in a try/catch block: https://github.com/vert-x3/vertx-auth/blob/a6c7e40e561c52eea68f0e2acada269fa94f7b34/vertx-auth-jwt/src/main/java/io/vertx/ext/auth/jwt/impl/JWTAuthProviderImpl.java#L152-L154
The call to isExpired() seems to be the only thing that throws a RuntimeException in that block.
OAuthUser2Impl also has a strange check which merely logs the exception: https://github.com/vert-x3/vertx-auth/blob/ac1cd2b4810ea7fa7ebe2bb3bec5d51590e8b343/vertx-auth-oauth2/src/main/java/io/vertx/ext/auth/oauth2/impl/OAuth2UserImpl.java#L237-L243
Perhaps just replacing the exceptions in JWT with log statements and returning true?
This code has been refactored in 4.x and behavior is changed.