((OAuth2Auth) authProvider).decodeToken(token, decodeToken -> { if (decodeToken.failed()) { handler.handle(Future.failedFuture(new HttpStatusException(401, decodeToken.cause().getMessage())));
/** * Decode a token to a {@link io.vertx.rxjava.ext.auth.oauth2.AccessToken} object. This is useful to handle bearer JWT tokens. * @param token the access token (base64 string) * @param handler A handler to receive the event * @return self */ @Deprecated() public io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth decodeToken(String token, Handler<AsyncResult<io.vertx.rxjava.ext.auth.oauth2.AccessToken>> handler) { delegate.decodeToken(token, new Handler<AsyncResult<io.vertx.ext.auth.oauth2.AccessToken>>() { public void handle(AsyncResult<io.vertx.ext.auth.oauth2.AccessToken> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.auth.oauth2.AccessToken.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; }
/** * Decode a token to a {@link io.vertx.rxjava.ext.auth.oauth2.AccessToken} object. This is useful to handle bearer JWT tokens. * @param token the access token (base64 string) * @param handler A handler to receive the event * @return self */ @Deprecated() public io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth decodeToken(String token, Handler<AsyncResult<io.vertx.rxjava.ext.auth.oauth2.AccessToken>> handler) { delegate.decodeToken(token, new Handler<AsyncResult<io.vertx.ext.auth.oauth2.AccessToken>>() { public void handle(AsyncResult<io.vertx.ext.auth.oauth2.AccessToken> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.auth.oauth2.AccessToken.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; }
@Override public void parseCredentials(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) { parseAuthorization(context, true, parseAuthorization -> { if (parseAuthorization.failed()) { handler.handle(Future.failedFuture(parseAuthorization.cause())); return; } // Authorization header could be null as we mark it as optional final String token = parseAuthorization.result(); if (token == null) { context.next(); } else { // attempt to decode the token and handle it as a user ((OAuth2Auth) authProvider).decodeToken(token, decodeToken -> { if (decodeToken.failed()) { handler.handle(Future.failedFuture(new HttpStatusException(401, decodeToken.cause().getMessage()))); return; } context.setUser(decodeToken.result()); // continue handler.handle(Future.succeededFuture()); }); } }); }
((OAuth2Auth) authProvider).decodeToken(token, decodeToken -> { if (decodeToken.failed()) { handler.handle(Future.failedFuture(new HttpStatusException(401, decodeToken.cause().getMessage())));
@Ignore @Test public void testDecode() { OpenIDConnectAuth.discover( vertx, new OAuth2ClientOptions() .setClientID("vertx") .setSite("http://localhost:8080/auth/realms/master"), res -> { if (res.failed()) { fail(res.cause()); return; } final OAuth2Auth oidc = res.result(); oidc.decodeToken("borked", res1 -> { if (res1.failed()) { testComplete(); return; } fail("Should not reach this!"); }); }); await(); } }