diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache index bf9545f34f4..2a027220da7 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache @@ -524,6 +524,22 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { throw new RuntimeException("No OAuth2 authentication configured!"); } + /** + * Helper method to set the credentials of a public client for the first OAuth2 authentication. + * + * @param clientId the client ID + * @return a {@link org.openapitools.client.ApiClient} object. + */ + public ApiClient setOauthCredentialsForPublicClient(String clientId) { + for (Authentication auth : authentications.values()) { + if (auth instanceof OAuth) { + ((OAuth) auth).setCredentialsForPublicClient(clientId, isDebugging()); + return this; + } + } + throw new RuntimeException("No OAuth2 authentication configured!"); + } + /** * Helper method to set the password flow for the first OAuth2 authentication. * diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/auth/OAuth.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/auth/OAuth.mustache index b7e28e55bfc..8908aa543dd 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/auth/OAuth.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/auth/OAuth.mustache @@ -158,6 +158,19 @@ public class OAuth implements Authentication { return this; } + public OAuth setCredentialsForPublicClient(String clientId, Boolean debug) { + if (Boolean.TRUE.equals(debug)) { + service = new ServiceBuilder(clientId) + .apiSecretIsEmptyStringUnsafe().debug() + .build(authApi); + } else { + service = new ServiceBuilder(clientId) + .apiSecretIsEmptyStringUnsafe() + .build(authApi); + } + return this; + } + public OAuth usePasswordFlow(String username, String password) { this.flow = OAuthFlow.PASSWORD; this.username = username; diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache index baaa6037fab..a89642a2758 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache @@ -524,6 +524,22 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { throw new RuntimeException("No OAuth2 authentication configured!"); } + /** + * Helper method to set the credentials of a public client for the first OAuth2 authentication. + * + * @param clientId the client ID + * @return a {@link org.openapitools.client.ApiClient} object. + */ + public ApiClient setOauthCredentialsForPublicClient(String clientId) { + for (Authentication auth : authentications.values()) { + if (auth instanceof OAuth) { + ((OAuth) auth).setCredentialsForPublicClient(clientId, isDebugging()); + return this; + } + } + throw new RuntimeException("No OAuth2 authentication configured!"); + } + /** * Helper method to set the password flow for the first OAuth2 authentication. * diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/auth/OAuth.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/auth/OAuth.mustache index 993bfdcd394..67f56597696 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/auth/OAuth.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/auth/OAuth.mustache @@ -158,6 +158,19 @@ public class OAuth implements Authentication { return this; } + public OAuth setCredentialsForPublicClient(String clientId, Boolean debug) { + if (Boolean.TRUE.equals(debug)) { + service = new ServiceBuilder(clientId) + .apiSecretIsEmptyStringUnsafe().debug() + .build(authApi); + } else { + service = new ServiceBuilder(clientId) + .apiSecretIsEmptyStringUnsafe() + .build(authApi); + } + return this; + } + public OAuth usePasswordFlow(String username, String password) { this.flow = OAuthFlow.PASSWORD; this.username = username; diff --git a/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/ApiClient.java index 951aa9d50a9..506ac25db7d 100644 --- a/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/ApiClient.java @@ -446,6 +446,22 @@ public class ApiClient extends JavaTimeFormatter { throw new RuntimeException("No OAuth2 authentication configured!"); } + /** + * Helper method to set the credentials of a public client for the first OAuth2 authentication. + * + * @param clientId the client ID + * @return a {@link org.openapitools.client.ApiClient} object. + */ + public ApiClient setOauthCredentialsForPublicClient(String clientId) { + for (Authentication auth : authentications.values()) { + if (auth instanceof OAuth) { + ((OAuth) auth).setCredentialsForPublicClient(clientId, isDebugging()); + return this; + } + } + throw new RuntimeException("No OAuth2 authentication configured!"); + } + /** * Helper method to set the password flow for the first OAuth2 authentication. * diff --git a/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/auth/OAuth.java b/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/auth/OAuth.java index c55fb3793e2..69182323137 100644 --- a/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/auth/OAuth.java +++ b/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/auth/OAuth.java @@ -169,6 +169,19 @@ public class OAuth implements Authentication { return this; } + public OAuth setCredentialsForPublicClient(String clientId, Boolean debug) { + if (Boolean.TRUE.equals(debug)) { + service = new ServiceBuilder(clientId) + .apiSecretIsEmptyStringUnsafe().debug() + .build(authApi); + } else { + service = new ServiceBuilder(clientId) + .apiSecretIsEmptyStringUnsafe() + .build(authApi); + } + return this; + } + public OAuth usePasswordFlow(String username, String password) { this.flow = OAuthFlow.PASSWORD; this.username = username; diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java index 951aa9d50a9..506ac25db7d 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java @@ -446,6 +446,22 @@ public class ApiClient extends JavaTimeFormatter { throw new RuntimeException("No OAuth2 authentication configured!"); } + /** + * Helper method to set the credentials of a public client for the first OAuth2 authentication. + * + * @param clientId the client ID + * @return a {@link org.openapitools.client.ApiClient} object. + */ + public ApiClient setOauthCredentialsForPublicClient(String clientId) { + for (Authentication auth : authentications.values()) { + if (auth instanceof OAuth) { + ((OAuth) auth).setCredentialsForPublicClient(clientId, isDebugging()); + return this; + } + } + throw new RuntimeException("No OAuth2 authentication configured!"); + } + /** * Helper method to set the password flow for the first OAuth2 authentication. * diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/OAuth.java b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/OAuth.java index c55fb3793e2..69182323137 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/OAuth.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/OAuth.java @@ -169,6 +169,19 @@ public class OAuth implements Authentication { return this; } + public OAuth setCredentialsForPublicClient(String clientId, Boolean debug) { + if (Boolean.TRUE.equals(debug)) { + service = new ServiceBuilder(clientId) + .apiSecretIsEmptyStringUnsafe().debug() + .build(authApi); + } else { + service = new ServiceBuilder(clientId) + .apiSecretIsEmptyStringUnsafe() + .build(authApi); + } + return this; + } + public OAuth usePasswordFlow(String username, String password) { this.flow = OAuthFlow.PASSWORD; this.username = username; diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/ApiClient.java index 10170cec2b6..afce13bf9fa 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/ApiClient.java @@ -530,6 +530,22 @@ public class ApiClient extends JavaTimeFormatter { throw new RuntimeException("No OAuth2 authentication configured!"); } + /** + * Helper method to set the credentials of a public client for the first OAuth2 authentication. + * + * @param clientId the client ID + * @return a {@link org.openapitools.client.ApiClient} object. + */ + public ApiClient setOauthCredentialsForPublicClient(String clientId) { + for (Authentication auth : authentications.values()) { + if (auth instanceof OAuth) { + ((OAuth) auth).setCredentialsForPublicClient(clientId, isDebugging()); + return this; + } + } + throw new RuntimeException("No OAuth2 authentication configured!"); + } + /** * Helper method to set the password flow for the first OAuth2 authentication. * diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/auth/OAuth.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/auth/OAuth.java index adf880d90be..16d2c280c88 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/auth/OAuth.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/auth/OAuth.java @@ -169,6 +169,19 @@ public class OAuth implements Authentication { return this; } + public OAuth setCredentialsForPublicClient(String clientId, Boolean debug) { + if (Boolean.TRUE.equals(debug)) { + service = new ServiceBuilder(clientId) + .apiSecretIsEmptyStringUnsafe().debug() + .build(authApi); + } else { + service = new ServiceBuilder(clientId) + .apiSecretIsEmptyStringUnsafe() + .build(authApi); + } + return this; + } + public OAuth usePasswordFlow(String username, String password) { this.flow = OAuthFlow.PASSWORD; this.username = username; diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java index 5e115bca68a..ac4d6528e7a 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java @@ -530,6 +530,22 @@ public class ApiClient extends JavaTimeFormatter { throw new RuntimeException("No OAuth2 authentication configured!"); } + /** + * Helper method to set the credentials of a public client for the first OAuth2 authentication. + * + * @param clientId the client ID + * @return a {@link org.openapitools.client.ApiClient} object. + */ + public ApiClient setOauthCredentialsForPublicClient(String clientId) { + for (Authentication auth : authentications.values()) { + if (auth instanceof OAuth) { + ((OAuth) auth).setCredentialsForPublicClient(clientId, isDebugging()); + return this; + } + } + throw new RuntimeException("No OAuth2 authentication configured!"); + } + /** * Helper method to set the password flow for the first OAuth2 authentication. * diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/OAuth.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/OAuth.java index c55fb3793e2..69182323137 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/OAuth.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/OAuth.java @@ -169,6 +169,19 @@ public class OAuth implements Authentication { return this; } + public OAuth setCredentialsForPublicClient(String clientId, Boolean debug) { + if (Boolean.TRUE.equals(debug)) { + service = new ServiceBuilder(clientId) + .apiSecretIsEmptyStringUnsafe().debug() + .build(authApi); + } else { + service = new ServiceBuilder(clientId) + .apiSecretIsEmptyStringUnsafe() + .build(authApi); + } + return this; + } + public OAuth usePasswordFlow(String username, String password) { this.flow = OAuthFlow.PASSWORD; this.username = username;