Skip to content

Commit 8a2fcb3

Browse files
Fix #1127 - Use CredentialProvider in OAuth2 provider (#1126)
* Use CredentialProvider in OAUTH2 provider and update data structure for CrendentialProvider Signed-off-by: gabriel-farache <[email protected]> * Fix Custom auth provider doc Signed-off-by: gabriel-farache <[email protected]> --------- Signed-off-by: gabriel-farache <[email protected]>
1 parent 8026891 commit 8a2fcb3

File tree

27 files changed

+991
-58
lines changed

27 files changed

+991
-58
lines changed

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GeneratorProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ void produceOauthAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
174174
.annotation(OpenApiSpec.class)
175175
.addValue("openApiSpecId", openApiSpecId)
176176
.done()
177+
.addInjectionPoint(ClassType.create(DotName.createSimple(CredentialsProvider.class)))
177178
.addInjectionPoint(ClassType.create(OAuth2AuthenticationProvider.OidcClientRequestFilterDelegate.class),
178179
AnnotationInstance.builder(OidcClient.class).add("name", sanitizeAuthName(name)).build())
179180
.addInjectionPoint(ClassType.create(DotName.createSimple(CredentialsProvider.class)))
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<parent>
4+
<artifactId>quarkus-openapi-generator-integration-tests</artifactId>
5+
<groupId>io.quarkiverse.openapi.generator</groupId>
6+
<version>3.0.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>quarkus-openapi-generator-it-auth-provider</artifactId>
11+
<name>Quarkus - OpenAPI Generator - Integration Tests - Client - Auth Provider</name>
12+
<description>A few use cases that relies on authentication provider use cases with the OpenAPI Generator</description>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.quarkiverse.openapi.generator</groupId>
17+
<artifactId>quarkus-openapi-generator</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>io.quarkiverse.openapi.generator</groupId>
21+
<artifactId>quarkus-openapi-generator-oidc</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>io.quarkus</groupId>
25+
<artifactId>quarkus-junit5</artifactId>
26+
<scope>test</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.wiremock</groupId>
30+
<artifactId>wiremock</artifactId>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>io.rest-assured</groupId>
35+
<artifactId>rest-assured</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
</dependencies>
39+
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<groupId>io.quarkus</groupId>
44+
<artifactId>quarkus-maven-plugin</artifactId>
45+
<extensions>true</extensions>
46+
<executions>
47+
<execution>
48+
<goals>
49+
<goal>build</goal>
50+
<goal>generate-code</goal>
51+
<goal>generate-code-tests</goal>
52+
</goals>
53+
</execution>
54+
</executions>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
<profiles>
59+
<profile>
60+
<id>native-image</id>
61+
<activation>
62+
<property>
63+
<name>native</name>
64+
</property>
65+
</activation>
66+
<build>
67+
<plugins>
68+
<plugin>
69+
<artifactId>maven-surefire-plugin</artifactId>
70+
<configuration>
71+
<skipTests>${native.surefire.skip}</skipTests>
72+
</configuration>
73+
</plugin>
74+
<plugin>
75+
<artifactId>maven-failsafe-plugin</artifactId>
76+
<executions>
77+
<execution>
78+
<goals>
79+
<goal>integration-test</goal>
80+
<goal>verify</goal>
81+
</goals>
82+
<configuration>
83+
<systemPropertyVariables>
84+
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
85+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
86+
<maven.home>${maven.home}</maven.home>
87+
</systemPropertyVariables>
88+
</configuration>
89+
</execution>
90+
</executions>
91+
</plugin>
92+
</plugins>
93+
</build>
94+
<properties>
95+
<quarkus.package.type>native</quarkus.package.type>
96+
</properties>
97+
</profile>
98+
<profile>
99+
<id>resteasy-reactive</id>
100+
<dependencies>
101+
<dependency>
102+
<groupId>io.quarkus</groupId>
103+
<artifactId>quarkus-rest-client-oidc-filter</artifactId>
104+
</dependency>
105+
</dependencies>
106+
</profile>
107+
<profile>
108+
<id>resteasy-classic</id>
109+
<activation>
110+
<activeByDefault>true</activeByDefault>
111+
</activation>
112+
<dependencies>
113+
<dependency>
114+
<groupId>io.quarkus</groupId>
115+
<artifactId>quarkus-resteasy-client-oidc-filter</artifactId>
116+
</dependency>
117+
<dependency>
118+
<groupId>io.quarkus</groupId>
119+
<artifactId>quarkus-resteasy-multipart</artifactId>
120+
</dependency>
121+
</dependencies>
122+
</profile>
123+
</profiles>
124+
</project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package io.quarkiverse.openapi.generator.it.auth;
2+
3+
import jakarta.ws.rs.POST;
4+
import jakarta.ws.rs.Path;
5+
6+
import org.eclipse.microprofile.rest.client.inject.RestClient;
7+
8+
@Path("/token_server")
9+
public class TokenServerResource {
10+
11+
@RestClient
12+
org.acme.externalservice1.api.DefaultApi defaultApi1;
13+
14+
@RestClient
15+
org.acme.externalservice2.api.DefaultApi defaultApi2;
16+
17+
@RestClient
18+
org.acme.externalservice3.api.DefaultApi defaultApi3;
19+
20+
@RestClient
21+
org.acme.externalservice5.api.DefaultApi defaultApi5;
22+
23+
@POST
24+
@Path("service1")
25+
public String service1() {
26+
defaultApi1.executeQuery1();
27+
return "hello";
28+
}
29+
30+
@POST
31+
@Path("service2")
32+
public String service2() {
33+
defaultApi2.executeQuery2();
34+
return "hello";
35+
}
36+
37+
@POST
38+
@Path("service3")
39+
public String service3() {
40+
defaultApi3.executeQuery3();
41+
return "hello";
42+
}
43+
44+
@POST
45+
@Path("service5")
46+
public String service5() {
47+
defaultApi5.executeQuery5();
48+
return "hello";
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.quarkiverse.openapi.generator.it.auth.provider;
2+
3+
import jakarta.annotation.Priority;
4+
import jakarta.enterprise.context.Dependent;
5+
import jakarta.enterprise.inject.Alternative;
6+
import jakarta.enterprise.inject.Specializes;
7+
8+
import io.quarkiverse.openapi.generator.providers.ConfigCredentialsProvider;
9+
10+
@Dependent
11+
@Alternative
12+
@Specializes
13+
@Priority(200)
14+
public class CustomCredentialsProvider extends ConfigCredentialsProvider {
15+
public CustomCredentialsProvider() {
16+
}
17+
18+
@Override
19+
public String getBearerToken(CredentialsContext input) {
20+
return super.getBearerToken(input) + "_TEST";
21+
}
22+
23+
@Override
24+
public String getOauth2BearerToken(CredentialsContext input) {
25+
return super.getOauth2BearerToken(input) + "_TEST";
26+
}
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: token-external-service1 API
5+
version: 3.0.0-SNAPSHOT
6+
paths:
7+
/token-external-service1/executeQuery1:
8+
post:
9+
operationId: executeQuery1
10+
responses:
11+
"200":
12+
description: OK
13+
security:
14+
- service1-http-bearer: []
15+
components:
16+
securitySchemes:
17+
service1-http-bearer:
18+
type: http
19+
scheme: bearer
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: token-external-service2 API
5+
version: 3.0.0-SNAPSHOT
6+
paths:
7+
/token-external-service2/executeQuery2:
8+
post:
9+
operationId: executeQuery2
10+
responses:
11+
"200":
12+
description: OK
13+
security:
14+
- service2-oauth2: []
15+
components:
16+
securitySchemes:
17+
service2-oauth2:
18+
type: oauth2
19+
flows:
20+
clientCredentials:
21+
authorizationUrl: https://example.com/oauth
22+
tokenUrl: https://example.com/oauth/token
23+
scopes: {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: token-external-service3 API
5+
version: 3.0.0-SNAPSHOT
6+
paths:
7+
/token-external-service3/executeQuery3:
8+
post:
9+
operationId: executeQuery3
10+
responses:
11+
"200":
12+
description: OK
13+
security:
14+
- service3-http-bearer: []
15+
components:
16+
securitySchemes:
17+
service3-http-bearer:
18+
type: http
19+
scheme: bearer
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: token-external-service5 API
5+
version: 3.0.0-SNAPSHOT
6+
paths:
7+
/token-external-service5/executeQuery5:
8+
post:
9+
operationId: executeQuery5
10+
responses:
11+
"200":
12+
description: OK
13+
security:
14+
- service5-oauth2: []
15+
components:
16+
securitySchemes:
17+
service5-oauth2:
18+
type: oauth2
19+
flows:
20+
clientCredentials:
21+
authorizationUrl: https://example.com/oauth
22+
tokenUrl: https://example.com/oauth/token
23+
scopes: {}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Note: The property value is the name of an existing securityScheme in the spec file
2+
quarkus.openapi-generator.codegen.default-security-scheme=app_id
3+
4+
#Token service
5+
quarkus.openapi-generator.codegen.spec.token_external_service1_yaml.base-package=org.acme.externalservice1
6+
quarkus.openapi-generator.codegen.spec.token_external_service2_yaml.base-package=org.acme.externalservice2
7+
quarkus.openapi-generator.codegen.spec.token_external_service3_yaml.base-package=org.acme.externalservice3
8+
quarkus.openapi-generator.codegen.spec.token_external_service5_yaml.base-package=org.acme.externalservice5
9+
10+
quarkus.rest-client.token_external_service1_yaml.url=${propagation-external-service-mock.url}
11+
quarkus.rest-client.token_external_service2_yaml.url=${propagation-external-service-mock.url}
12+
quarkus.rest-client.token_external_service3_yaml.url=${propagation-external-service-mock.url}
13+
quarkus.rest-client.token_external_service5_yaml.url=${propagation-external-service-mock.url}
14+
15+
# default propagation for token_external_service1 invocation
16+
quarkus.openapi-generator.token_external_service1_yaml.auth.service1_http_bearer.token-propagation=true
17+
# default propagation for token_external_service2 invocation
18+
quarkus.openapi-generator.token_external_service2_yaml.auth.service2_oauth2.token-propagation=true
19+
20+
quarkus.openapi-generator.token_external_service3_yaml.auth.service3_http_bearer.bearer-token=BEARER_TOKEN
21+
22+
# Oidc clients for the services that has oauth2 security.
23+
# Oidc client used by the token_external_service2
24+
quarkus.oidc-client.service2_oauth2.auth-server-url=${keycloak.mock.service.url}
25+
quarkus.oidc-client.service2_oauth2.token-path=${keycloak.mock.service.token-path}
26+
quarkus.oidc-client.service2_oauth2.discovery-enabled=false
27+
quarkus.oidc-client.service2_oauth2.client-id=kogito-app
28+
quarkus.oidc-client.service2_oauth2.grant.type=client
29+
quarkus.oidc-client.service2_oauth2.credentials.client-secret.method=basic
30+
quarkus.oidc-client.service2_oauth2.credentials.client-secret.value=secret
31+
32+
33+
# Oidc client used by the token_external_service5
34+
quarkus.oidc-client.service5_oauth2.auth-server-url=${keycloak.mock.service.url}
35+
quarkus.oidc-client.service5_oauth2.token-path=${keycloak.mock.service.token-path}
36+
quarkus.oidc-client.service5_oauth2.discovery-enabled=false
37+
quarkus.oidc-client.service5_oauth2.client-id=kogito-app
38+
quarkus.oidc-client.service5_oauth2.grant.type=client
39+
quarkus.oidc-client.service5_oauth2.credentials.client-secret.method=basic
40+
quarkus.oidc-client.service5_oauth2.credentials.client-secret.value=secret
41+
42+
quarkus.keycloak.devservices.enabled=false

0 commit comments

Comments
 (0)