Skip to content

Commit 5f657a0

Browse files
authored
Feature/open id connect (#1) (#1284)
Fixes: #1227 Add to the template and codegen to look for and use the openIdConnectMethods Add Integration tests to verify support
1 parent 13a0938 commit 5f657a0

File tree

11 files changed

+100
-2
lines changed

11 files changed

+100
-2
lines changed

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/QuarkusJavaClientCodegen.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ private void replaceWithQuarkusTemplateFiles() {
7777
if (ProcessUtils.hasHttpBasicMethods(this.openAPI) ||
7878
ProcessUtils.hasApiKeyMethods(this.openAPI) ||
7979
ProcessUtils.hasHttpBearerMethods(this.openAPI) ||
80-
ProcessUtils.hasOAuthMethods(this.openAPI)) {
80+
ProcessUtils.hasOAuthMethods(this.openAPI) ||
81+
ProcessUtils.hasOpenIdConnectMethods(this.openAPI)) {
8182
supportingFiles.add(
8283
new SupportingFile(AUTH_PACKAGE + "/compositeAuthenticationProvider.qute",
8384
authFileFolder(),

client/deployment/src/main/resources/templates/libraries/microprofile/auth/compositeAuthenticationProvider.qute

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ package {apiPackage}.auth;
44
{#for auth in openapi:getUniqueOAuthOperations(oauthMethods.orEmpty)}
55
@io.quarkiverse.openapi.generator.markers.OauthAuthenticationMarker(name="{auth.name}", openApiSpecId="{quarkus-generator.openApiSpecId}")
66
{/for}
7+
{#for auth in openapi:getUniqueOAuthOperations(openIdConnectMethods.orEmpty)}
8+
@io.quarkiverse.openapi.generator.markers.OauthAuthenticationMarker(name="{auth.name}", openApiSpecId="{quarkus-generator.openApiSpecId}")
9+
{/for}
710
{#for auth in httpBasicMethods.orEmpty}
811
@io.quarkiverse.openapi.generator.markers.BasicAuthenticationMarker(name="{auth.name}", openApiSpecId="{quarkus-generator.openApiSpecId}")
912
{/for}

client/integration-tests/auth-provider/src/main/java/io/quarkiverse/openapi/generator/it/auth/TokenServerResource.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class TokenServerResource {
2020
@RestClient
2121
org.acme.externalservice5.api.DefaultApi defaultApi5;
2222

23+
@RestClient
24+
org.acme.externalservice6.api.DefaultApi defaultApi6;
25+
2326
@POST
2427
@Path("service1")
2528
public String service1() {
@@ -47,4 +50,11 @@ public String service5() {
4750
defaultApi5.executeQuery5();
4851
return "hello";
4952
}
53+
54+
@POST
55+
@Path("service6")
56+
public String service6() {
57+
defaultApi6.executeQuery6();
58+
return "hello";
59+
}
5060
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: token-external-service6 API
5+
version: 3.0.0-SNAPSHOT
6+
paths:
7+
/token-external-service6/executeQuery6:
8+
post:
9+
operationId: executeQuery6
10+
responses:
11+
"200":
12+
description: OK
13+
security:
14+
- service6-oidc: []
15+
components:
16+
securitySchemes:
17+
service6-oidc:
18+
type: openIdConnect
19+
description: Authentication for service6
20+
openIdConnectUrl: https://example.com/realms/master/.well-known/openid-configuration

client/integration-tests/auth-provider/src/main/resources/application.properties

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ quarkus.openapi-generator.codegen.spec.token_external_service1_yaml.base-package
66
quarkus.openapi-generator.codegen.spec.token_external_service2_yaml.base-package=org.acme.externalservice2
77
quarkus.openapi-generator.codegen.spec.token_external_service3_yaml.base-package=org.acme.externalservice3
88
quarkus.openapi-generator.codegen.spec.token_external_service5_yaml.base-package=org.acme.externalservice5
9+
quarkus.openapi-generator.codegen.spec.token_external_service6_yaml.base-package=org.acme.externalservice6
910

1011
quarkus.rest-client.token_external_service1_yaml.url=${propagation-external-service-mock.url}
1112
quarkus.rest-client.token_external_service2_yaml.url=${propagation-external-service-mock.url}
1213
quarkus.rest-client.token_external_service3_yaml.url=${propagation-external-service-mock.url}
1314
quarkus.rest-client.token_external_service5_yaml.url=${propagation-external-service-mock.url}
15+
quarkus.rest-client.token_external_service6_yaml.url=${propagation-external-service-mock.url}
1416

1517
# default propagation for token_external_service1 invocation
1618
quarkus.openapi-generator.token_external_service1_yaml.auth.service1_http_bearer.token-propagation=true
@@ -39,4 +41,15 @@ quarkus.oidc-client.service5_oauth2.grant.type=client
3941
quarkus.oidc-client.service5_oauth2.credentials.client-secret.method=basic
4042
quarkus.oidc-client.service5_oauth2.credentials.client-secret.value=secret
4143

44+
45+
# Oidc client used by the token_external_service6
46+
quarkus.oidc-client.service6_oidc.auth-server-url=${keycloak.mock.service.url}
47+
quarkus.oidc-client.service6_oidc.token-path=${keycloak.mock.service.token-path}
48+
quarkus.oidc-client.service6_oidc.discovery-enabled=false
49+
quarkus.oidc-client.service6_oidc.client-id=kogito-app
50+
quarkus.oidc-client.service6_oidc.grant.type=client
51+
quarkus.oidc-client.service6_oidc.credentials.client-secret.method=basic
52+
quarkus.oidc-client.service6_oidc.credentials.client-secret.value=secret
53+
54+
4255
quarkus.keycloak.devservices.enabled=false

client/integration-tests/auth-provider/src/test/java/io/quarkiverse/openapi/generator/it/auth/TokenExternalServicesMock.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public Map<String, String> start() {
6060
// configured. The token will be overridden by the custom credential provider
6161
stubForExternalService("/token-external-service5/executeQuery5", KEYCLOAK_ACCESS_TOKEN + "_TEST");
6262

63+
// stub the token-external-service6 invocation with the expected token, no propagation is produced
64+
// in this case but the service must receive the token provided by Keycloak since it has oidc security
65+
// configured. The token will be overridden by the custom credential provider
66+
stubForExternalService("/token-external-service6/executeQuery6", KEYCLOAK_ACCESS_TOKEN + "_TEST");
67+
6368
return Map.of(TOKEN_EXTERNAL_SERVICE_MOCK_URL, wireMockServer.baseUrl());
6469
}
6570

client/integration-tests/auth-provider/src/test/java/io/quarkiverse/openapi/generator/it/auth/TokenWithCustomCredentialProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class TokenWithCustomCredentialProviderTest {
2323

2424
@ParameterizedTest
25-
@ValueSource(strings = { "service1", "service2", "service3", "service5" })
25+
@ValueSource(strings = { "service1", "service2", "service3", "service5", "service6" })
2626
void testService(String service) {
2727
Map<String, String> headers = Map.of(HttpHeaders.AUTHORIZATION, AUTHORIZATION_TOKEN);
2828

client/integration-tests/security/src/main/java/io/quarkiverse/openapi/generator/it/security/TokenPropagationResource.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class TokenPropagationResource {
2424
@RestClient
2525
org.acme.externalservice5.api.DefaultApi defaultApi5;
2626

27+
@RestClient
28+
org.acme.externalservice6.api.DefaultApi defaultApi6;
29+
2730
@POST
2831
@Path("service1")
2932
public Response service1() {
@@ -53,4 +56,10 @@ public Response service4() {
5356
public Response service5() {
5457
return defaultApi5.executeQuery5();
5558
}
59+
60+
@POST
61+
@Path("service6")
62+
public Response service6() {
63+
return defaultApi6.executeQuery6();
64+
}
5665
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: external-service6 API
5+
version: 3.0.0-SNAPSHOT
6+
paths:
7+
/token-propagation-external-service6/executeQuery6:
8+
post:
9+
operationId: executeQuery6
10+
responses:
11+
"200":
12+
description: OK
13+
security:
14+
- service6-oidc: []
15+
components:
16+
securitySchemes:
17+
service6-oidc:
18+
type: openIdConnect
19+
description: Authentication for service6
20+
openIdConnectUrl: https://example.com/realms/master/.well-known/openid-configuration

client/integration-tests/security/src/main/resources/application.properties

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ quarkus.openapi-generator.codegen.spec.token_propagation_external_service2_yaml.
3232
quarkus.openapi-generator.codegen.spec.token_propagation_external_service3_yaml.base-package=org.acme.externalservice3
3333
quarkus.openapi-generator.codegen.spec.token_propagation_external_service4_yaml.base-package=org.acme.externalservice4
3434
quarkus.openapi-generator.codegen.spec.token_propagation_external_service5_yaml.base-package=org.acme.externalservice5
35+
quarkus.openapi-generator.codegen.spec.token_propagation_external_service6_yaml.base-package=org.acme.externalservice6
3536

3637
quarkus.rest-client.token_propagation_external_service1_yaml.url=${propagation-external-service-mock.url}
3738
quarkus.rest-client.token_propagation_external_service2_yaml.url=${propagation-external-service-mock.url}
3839
quarkus.rest-client.token_propagation_external_service3_yaml.url=${propagation-external-service-mock.url}
3940
quarkus.rest-client.token_propagation_external_service4_yaml.url=${propagation-external-service-mock.url}
4041
quarkus.rest-client.token_propagation_external_service5_yaml.url=${propagation-external-service-mock.url}
42+
quarkus.rest-client.token_propagation_external_service6_yaml.url=${propagation-external-service-mock.url}
43+
4144

4245
# default propagation for token_propagation_external_service1 invocation
4346
quarkus.openapi-generator.token_propagation_external_service1_yaml.auth.service1_http_bearer.token-propagation=true
@@ -78,6 +81,15 @@ quarkus.oidc-client.service5_oauth2.grant.type=client
7881
quarkus.oidc-client.service5_oauth2.credentials.client-secret.method=basic
7982
quarkus.oidc-client.service5_oauth2.credentials.client-secret.value=secret
8083

84+
# Oidc client used by the token_propagation_external_service6
85+
quarkus.oidc-client.service6_oidc.auth-server-url=${keycloak.mock.service.url}
86+
quarkus.oidc-client.service6_oidc.token-path=${keycloak.mock.service.token-path}
87+
quarkus.oidc-client.service6_oidc.discovery-enabled=false
88+
quarkus.oidc-client.service6_oidc.client-id=kogito-app
89+
quarkus.oidc-client.service6_oidc.grant.type=client
90+
quarkus.oidc-client.service6_oidc.credentials.client-secret.method=basic
91+
quarkus.oidc-client.service6_oidc.credentials.client-secret.value=secret
92+
8193
quarkus.keycloak.devservices.enabled=false
8294

8395
# Slack OpenAPI

0 commit comments

Comments
 (0)