Skip to content

Commit

Permalink
Skip OIDC DevConsole setup if quarkus.oidc.auth-server-url can not be…
Browse files Browse the repository at this point in the history
… accessed at build time
  • Loading branch information
sberyozkin committed Dec 23, 2021
1 parent 3d73f32 commit dcec760
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ public void run() {
closeBuildItem.addCloseTask(closeTask, true);
}

String authServerUrl = getConfigProperty(AUTH_SERVER_URL_CONFIG_KEY);
String authServerUrl = null;
try {
authServerUrl = getConfigProperty(AUTH_SERVER_URL_CONFIG_KEY);
} catch (Exception ex) {
// It is not possible to initialize OIDC Dev Console UI without being able to access this property at the build time
return;
}
JsonObject metadata = null;
if (isDiscoveryEnabled()) {
metadata = discoverMetadata(authServerUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@

function signInToOidcProviderAndGetTokens() {
{#if info:oidcGrantType is 'implicit'}
window.location.href = '{info:authorizationUrl}'
window.location.href = '{info:authorizationUrl??}'
+ "?client_id=" + '{info:clientId}'
+ "&redirect_uri=" + "http%3A%2F%2Flocalhost%3A" + port + encodedDevRoot + "%2Fio.quarkus.quarkus-oidc%2Fprovider"
+ "&scope=openid&response_type=token id_token&response_mode=query&prompt=login"
+ "&nonce=" + makeid();
{#else}
window.location.href = '{info:authorizationUrl}'
window.location.href = '{info:authorizationUrl??}'
+ "?client_id=" + '{info:clientId}'
+ "&redirect_uri=" + "http%3A%2F%2Flocalhost%3A" + port + encodedDevRoot + "%2Fio.quarkus.quarkus-oidc%2Fprovider"
+ "&scope=openid&response_type=code&response_mode=query&prompt=login"
Expand Down Expand Up @@ -193,7 +193,7 @@
function exchangeCodeForTokens(code){
$.post("exchangeCodeForTokens",
{
tokenUrl: '{info:tokenUrl}',
tokenUrl: '{info:tokenUrl??}',
client: '{info:clientId}',
clientSecret: '{info:clientSecret}',
authorizationCode: code,
Expand Down Expand Up @@ -258,7 +258,7 @@
function testServiceWithPassword(userName, password, servicePath){
$.post("testService",
{
tokenUrl: '{info:tokenUrl}',
tokenUrl: '{info:tokenUrl??}',
serviceUrl: "http://localhost:" + port + servicePath,
client: '{info:clientId}',
clientSecret: '{info:clientSecret}',
Expand All @@ -274,7 +274,7 @@
function testServiceWithPasswordInSwaggerUi(userName, password){
$.post("testService",
{
tokenUrl: '{info:tokenUrl}',
tokenUrl: '{info:tokenUrl??}',
client: '{info:clientId}',
clientSecret: '{info:clientSecret}',
user: userName,
Expand All @@ -289,7 +289,7 @@
function testServiceWithPasswordInGraphQLUi(userName){
$.post("testService",
{
tokenUrl: '{info:tokenUrl}',
tokenUrl: '{info:tokenUrl??}',
client: '{info:clientId}',
clientSecret: '{info:clientSecret}',
user: userName,
Expand All @@ -305,7 +305,7 @@
function testServiceWithClientCredentials(servicePath) {
$.post("testService",
{
tokenUrl: '{info:tokenUrl}',
tokenUrl: '{info:tokenUrl??}',
serviceUrl: "http://localhost:" + port + servicePath,
client: '{info:clientId}',
clientSecret: '{info:clientSecret}',
Expand All @@ -318,7 +318,7 @@
function testServiceWithClientCredentialsInSwaggerUi(){
$.post("testService",
{
tokenUrl: '{info:tokenUrl}',
tokenUrl: '{info:tokenUrl??}',
client: '{info:clientId}',
clientSecret: '{info:clientSecret}',
grant: '{info:oidcGrantType}'
Expand All @@ -331,7 +331,7 @@
function testServiceWithClientCredentialsInGraphQLUi(){
$.post("testService",
{
tokenUrl: '{info:tokenUrl}',
tokenUrl: '{info:tokenUrl??}',
client: '{info:clientId}',
clientSecret: '{info:clientSecret}',
grant: '{info:oidcGrantType}'
Expand All @@ -350,8 +350,8 @@
"SecurityScheme":{
"schema":{
"flow":"implicit",
"authorizationUrl":"{info:authorizationUrl}",
"tokenUrl":"{info:tokenUrl}",
"authorizationUrl":"{info:authorizationUrl??}",
"tokenUrl":"{info:tokenUrl??}",
"type":"oauth2",
"description":"Authentication"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ public String get() {
if (defaultValue != null || END_SESSION_PATH_KEY.equals(oidcConfigProperty)) {
Optional<String> value = ConfigProvider.getConfig().getOptionalValue(oidcConfigProperty, String.class);
if (value.isPresent()) {
return checkUrlProperty(value.get());
return checkUrlProperty(value);
}
return defaultValue;
} else {
return checkUrlProperty(ConfigProvider.getConfig().getValue(oidcConfigProperty, String.class));
return checkUrlProperty(ConfigProvider.getConfig().getOptionalValue(oidcConfigProperty, String.class));
}
}

private String checkUrlProperty(String value) {
if (urlProperty && !value.startsWith("http:")) {
String authServerUrl = ConfigProvider.getConfig().getValue(AUTH_SERVER_URL_CONFIG_KEY, String.class);
return OidcCommonUtils.getOidcEndpointUrl(authServerUrl, Optional.of(value));
} else {
return value;
private String checkUrlProperty(Optional<String> value) {
if (urlProperty && value.isPresent() && !value.get().startsWith("http:")) {
Optional<String> authServerUrl = ConfigProvider.getConfig().getOptionalValue(AUTH_SERVER_URL_CONFIG_KEY,
String.class);
return authServerUrl.isPresent() ? OidcCommonUtils.getOidcEndpointUrl(authServerUrl.get(), value) : null;
}
return value.orElse(null);
}

public String getOidcConfigProperty() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.quarkus.test.devconsole;

import org.hamcrest.Matchers;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;

/**
* Note that this test cannot be placed under the relevant {@code -deployment} module because then the DEV UI processor would
* not be able to locate the template resources correctly.
*/
public class DevConsoleOidcNoDiscoverySmokeTest {

@RegisterExtension
static final QuarkusDevModeTest config = new QuarkusDevModeTest()
.withApplicationRoot((jar) -> jar.addAsResource(createApplicationProperties(),
"application.properties"));

@Test
public void testOidcProviderTemplate() {
RestAssured.get("q/dev/io.quarkus.quarkus-oidc/provider")
.then()
.statusCode(200).body(Matchers.containsString("OpenId Connect Dev Console"));
}

private static StringAsset createApplicationProperties() {
return new StringAsset("quarkus.oidc.auth-server-url=http://localhost/oidc\n"
+ "quarkus.oidc.client-id=client\n"
+ "quarkus.oidc.discovery-enabled=false\n"
+ "quarkus.oidc.introspection-path=introspect\n");

}
}

0 comments on commit dcec760

Please sign in to comment.