/** * Refresh the access token * @param callback - The callback function returning the results. * @return */ public io.vertx.rxjava.ext.auth.oauth2.AccessToken refresh(Handler<AsyncResult<Void>> callback) { delegate.refresh(callback); return this; }
/** * Refresh the access token * @param callback - The callback function returning the results. * @return */ public io.vertx.rxjava.ext.auth.oauth2.AccessToken refresh(Handler<AsyncResult<Void>> callback) { delegate.refresh(callback); return this; }
@Test public void shouldRefreshAToken(TestContext should) { final Async test = should.async(); keycloak.authenticate(new JsonObject().put("username", "test-user").put("password", "tiger"), authn -> { should.assertTrue(authn.succeeded()); should.assertNotNull(authn.result()); // generate a access token from the user AccessToken token = (AccessToken) authn.result(); final String origToken = token.opaqueAccessToken(); token.refresh(refresh -> { should.assertTrue(refresh.succeeded()); should.assertNotEquals(origToken, token.opaqueAccessToken()); test.complete(); }); }); }
@Test public void whenRefreshingTokenShouldGetNewAccessToken() { config = oauthConfig; oauth2.authenticate(tokenConfig, res -> { if (res.failed()) { fail(res.cause().getMessage()); } else { AccessToken token = (AccessToken) res.result(); final long origTTl = token.principal().getLong("expires_at"); // refresh the token config = refreshConfig; token.refresh(v -> { if (v.failed()) { fail(v.cause().getMessage()); } else { assertTrue(origTTl < token.principal().getLong("expires_at")); testComplete(); } }); } }); await(); }