diff --git a/bom/application/pom.xml b/bom/application/pom.xml index 7acd0a5f7ff49..7061ce41ff0ee 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -45,7 +45,7 @@ 2.4.4 3.1.1 3.0.1 - 2.1.12 + 2.1.13 1.3.2 2.0.1 5.2.1 diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevConsoleProcessor.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevConsoleProcessor.java index 6404c3ba67be7..0d87d345f67ad 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevConsoleProcessor.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevConsoleProcessor.java @@ -3,6 +3,8 @@ import java.util.Map; import java.util.Optional; +import io.quarkus.deployment.Capabilities; +import io.quarkus.deployment.Capability; import io.quarkus.deployment.IsDevelopment; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; @@ -20,7 +22,8 @@ public class KeycloakDevConsoleProcessor { @BuildStep(onlyIf = IsDevelopment.class) @Consume(RuntimeConfigSetupCompleteBuildItem.class) public void setConfigProperties(BuildProducer console, - Optional configProps) { + Optional configProps, + Capabilities capabilities) { if (configProps.isPresent() && configProps.get().getProperties().containsKey("keycloak.url")) { String keycloakUrl = (String) configProps.get().getProperties().get("keycloak.url"); String realmUrl = keycloakUrl + "/realms/" + configProps.get().getProperties().get("keycloak.realm"); @@ -41,6 +44,9 @@ public void setConfigProperties(BuildProducer c new DevConsoleTemplateInfoBuildItem("authorizationUrl", realmUrl + "/protocol/openid-connect/auth")); console.produce(new DevConsoleTemplateInfoBuildItem("logoutUrl", realmUrl + "/protocol/openid-connect/logout")); console.produce(new DevConsoleTemplateInfoBuildItem("oidcGrantType", config.devservices.grant.type.getGrantType())); + console.produce(new DevConsoleTemplateInfoBuildItem("swaggerIsAvailable", + capabilities.isPresent(Capability.SMALLRYE_OPENAPI))); + } } diff --git a/extensions/oidc/deployment/src/main/resources/dev-templates/provider.html b/extensions/oidc/deployment/src/main/resources/dev-templates/provider.html index ff78e4b835361..b1c10670b2583 100644 --- a/extensions/oidc/deployment/src/main/resources/dev-templates/provider.html +++ b/extensions/oidc/deployment/src/main/resources/dev-templates/provider.html @@ -135,6 +135,32 @@ copyToClipboard(idToken,"dummyIdTokenClipBoard"); } + function navigateToSwaggerUi(){ + var url = "{config:http-path('quarkus.swagger-ui.path')}"; + + var authorizedValue = { + "SecurityScheme":{ + "schema":{ + "flow":"implicit", + "authorizationUrl":"{info:authorizationUrl}", + "tokenUrl":"{info:tokenUrl}", + "type":"oauth2", + "description":"Authentication" + }, + "clientId":"{info:clientId}", + "name":"SecurityScheme", + "token":{ + "access_token":accessToken, + "token_type":"Bearer", + "expires_in":"900" + } + } + }; + + localStorage.setItem('authorized', JSON.stringify(authorizedValue)); + window.open(url, '_blank').focus(); + } + function copyToClipboard(token, type){ var dummy = document.createElement("input"); document.body.appendChild(dummy); @@ -146,6 +172,8 @@ } function logout() { + localStorage.removeItem('authorized'); + window.location.assign('{info:logoutUrl??}' + "?post_logout_redirect_uri=" + "http%3A%2F%2Flocalhost%3A" + port + "%2Fq%2Fdev%2Fio.quarkus.quarkus-oidc%2Fprovider"); } @@ -374,7 +402,16 @@
Decoded

- Test your service +
+ Test your service +
+
+ {#if info:swaggerIsAvailable} + + Swagger UI + + {/if} +
diff --git a/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java b/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java index 2169e4b037e16..85188b2fff31b 100644 --- a/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java +++ b/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -15,6 +16,7 @@ import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Record; +import io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.GeneratedResourceBuildItem; import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem; @@ -51,6 +53,9 @@ public class SwaggerUiProcessor { private static final String BRANDING_FAVICON_GENERAL = BRANDING_DIR + "favicon.ico"; private static final String BRANDING_FAVICON_MODULE = BRANDING_DIR + "smallrye-open-api-ui.ico"; + // To autoset some security config from OIDC + private static final String OIDC_CLIENT_ID = "quarkus.oidc.client-id"; + @BuildStep void feature(BuildProducer feature, LaunchModeBuildItem launchMode, @@ -81,7 +86,8 @@ public void getSwaggerUiFinalDestination( LaunchModeBuildItem launchMode, SwaggerUiConfig swaggerUiConfig, SmallRyeOpenApiConfig openapi, - LiveReloadBuildItem liveReloadBuildItem) throws Exception { + LiveReloadBuildItem liveReloadBuildItem, + Optional devServicesLauncherConfig) throws Exception { if (shouldInclude(launchMode, swaggerUiConfig)) { if ("/".equals(swaggerUiConfig.path)) { @@ -96,6 +102,18 @@ public void getSwaggerUiFinalDestination( } + if (devServicesLauncherConfig.isPresent()) { + DevServicesLauncherConfigResultBuildItem devServicesLauncherConfigResult = devServicesLauncherConfig.get(); + Map devServiceConfig = devServicesLauncherConfigResult.getConfig(); + if (devServiceConfig != null && !devServiceConfig.isEmpty()) { + // Map client Id from OIDC Dev Services + if (devServiceConfig.containsKey(OIDC_CLIENT_ID) && !swaggerUiConfig.oauthClientId.isPresent()) { + String clientId = devServiceConfig.get(OIDC_CLIENT_ID); + swaggerUiConfig.oauthClientId = Optional.of(clientId); + } + } + } + String openApiPath = nonApplicationRootPathBuildItem.resolvePath(openapi.path); String swaggerUiPath = nonApplicationRootPathBuildItem.resolvePath(swaggerUiConfig.path); @@ -103,6 +121,12 @@ public void getSwaggerUiFinalDestination( SWAGGER_UI_WEBJAR_ARTIFACT_ID); if (launchMode.getLaunchMode().isDevOrTest()) { + + // In dev mode, default to persist Authorization true + if (!swaggerUiConfig.persistAuthorization.isPresent()) { + swaggerUiConfig.persistAuthorization = Optional.of(true); + } + Path tempPath = WebJarUtil.copyResourcesForDevOrTest(liveReloadBuildItem, curateOutcomeBuildItem, launchMode, artifact, SWAGGER_UI_WEBJAR_PREFIX);