/** * Create a OAuth2Auth provider for Keycloak * * @param config the json config file exported from Keycloak admin console * @param httpClientOptions custom http client options */ static OAuth2Auth create(Vertx vertx, JsonObject config, HttpClientOptions httpClientOptions) { return create(vertx, OAuth2FlowType.AUTH_CODE, config, httpClientOptions); }
/** * Create a OAuth2Auth provider for Keycloak * * @param config the json config file exported from Keycloak admin console */ static OAuth2Auth create(Vertx vertx, JsonObject config) { return create(vertx, OAuth2FlowType.AUTH_CODE, config); }
/** * Create a OAuth2Auth provider for Keycloak * * @param flow the oauth2 flow to use * @param config the json config file exported from Keycloak admin console */ static OAuth2Auth create(Vertx vertx, OAuth2FlowType flow, JsonObject config) { return create(vertx, flow, config, new HttpClientOptions()); }
public static io.vertx.ext.auth.oauth2.OAuth2Auth create(io.vertx.ext.auth.oauth2.providers.KeycloakAuth j_receiver, io.vertx.core.Vertx vertx, io.vertx.ext.auth.oauth2.OAuth2FlowType flow, java.util.Map<String, Object> config) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.auth.oauth2.providers.KeycloakAuth.create(vertx, flow, config != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(config) : null)); } public static io.vertx.ext.auth.oauth2.OAuth2Auth create(io.vertx.ext.auth.oauth2.providers.KeycloakAuth j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> config, java.util.Map<String, Object> httpClientOptions) {
/** * Create a OAuth2Auth provider for Keycloak * @param vertx * @param flow the oauth2 flow to use * @param config the json config file exported from Keycloak admin console * @return */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, OAuth2FlowType flow, JsonObject config) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.providers.KeycloakAuth.create(vertx.getDelegate(), flow, config)); return ret; }
/** * Create a OAuth2Auth provider for Keycloak * @param vertx * @param flow the oauth2 flow to use * @param config the json config file exported from Keycloak admin console * @param httpClientOptions custom http client options * @return */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, OAuth2FlowType flow, JsonObject config, HttpClientOptions httpClientOptions) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.providers.KeycloakAuth.create(vertx.getDelegate(), flow, config, httpClientOptions)); return ret; }
/** * Create a OAuth2Auth provider for Keycloak * @param vertx * @param config the json config file exported from Keycloak admin console * @return */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, JsonObject config) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.providers.KeycloakAuth.create(vertx.getDelegate(), config)); return ret; }
/** * Create a OAuth2Auth provider for Keycloak * @param vertx * @param flow the oauth2 flow to use * @param config the json config file exported from Keycloak admin console * @param httpClientOptions custom http client options * @return */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, OAuth2FlowType flow, JsonObject config, HttpClientOptions httpClientOptions) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.providers.KeycloakAuth.create(vertx.getDelegate(), flow, config, httpClientOptions)); return ret; }
/** * Create a OAuth2Auth provider for Keycloak * @param vertx * @param config the json config file exported from Keycloak admin console * @return */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, JsonObject config) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.providers.KeycloakAuth.create(vertx.getDelegate(), config)); return ret; }
/** * Create a OAuth2Auth provider for Keycloak * @param vertx * @param config the json config file exported from Keycloak admin console * @param httpClientOptions custom http client options * @return */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, JsonObject config, HttpClientOptions httpClientOptions) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.providers.KeycloakAuth.create(vertx.getDelegate(), config, httpClientOptions)); return ret; }
public static io.vertx.ext.auth.oauth2.OAuth2Auth create(io.vertx.ext.auth.oauth2.providers.KeycloakAuth j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> config) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.auth.oauth2.providers.KeycloakAuth.create(vertx, config != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(config) : null)); } public static io.vertx.ext.auth.oauth2.OAuth2Auth create(io.vertx.ext.auth.oauth2.providers.KeycloakAuth j_receiver, io.vertx.core.Vertx vertx, io.vertx.ext.auth.oauth2.OAuth2FlowType flow, java.util.Map<String, Object> config) {
/** * Create a OAuth2Auth provider for Keycloak * @param vertx * @param flow the oauth2 flow to use * @param config the json config file exported from Keycloak admin console * @return */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, OAuth2FlowType flow, JsonObject config) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.providers.KeycloakAuth.create(vertx.getDelegate(), flow, config)); return ret; }
/** * Create a OAuth2Auth provider for Keycloak * @param vertx * @param config the json config file exported from Keycloak admin console * @param httpClientOptions custom http client options * @return */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, JsonObject config, HttpClientOptions httpClientOptions) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.providers.KeycloakAuth.create(vertx.getDelegate(), config, httpClientOptions)); return ret; }
public static io.vertx.ext.auth.oauth2.OAuth2Auth create(io.vertx.ext.auth.oauth2.providers.KeycloakAuth j_receiver, io.vertx.core.Vertx vertx, io.vertx.ext.auth.oauth2.OAuth2FlowType flow, java.util.Map<String, Object> config, java.util.Map<String, Object> httpClientOptions) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.auth.oauth2.providers.KeycloakAuth.create(vertx, flow, config != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(config) : null, httpClientOptions != null ? new io.vertx.core.http.HttpClientOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(httpClientOptions)) : null)); } public static void discover(io.vertx.ext.auth.oauth2.providers.KeycloakAuth j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> config, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.auth.oauth2.OAuth2Auth>> handler) {
private static OAuth2AuthHandler standardAuth(Vertx vertx, Router router, VertxEngineConfig apimanConfig, JsonObject authConfig, OAuth2FlowType flowType) { String proto = apimanConfig.isSSL() ? "https://" : "http://"; int port = apimanConfig.getPort(ApiVerticle.VERTICLE_TYPE); String hostname = Optional.of(apimanConfig.getPublicEndpoint()).orElse(apimanConfig.getHostname()); String redirect = proto + hostname + ":" + port; // Redirect back here to *after* auth. // Set up KC OAuth2 Authentication OAuth2AuthHandler auth = OAuth2AuthHandler.create(KeycloakAuth.create(vertx, flowType, authConfig), redirect); // Callback can be anything (as long as it's not already used by something else). auth.setupCallback(router.get("/callback")); return auth; }
public static io.vertx.ext.auth.oauth2.OAuth2Auth create(io.vertx.ext.auth.oauth2.providers.KeycloakAuth j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> config, java.util.Map<String, Object> httpClientOptions) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.auth.oauth2.providers.KeycloakAuth.create(vertx, config != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(config) : null, httpClientOptions != null ? new io.vertx.core.http.HttpClientOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(httpClientOptions)) : null)); } public static io.vertx.ext.auth.oauth2.OAuth2Auth create(io.vertx.ext.auth.oauth2.providers.KeycloakAuth j_receiver, io.vertx.core.Vertx vertx, io.vertx.ext.auth.oauth2.OAuth2FlowType flow, java.util.Map<String, Object> config, java.util.Map<String, Object> httpClientOptions) {
@Inject public MeshOAuth2ServiceImpl(Database db, BootstrapInitializer boot, MeshOptions meshOptions, Vertx vertx, SearchQueue searchQueue) { this.db = db; this.boot = boot; this.options = meshOptions.getAuthenticationOptions().getOauth2(); this.searchQueue = searchQueue; if (options == null || !options.isEnabled()) { return; } JsonObject config = loadRealmInfo(vertx, meshOptions); this.mapperScript = loadScript(); this.oauth2Provider = KeycloakAuth.create(vertx, OAuth2FlowType.AUTH_CODE, config); this.oauth2Handler = new MeshOAuth2AuthHandlerImpl(oauth2Provider); }
@Test public void loadUser() { OAuth2Auth provider = KeycloakAuth.create(Vertx.vertx(), OAuth2FlowType.AUTH_CODE, keycloakConfig); OAuth2TokenImpl user = new OAuth2TokenImpl(); System.out.println(keycloakToken.length()); user.readFromBuffer(0, Buffer.buffer().appendInt(0).appendInt(keycloakToken.length()).appendString(keycloakToken)); user.setAuthProvider(provider); } }
@Test public void testNullScope() throws Exception { super.setUp(); oauth2 = KeycloakAuth.create(vertx, OAuth2FlowType.AUTH_CODE, keycloakConfig); JsonObject json = new JsonObject( "{\n" + " \"access_token\":\"xyz\",\n" + " \"expires_in\":60,\n" + " \"token_type\":\"bearer\",\n" + " \"not-before-policy\":0,\n" + " \"scope\":null\n" + "}" ); try { OAuth2TokenImpl token = new OAuth2TokenImpl((OAuth2AuthProviderImpl) oauth2, json); } catch (RuntimeException e) { fail(); } } }
@Test public void keycloakTest() throws Exception { super.setUp(); oauth2 = KeycloakAuth.create(vertx, OAuth2FlowType.AUTH_CODE, keycloakConfig); OAuth2TokenImpl token = new OAuth2TokenImpl((OAuth2AuthProviderImpl) oauth2, keycloakToken); assertNotNull(token.opaqueAccessToken()); assertNotNull(token.opaqueRefreshToken()); assertNull(token.accessToken()); // trust it token.setTrustJWT(true); assertNotNull(token.accessToken()); }