AccessToken user = (AccessToken) ctx.user(); user.userInfo(res -> { if (res.failed()) {
/** * Load the user info as per OIDC spec. * @param callback - The callback function returning the results. * @return */ public io.vertx.rxjava.ext.auth.oauth2.AccessToken userInfo(Handler<AsyncResult<JsonObject>> callback) { delegate.userInfo(callback); return this; }
/** * Load the user info as per OIDC spec. * @param callback - The callback function returning the results. * @return */ public io.vertx.rxjava.ext.auth.oauth2.AccessToken userInfo(Handler<AsyncResult<JsonObject>> callback) { delegate.userInfo(callback); return this; }
public static io.vertx.ext.auth.oauth2.AccessToken userInfo(io.vertx.ext.auth.oauth2.AccessToken j_receiver, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> callback) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.userInfo(callback != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.core.json.JsonObject>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.core.json.JsonObject> ar) { callback.handle(ar.map(event -> io.vertx.core.impl.ConversionHelper.fromJsonObject(event))); } } : null)); return j_receiver; } public static io.vertx.ext.auth.oauth2.AccessToken fetch(io.vertx.ext.auth.oauth2.AccessToken j_receiver, io.vertx.core.http.HttpMethod method, java.lang.String resource, java.util.Map<String, Object> headers, io.vertx.core.buffer.Buffer payload, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.auth.oauth2.OAuth2Response>> callback) {
@Test public void getUserInfo() { final AccessToken accessToken = new OAuth2TokenImpl((OAuth2AuthProviderImpl) oauth2, new JsonObject("{\"access_token\":\"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJhdXRob3JpemF0aW9uIjp7InBlcm1pc3Npb25zIjpbeyJyZXNvdXJjZV9zZXRfaWQiOiJkMmZlOTg0My02NDYyLTRiZmMtYmFiYS1iNTc4N2JiNmUwZTciLCJyZXNvdXJjZV9zZXRfbmFtZSI6IkhlbGxvIFdvcmxkIFJlc291cmNlIn1dfSwianRpIjoiZDYxMDlhMDktNzhmZC00OTk4LWJmODktOTU3MzBkZmQwODkyLTE0NjQ5MDY2Nzk0MDUiLCJleHAiOjk5OTk5OTk5OTksIm5iZiI6MCwiaWF0IjoxNDY0OTA2NjcxLCJzdWIiOiJmMTg4OGY0ZC01MTcyLTQzNTktYmUwYy1hZjMzODUwNWQ4NmMiLCJ0eXAiOiJrY19ldHQiLCJhenAiOiJoZWxsby13b3JsZC1hdXRoei1zZXJ2aWNlIn0\",\"active\":true,\"scope\":\"scopeA scopeB\",\"client_id\":\"client-id\",\"username\":\"username\",\"token_type\":\"bearer\",\"expires_at\":99999999999000}")); accessToken.userInfo(userInfo -> { if (userInfo.failed()) { fail(userInfo.cause().getMessage()); } else { testComplete(); } }); await(); }
@Test public void getUserInfoWithParams() { final AccessToken accessToken = new OAuth2TokenImpl((OAuth2AuthProviderImpl) oauth2, new JsonObject("{\"access_token\":\"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJhdXRob3JpemF0aW9uIjp7InBlcm1pc3Npb25zIjpbeyJyZXNvdXJjZV9zZXRfaWQiOiJkMmZlOTg0My02NDYyLTRiZmMtYmFiYS1iNTc4N2JiNmUwZTciLCJyZXNvdXJjZV9zZXRfbmFtZSI6IkhlbGxvIFdvcmxkIFJlc291cmNlIn1dfSwianRpIjoiZDYxMDlhMDktNzhmZC00OTk4LWJmODktOTU3MzBkZmQwODkyLTE0NjQ5MDY2Nzk0MDUiLCJleHAiOjk5OTk5OTk5OTksIm5iZiI6MCwiaWF0IjoxNDY0OTA2NjcxLCJzdWIiOiJmMTg4OGY0ZC01MTcyLTQzNTktYmUwYy1hZjMzODUwNWQ4NmMiLCJ0eXAiOiJrY19ldHQiLCJhenAiOiJoZWxsby13b3JsZC1hdXRoei1zZXJ2aWNlIn0\",\"active\":true,\"scope\":\"scopeA scopeB\",\"client_id\":\"client-id\",\"username\":\"username\",\"token_type\":\"bearer\",\"expires_at\":99999999999000}")); accessToken.userInfo(userInfo -> { if (userInfo.failed()) { fail(userInfo.cause().getMessage()); } else { assertEquals(fixture, userInfo.result()); testComplete(); } }); await(); } }
@Test public void shouldLoadTheUserInfo(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(); token.userInfo(userinfo -> { should.assertTrue(userinfo.succeeded()); should.assertNotNull(userinfo.result()); should.assertEquals("test-user", userinfo.result().getString("preferred_username")); test.complete(); }); }); }
assertNotNull(token.refreshToken()); token.userInfo(res2 -> { if (res2.failed()) { fail(res2.cause().getMessage());