Skip to content

Commit 6cc7ba7

Browse files
committed
Configure Swagger OAuth systems from OpenAPI extension values.
1 parent dcff901 commit 6cc7ba7

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

cda-gui/src/pages/swagger-ui/index.jsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,27 @@ export default function SwaggerUI() {
3838
},
3939
onComplete: () => {
4040
const spec = JSON.parse(ui.spec().get("spec"));
41-
console.log(JSON.stringify(spec.components.securitySchemes));
42-
43-
ui.initOAuth({
44-
clientId:"cwms",
45-
additionalQueryStringParams: {kc_idp_hint: "federation-eams"},
46-
usePkceWithAuthorizationCodeGrant: true
47-
});
41+
for (const schemeName in spec.components.securitySchemes) {
42+
const scheme = spec.components.securitySchemes[schemeName];
43+
if (scheme.type === "openIdConnect") {
44+
let additionalParams = null;
45+
let hints = scheme["x-kc_idp_hint"];
46+
if (hints) {
47+
additionalParams = {
48+
// Since getting the interface to allow users to choose
49+
// is likely impossible, we will assume the first in the list
50+
// is the "primary" auth system
51+
"kc_idp_hint": hints.values[0]
52+
};
53+
}
54+
ui.initOAuth({
55+
clientId: scheme["x-oidc-client-id"],
56+
usePkceWithAuthorizationCodeGrant: true,
57+
additionalQueryStringParams: additionalParams,
58+
});
59+
break;
60+
}
61+
}
4862
},
4963
});
5064
}, []);

cda-gui/vite.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ export default defineConfig(({ mode }) => {
2323
changeOrigin: true,
2424
secure: false,
2525
},
26+
"^/cwms-data/auth/.*": {
27+
target: env.CDA_API_ROOT,
28+
changeOrigin: true,
29+
secure: false,
30+
},
2631
"^/cwms-data/swagger-docs$": {
2732
target: env.CDA_API_ROOT,
2833
changeOrigin: true,

cwms-data-api/src/main/java/cwms/cda/security/OpenIDConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.google.common.flogger.FluentLogger;
1313

1414
import io.swagger.v3.oas.models.security.SecurityScheme;
15-
import io.swagger.v3.oas.models.security.SecurityScheme.In;
1615
import io.swagger.v3.oas.models.security.SecurityScheme.Type;
1716

1817
public class OpenIDConfig {
@@ -42,6 +41,7 @@ public OpenIDConfig(URL wellKnown, String client_id, String idp_hint) throws IOE
4241
ObjectMapper mapper = new ObjectMapper();
4342
JsonNode node = mapper.readTree(http.getInputStream());
4443
jwksUrl = new URL(node.get("jwks_uri").asText());
44+
issuer = node.get("issuer").asText();
4545
} else {
4646
log.atSevere().log("Unable to retrieve data from realm. Response code %d",status);
4747
}

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ services:
7777
- cwms.dataapi.access.openid.altAuthUrl=http://localhost:${APP_PORT:-8081}
7878
- cwms.dataapi.access.openid.useAltWellKnown=true
7979
- cwms.dataapi.access.openid.issuer=http://localhost:${APP_PORT:-8081}/auth/realms/cwms
80+
- cwms.dataapi.access.openid.clientId=cwms
81+
# values are not actually used in the local keycloak, however it does fail and leaves them in place for various testing.
82+
- cwms.dataapi.access.openid.idpHint=federation-eams,login.gov
8083
expose:
8184
- 7000
8285
- 5005

0 commit comments

Comments
 (0)