Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,18 @@ protected static CardPageBuildItem createProviderWebComponent(OidcDevUiRecorder
graphqlUiPath = null;
}

final String devUiLogoutPath = nonApplicationRootPathBuildItem.resolvePath("io.quarkus.quarkus-oidc/logout");
final String devUiReadSessionCookiePath = nonApplicationRootPathBuildItem
.resolvePath("io.quarkus.quarkus-oidc/readSessionCookie");

cardPage.addBuildTimeData("devRoot", nonApplicationRootPathBuildItem.getNonApplicationRootPath());

RuntimeValue<OidcDevUiRpcSvcPropertiesBean> runtimeProperties = recorder.getRpcServiceProperties(
authorizationUrl, tokenUrl, logoutUrl, webClientTimeout, grantOptions,
keycloakUsers, oidcProviderName, oidcApplicationType, oidcGrantType,
introspectionIsAvailable, keycloakAdminUrl, keycloakRealms, swaggerIsAvailable,
graphqlIsAvailable, swaggerUiPath, graphqlUiPath, alwaysLogoutUserInDevUiOnReload, discoverMetadata,
authServerUrl);
authServerUrl, devUiLogoutPath, devUiReadSessionCookiePath);

recorder.createJsonRPCService(beanContainer.getValue(), runtimeProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class OidcPropertiesState extends LitState {
propertiesStateId: null,
testServiceResponses: null,
webAppLoginObserver: null,
isWebApp: false
isWebApp: false,
logoutPath: null,
readSessionCookiePath: null
};
}

