Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] [Kotlin] (#14876) fix use of isBasic conditions - do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) #15220

Conversation

tiffmaelite
Copy link
Contributor

@tiffmaelite tiffmaelite commented Apr 14, 2023

First small replacement for #14878 to fix #14876

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (6.3.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608

from previous PR: @borsch @wing328

@tiffmaelite tiffmaelite changed the title import HttpBearerAuth only when relevant + not use HttpBearerAuth for… do not use HttpBearerAuth for signature auth when it is not supported or for other unsupported http auth methods Apr 14, 2023
@tiffmaelite tiffmaelite force-pushed the fix/align_use-HttpBearerAuth_import-HttpBearerAuth branch 3 times, most recently from c6315a6 to 516d5f5 Compare April 14, 2023 12:36
@tiffmaelite tiffmaelite changed the title do not use HttpBearerAuth for signature auth when it is not supported or for other unsupported http auth methods do not use HttpBearerAuth (or HttpBaisAuth) for other http auth methods (such as http signature auth or custom schemes) Apr 17, 2023
@tiffmaelite tiffmaelite changed the title do not use HttpBearerAuth (or HttpBaisAuth) for other http auth methods (such as http signature auth or custom schemes) do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) Apr 17, 2023
@tiffmaelite tiffmaelite changed the title do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) [fix #14876] do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) Apr 17, 2023
@tiffmaelite tiffmaelite changed the title [fix #14876] do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) [Java] [Kotlin] [fix #14876] do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) Apr 18, 2023
@tiffmaelite tiffmaelite changed the title [Java] [Kotlin] [fix #14876] do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) [Java] [Kotlin] [fix 14876] do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) Apr 18, 2023
@tiffmaelite tiffmaelite reopened this Apr 18, 2023
@tiffmaelite tiffmaelite changed the title [Java] [Kotlin] [fix 14876] do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) [Java] [Kotlin] [fix issue 14876] do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) Apr 18, 2023
@tiffmaelite
Copy link
Contributor Author

tiffmaelite commented Apr 20, 2023

Additional precision regarding target of this PR: some projects might rely on this bug if their openapi.yaml file contains a valid authorization scheme unsupported by the used generator in order to have these auth methods included in the generated code and then have custom workarounds implemented in their project to replace the way the authentication is handled.

Because I was not sure of how much this fix could disrupt projects misusing the authorization part, I decided to go against 7.x rather than master.

In any case, as I mentioned in the linked issue, I initially observed the bug with version 4.2.3 and it probably existed for a long time already, so it looks like it does not affect a lot of people and can wait a little longer and be marked as "potential breaking change without fallback" in the next major release.

@borsch borsch added this to the 7.0.0 milestone Apr 20, 2023
@tiffmaelite tiffmaelite changed the title [Java] [Kotlin] [fix issue 14876] do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) [Java] [Kotlin] (#14876) do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) Apr 20, 2023
@tiffmaelite tiffmaelite changed the base branch from 7.0.x to master May 11, 2023 06:50
@tiffmaelite tiffmaelite force-pushed the fix/align_use-HttpBearerAuth_import-HttpBearerAuth branch from 516d5f5 to 928c086 Compare May 11, 2023 07:00
@tiffmaelite tiffmaelite reopened this May 15, 2023
@tiffmaelite tiffmaelite force-pushed the fix/align_use-HttpBearerAuth_import-HttpBearerAuth branch from 928c086 to 97a7d50 Compare May 16, 2023 07:51
auth = new HttpBearerAuth("{{scheme}}");
{{/isBasicBearer}}
{{^isBasicBearer}}
throw new RuntimeException("auth name \"" + authName + "\" does not have a supported http scheme type");
Copy link
Contributor Author

@tiffmaelite tiffmaelite May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: that part might be a breaking change for those relying on the bug

auth = new HttpBearerAuth("{{scheme}}");
{{/isBasicBearer}}
{{^isBasicBearer}}
throw new RuntimeException("auth name \"" + authName + "\" does not have a supported http scheme type");
Copy link
Contributor Author

@tiffmaelite tiffmaelite May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: that part might be a breaking change for those relying on the bug

auth = new HttpBearerAuth("{{scheme}}");
{{/isBasicBasic}}{{/isBasic}}
{{/isBasicBearer}}{{^isBasicBearer}}
throw new RuntimeException("auth name \"" + authName + "\" does not have a supported http scheme type");
Copy link
Contributor Author

@tiffmaelite tiffmaelite May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: that part might be a breaking change for those relying on the bug

@@ -128,7 +128,7 @@ import okhttp3.MediaType.Companion.toMediaType
) : this(baseUrl, okHttpClientBuilder{{^kotlinx_serialization}}, serializerBuilder{{/kotlinx_serialization}}) {
authNames.forEach { authName ->
val auth = when (authName) {
{{#authMethods}}"{{name}}" -> {{#isBasic}}{{#isBasicBasic}}HttpBasicAuth(){{/isBasicBasic}}{{#isBasicBearer}}HttpBearerAuth("{{scheme}}"){{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{#isKeyInQuery}}"query"{{/isKeyInQuery}}{{#isKeyInCookie}}"cookie"{{/isKeyInCookie}}, "{{keyParamName}}"){{/isApiKey}}{{#isOAuth}}OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{^-last}}, {{/-last}}{{/scopes}}"){{/isOAuth}}{{/authMethods}}
{{#authMethods}}"{{name}}" -> {{#isBasic}}{{#isBasicBasic}}HttpBasicAuth(){{/isBasicBasic}}{{^isBasicBasic}}{{#isBasicBearer}}HttpBearerAuth("{{scheme}}"){{/isBasicBearer}}{{^isBasicBearer}}throw RuntimeException("auth name $authName does not have a supported http scheme type"){{/isBasicBearer}}{{/isBasicBasic}}{{/isBasic}}{{#isApiKey}}ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{#isKeyInQuery}}"query"{{/isKeyInQuery}}{{#isKeyInCookie}}"cookie"{{/isKeyInCookie}}, "{{keyParamName}}"){{/isApiKey}}{{#isOAuth}}OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{^-last}}, {{/-last}}{{/scopes}}"){{/isOAuth}}{{/authMethods}}
Copy link
Contributor Author

@tiffmaelite tiffmaelite May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: that part might be a breaking change for those relying on the bug

@@ -70,7 +70,7 @@ public ApiClient(String[] authNames) {
} else if ("bearer_test".equals(authName)) {
auth = new HttpBearerAuth("bearer");
} else if ("http_signature_test".equals(authName)) {
auth = new HttpBearerAuth("signature");
throw new RuntimeException("auth name \"" + authName + "\" does not have a supported http scheme type");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: that part might be a breaking change for those relying on the bug

@tiffmaelite tiffmaelite force-pushed the fix/align_use-HttpBearerAuth_import-HttpBearerAuth branch from 97a7d50 to 97ea4e2 Compare May 22, 2023 06:39
@tiffmaelite tiffmaelite changed the title [Java] [Kotlin] (#14876) do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) [Java] [Kotlin] (#14876) fix use of isBasic conditions - do not use HttpBearerAuth (or HttpBasicAuth) for other http auth methods (such as http signature auth or custom schemes) May 22, 2023
@wing328 wing328 merged commit cbcf3d3 into OpenAPITools:master May 22, 2023
@tiffmaelite tiffmaelite deleted the fix/align_use-HttpBearerAuth_import-HttpBearerAuth branch May 22, 2023 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants