diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache index 4ba31c8cbc0..9775e5b323d 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache @@ -54,6 +54,7 @@ import {{invokerPackage}}.auth.HttpBasicAuth; import {{invokerPackage}}.auth.ApiKeyAuth; import {{invokerPackage}}.auth.OAuth; import {{invokerPackage}}.auth.RetryingOAuth; +import {{invokerPackage}}.auth.OAuthFlow; public class ApiClient { @@ -102,7 +103,7 @@ public class ApiClient { ) { init(); - RetryingOAuth retryingOAuth = new RetryingOAuth("{{tokenUrl}}", clientId, GrantType.valueOf("{{flow}}"), clientSecret, parameters); + RetryingOAuth retryingOAuth = new RetryingOAuth("{{tokenUrl}}", clientId, OAuthFlow.{{flow}}, clientSecret, parameters); authentications.put( "{{name}}", retryingOAuth diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/RetryingOAuth.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/RetryingOAuth.mustache index b28169a6f22..4703c2488d0 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/RetryingOAuth.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/RetryingOAuth.mustache @@ -35,15 +35,14 @@ public class RetryingOAuth extends OAuth implements Interceptor { public RetryingOAuth( String tokenUrl, String clientId, - GrantType grantType, + OAuthFlow flow, String clientSecret, Map parameters ) { this(OAuthClientRequest.tokenLocation(tokenUrl) .setClientId(clientId) - .setGrantType(grantType) .setClientSecret(clientSecret)); - + setFlow(flow); if (parameters != null) { for (String paramName : parameters.keySet()) { tokenRequestBuilder.setParameter(paramName, parameters.get(paramName)); @@ -51,6 +50,25 @@ public class RetryingOAuth extends OAuth implements Interceptor { } } + public void setFlow(OAuthFlow flow) { + switch(flow) { + case accessCode: + tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE); + break; + case implicit: + tokenRequestBuilder.setGrantType(GrantType.IMPLICIT); + break; + case password: + tokenRequestBuilder.setGrantType(GrantType.PASSWORD); + break; + case application: + tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS); + break; + default: + break; + } + } + @Override public Response intercept(Chain chain) throws IOException { return retryingIntercept(chain, true); diff --git a/samples/client/petstore-security-test/java/okhttp-gson/.openapi-generator/VERSION b/samples/client/petstore-security-test/java/okhttp-gson/.openapi-generator/VERSION index 6d94c9c2e12..f4cb97d56ce 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/.openapi-generator/VERSION +++ b/samples/client/petstore-security-test/java/okhttp-gson/.openapi-generator/VERSION @@ -1 +1 @@ -3.3.0-SNAPSHOT \ No newline at end of file +3.3.1-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java index e78d33d2093..de2793cbeef 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java @@ -53,6 +53,7 @@ import org.openapitools.client.auth.HttpBasicAuth; import org.openapitools.client.auth.ApiKeyAuth; import org.openapitools.client.auth.OAuth; import org.openapitools.client.auth.RetryingOAuth; +import org.openapitools.client.auth.OAuthFlow; public class ApiClient { @@ -100,7 +101,7 @@ public class ApiClient { ) { init(); - RetryingOAuth retryingOAuth = new RetryingOAuth("", clientId, GrantType.valueOf("implicit"), clientSecret, parameters); + RetryingOAuth retryingOAuth = new RetryingOAuth("", clientId, OAuthFlow.implicit, clientSecret, parameters); authentications.put( "petstore_auth", retryingOAuth diff --git a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/org/openapitools/client/auth/RetryingOAuth.java b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/org/openapitools/client/auth/RetryingOAuth.java index c6451da5241..78fcb52d5a3 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/org/openapitools/client/auth/RetryingOAuth.java +++ b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/org/openapitools/client/auth/RetryingOAuth.java @@ -35,15 +35,14 @@ public class RetryingOAuth extends OAuth implements Interceptor { public RetryingOAuth( String tokenUrl, String clientId, - GrantType grantType, + OAuthFlow flow, String clientSecret, Map parameters ) { this(OAuthClientRequest.tokenLocation(tokenUrl) .setClientId(clientId) - .setGrantType(grantType) .setClientSecret(clientSecret)); - + setFlow(flow); if (parameters != null) { for (String paramName : parameters.keySet()) { tokenRequestBuilder.setParameter(paramName, parameters.get(paramName)); @@ -51,6 +50,25 @@ public class RetryingOAuth extends OAuth implements Interceptor { } } + public void setFlow(OAuthFlow flow) { + switch(flow) { + case accessCode: + tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE); + break; + case implicit: + tokenRequestBuilder.setGrantType(GrantType.IMPLICIT); + break; + case password: + tokenRequestBuilder.setGrantType(GrantType.PASSWORD); + break; + case application: + tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS); + break; + default: + break; + } + } + @Override public Response intercept(Chain chain) throws IOException { return retryingIntercept(chain, true); diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java index 99c0642c798..f8ad6cf3902 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java @@ -53,6 +53,7 @@ import org.openapitools.client.auth.HttpBasicAuth; import org.openapitools.client.auth.ApiKeyAuth; import org.openapitools.client.auth.OAuth; import org.openapitools.client.auth.RetryingOAuth; +import org.openapitools.client.auth.OAuthFlow; public class ApiClient { @@ -102,7 +103,7 @@ public class ApiClient { ) { init(); - RetryingOAuth retryingOAuth = new RetryingOAuth("", clientId, GrantType.valueOf("implicit"), clientSecret, parameters); + RetryingOAuth retryingOAuth = new RetryingOAuth("", clientId, OAuthFlow.implicit, clientSecret, parameters); authentications.put( "petstore_auth", retryingOAuth diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/auth/RetryingOAuth.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/auth/RetryingOAuth.java index c6451da5241..78fcb52d5a3 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/auth/RetryingOAuth.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/auth/RetryingOAuth.java @@ -35,15 +35,14 @@ public class RetryingOAuth extends OAuth implements Interceptor { public RetryingOAuth( String tokenUrl, String clientId, - GrantType grantType, + OAuthFlow flow, String clientSecret, Map parameters ) { this(OAuthClientRequest.tokenLocation(tokenUrl) .setClientId(clientId) - .setGrantType(grantType) .setClientSecret(clientSecret)); - + setFlow(flow); if (parameters != null) { for (String paramName : parameters.keySet()) { tokenRequestBuilder.setParameter(paramName, parameters.get(paramName)); @@ -51,6 +50,25 @@ public class RetryingOAuth extends OAuth implements Interceptor { } } + public void setFlow(OAuthFlow flow) { + switch(flow) { + case accessCode: + tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE); + break; + case implicit: + tokenRequestBuilder.setGrantType(GrantType.IMPLICIT); + break; + case password: + tokenRequestBuilder.setGrantType(GrantType.PASSWORD); + break; + case application: + tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS); + break; + default: + break; + } + } + @Override public Response intercept(Chain chain) throws IOException { return retryingIntercept(chain, true); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java index 99c0642c798..f8ad6cf3902 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java @@ -53,6 +53,7 @@ import org.openapitools.client.auth.HttpBasicAuth; import org.openapitools.client.auth.ApiKeyAuth; import org.openapitools.client.auth.OAuth; import org.openapitools.client.auth.RetryingOAuth; +import org.openapitools.client.auth.OAuthFlow; public class ApiClient { @@ -102,7 +103,7 @@ public class ApiClient { ) { init(); - RetryingOAuth retryingOAuth = new RetryingOAuth("", clientId, GrantType.valueOf("implicit"), clientSecret, parameters); + RetryingOAuth retryingOAuth = new RetryingOAuth("", clientId, OAuthFlow.implicit, clientSecret, parameters); authentications.put( "petstore_auth", retryingOAuth diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/auth/RetryingOAuth.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/auth/RetryingOAuth.java index c6451da5241..78fcb52d5a3 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/auth/RetryingOAuth.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/auth/RetryingOAuth.java @@ -35,15 +35,14 @@ public class RetryingOAuth extends OAuth implements Interceptor { public RetryingOAuth( String tokenUrl, String clientId, - GrantType grantType, + OAuthFlow flow, String clientSecret, Map parameters ) { this(OAuthClientRequest.tokenLocation(tokenUrl) .setClientId(clientId) - .setGrantType(grantType) .setClientSecret(clientSecret)); - + setFlow(flow); if (parameters != null) { for (String paramName : parameters.keySet()) { tokenRequestBuilder.setParameter(paramName, parameters.get(paramName)); @@ -51,6 +50,25 @@ public class RetryingOAuth extends OAuth implements Interceptor { } } + public void setFlow(OAuthFlow flow) { + switch(flow) { + case accessCode: + tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE); + break; + case implicit: + tokenRequestBuilder.setGrantType(GrantType.IMPLICIT); + break; + case password: + tokenRequestBuilder.setGrantType(GrantType.PASSWORD); + break; + case application: + tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS); + break; + default: + break; + } + } + @Override public Response intercept(Chain chain) throws IOException { return retryingIntercept(chain, true);