Expand Down Expand Up @@ -88,6 +90,8 @@ class OidcPropertiesState extends LitState {
propertiesState.keycloakRealms = response.result.keycloakRealms;
propertiesState.swaggerUiPath = response.result.swaggerUiPath;
propertiesState.graphqlUiPath = response.result.graphqlUiPath;
propertiesState.logoutPath = response.result.logoutPath;
propertiesState.readSessionCookiePath = response.result.readSessionCookiePath;

return {
// logout === true will trigger query params removal
Expand Down Expand Up @@ -257,7 +261,6 @@ export class QwcOidcProvider extends QwcHotReloadElement {
constructor() {
super();
this._devRoot = (devRoot?.replaceAll('/', '%2F') ?? '') + 'dev-ui'; // e.g. /q/dev-ui

this._selectedRealm = null;
this._servicePath = '/';
this._selectedClientId = null;
Expand Down Expand Up @@ -390,7 +393,7 @@ export class QwcOidcProvider extends QwcHotReloadElement {
}

_signInToService() {
window.open("http://localhost:" + propertiesState.httpPort + this._servicePath);
window.open(QwcOidcProvider._toServiceUrl(this._servicePath));
}

static _isServiceOrHybridApp() {
Expand Down Expand Up @@ -914,8 +917,7 @@ export class QwcOidcProvider extends QwcHotReloadElement {
_getEncodedPath() {
// this is the last part of this path: /q/dev-ui/io.quarkus.quarkus-oidc/keycloak-provider -> keycloak-provider
const subPath = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1);
return "http%3A%2F%2Flocalhost%3A" + propertiesState.httpPort + this._devRoot
+ "%2Fio.quarkus.quarkus-oidc%2F" + subPath;
return QwcOidcProvider._getEncodedCurrentBaseUrl() + this._devRoot + "%2Fio.quarkus.quarkus-oidc%2F" + subPath;
}

_getClientId() {
Expand Down Expand Up @@ -1091,7 +1093,7 @@ export class QwcOidcProvider extends QwcHotReloadElement {
tokenUrl = tokenUrl.substring(0, index + 8) + parts[1] + "/protocol/openid-connect/token";
clientId = parts[2];
}
const redirectUri = "http://localhost:" + propertiesState.httpPort + window.location.pathname;
const redirectUri = QwcOidcProvider._getCurrentBaseUrl() + window.location.pathname;
const clientSecret = propertiesState.clientSecret;
jsonRpc
.exchangeCodeForTokens({tokenUrl, clientId, clientSecret, authorizationCode, redirectUri})
Expand Down Expand Up @@ -1175,10 +1177,16 @@ export class QwcOidcProvider extends QwcHotReloadElement {
});
}

static _getEncodedCurrentBaseUrl() {
return QwcOidcProvider._getCurrentBaseUrl().replaceAll('/', '%2F').replaceAll(':', '%3A')
}

static _getCurrentBaseUrl() {
return window.location.origin
}

static _checkSessionCookie(jsonRpc, onLoggedIn, onLoggedOut) {
// FIXME: hardcoded path?
const port = propertiesState.httpPort ?? 8080
fetch("http://localhost:" + port + "/q/io.quarkus.quarkus-oidc/readSessionCookie")
fetch(QwcOidcProvider._getCurrentBaseUrl() + propertiesState.readSessionCookiePath)
.then(response => response.json())
.then(result => {
if ("id_token" in result || "access_token" in result) {
Expand All @@ -1194,7 +1202,7 @@ export class QwcOidcProvider extends QwcHotReloadElement {
} else {
propertiesState.idToken = null;
}
propertiesState.logoutUrl = "http://localhost:8080/q/io.quarkus.quarkus-oidc/logout";
propertiesState.logoutUrl = QwcOidcProvider._getCurrentBaseUrl() + propertiesState.logoutPath;
propertiesState.postLogoutUriParam = "redirect_uri";
onLoggedIn();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public OidcDevUiRuntimePropertiesDTO getProperties() {
props.isIntrospectionIsAvailable(), props.getKeycloakAdminUrl(),
props.getKeycloakRealms(), props.isSwaggerIsAvailable(), props.isGraphqlIsAvailable(), props.getSwaggerUiPath(),
props.getGraphqlUiPath(),
props.isAlwaysLogoutUserInDevUiOnReload(), props.getPropertiesStateId());
props.isAlwaysLogoutUserInDevUiOnReload(), props.getPropertiesStateId(),
props.getLogoutPath(), props.getReadSessionCookiePath());
}

public Uni<String> exchangeCodeForTokens(String tokenUrl, String clientId, String clientSecret,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public RuntimeValue<OidcDevUiRpcSvcPropertiesBean> getRpcServiceProperties(Strin
Map<String, String> oidcUsers, String oidcProviderName, String oidcApplicationType, String oidcGrantType,
boolean introspectionIsAvailable, String keycloakAdminUrl, List<String> keycloakRealms, boolean swaggerIsAvailable,
boolean graphqlIsAvailable, String swaggerUiPath, String graphqlUiPath, boolean alwaysLogoutUserInDevUiOnReload,
boolean discoverMetadata, String authServerUrl) {
boolean discoverMetadata, String authServerUrl, String devUiLogoutPath, String devUiReadSessionCookiePath) {
if (discoverMetadata) {
JsonObject metadata = discoverMetadata(authServerUrl);
if (metadata != null) {
Expand All @@ -56,7 +56,8 @@ public RuntimeValue<OidcDevUiRpcSvcPropertiesBean> getRpcServiceProperties(Strin
new OidcDevUiRpcSvcPropertiesBean(authorizationUrl, tokenUrl, logoutUrl,
webClientTimeout, grantOptions, oidcUsers, oidcProviderName, oidcApplicationType, oidcGrantType,
introspectionIsAvailable, keycloakAdminUrl, keycloakRealms, swaggerIsAvailable,
graphqlIsAvailable, swaggerUiPath, graphqlUiPath, alwaysLogoutUserInDevUiOnReload));
graphqlIsAvailable, swaggerUiPath, graphqlUiPath, alwaysLogoutUserInDevUiOnReload,
devUiLogoutPath, devUiReadSessionCookiePath));
}

public Handler<RoutingContext> readSessionCookieHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ public class OidcDevUiRpcSvcPropertiesBean {
* and web component needs to be updated.
*/
private final String propertiesStateId;
private final String logoutPath;
private final String readSessionCookiePath;

OidcDevUiRpcSvcPropertiesBean(String authorizationUrl, String tokenUrl, String logoutUrl,
Duration webClientTimeout, Map<String, Map<String, String>> grantOptions,
Map<String, String> oidcUsers, String oidcProviderName, String oidcApplicationType,
String oidcGrantType, boolean introspectionIsAvailable, String keycloakAdminUrl,
List<String> keycloakRealms, boolean swaggerIsAvailable, boolean graphqlIsAvailable,
String swaggerUiPath, String graphqlUiPath, boolean alwaysLogoutUserInDevUiOnReload) {
String swaggerUiPath, String graphqlUiPath, boolean alwaysLogoutUserInDevUiOnReload,
String devUiLogoutPath, String devUiReadSessionCookiePath) {
this.authorizationUrl = authorizationUrl;
this.tokenUrl = tokenUrl;
this.logoutUrl = logoutUrl;
Expand All @@ -54,6 +57,8 @@ public class OidcDevUiRpcSvcPropertiesBean {
this.graphqlUiPath = graphqlUiPath;
this.alwaysLogoutUserInDevUiOnReload = alwaysLogoutUserInDevUiOnReload;
this.propertiesStateId = Long.toString(UUID.randomUUID().getLeastSignificantBits());
this.logoutPath = devUiLogoutPath;
this.readSessionCookiePath = devUiReadSessionCookiePath;
}

String getAuthorizationUrl() {
Expand Down Expand Up @@ -135,4 +140,12 @@ boolean isAlwaysLogoutUserInDevUiOnReload() {
String getPropertiesStateId() {
return propertiesStateId;
}

String getLogoutPath() {
return logoutPath;
}

String getReadSessionCookiePath() {
return readSessionCookiePath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ public class OidcDevUiRuntimePropertiesDTO {
private final String graphqlUiPath;
private final boolean alwaysLogoutUserInDevUiOnReload;
private final String propertiesStateId;
private final String logoutPath;
private final String readSessionCookiePath;

OidcDevUiRuntimePropertiesDTO(String authorizationUrl, String tokenUrl, String logoutUrl, Config config, int httpPort,
String oidcProviderName, String oidcApplicationType, String oidcGrantType,
boolean introspectionIsAvailable, String keycloakAdminUrl, List<String> keycloakRealms,
boolean swaggerIsAvailable, boolean graphqlIsAvailable, String swaggerUiPath,
String graphqlUiPath, boolean alwaysLogoutUserInDevUiOnReload, String propertiesStateId) {
String graphqlUiPath, boolean alwaysLogoutUserInDevUiOnReload, String propertiesStateId,
String logoutPath, String readSessionCookiePath) {
this.clientId = new OidcConfigPropertySupplier(CLIENT_ID_CONFIG_KEY).get(config);
this.clientSecret = new OidcConfigPropertySupplier(CLIENT_SECRET_CONFIG_KEY, "").get(config);
this.authorizationUrl = new OidcConfigPropertySupplier(AUTHORIZATION_PATH_CONFIG_KEY, authorizationUrl, true)
Expand All @@ -65,6 +68,8 @@ public class OidcDevUiRuntimePropertiesDTO {
this.graphqlUiPath = graphqlUiPath;
this.alwaysLogoutUserInDevUiOnReload = alwaysLogoutUserInDevUiOnReload;
this.propertiesStateId = propertiesStateId;
this.logoutPath = logoutPath;
this.readSessionCookiePath = readSessionCookiePath;
}

public String getClientId() {
Expand Down Expand Up @@ -150,4 +155,12 @@ public boolean isAlwaysLogoutUserInDevUiOnReload() {
public String getPropertiesStateId() {
return propertiesStateId;
}

public String getLogoutPath() {
return logoutPath;
}

public String getReadSessionCookiePath() {
return readSessionCookiePath;
}
}
Loading