Skip to content

Add new OAuth2RequestInterceptor to remove deprecated open feign classes #16011

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

Merged
merged 16 commits into from
Jul 13, 2023

Conversation

MelleD
Copy link
Contributor

@MelleD MelleD commented Jul 5, 2023

Fix #8561 and #16023

The project spring-cloud-starter-oauth2 is EOL and there is no replacement see issue spring-cloud/spring-cloud-openfeign#417

One approach to replace the classes is described here: https://stackoverflow.com/questions/63283022/feign-and-spring-security-5-client-credentials

This PR implements the idea for the open feign client for open api generator.

This PR BREAKS the current implementation and the clients need to be migrated

Migration guide:

Solution 1:
Replace the old properties and set the new properties:

spring.security.oauth2.client.registration.{{{your-name}}}.enabled=true
spring.security.oauth2.client.registration.{{{your-name}}}.client-id=
spring.security.oauth2.client.registration.{{{your-name}}}.client-secret=
spring.security.oauth2.client.registration.{{{your-name}}}.scope=
spring.security.oauth2.client.registration.{{{your-name}}}.authorization-grant-type=
spring.security.oauth2.client.provider.{{{your-name}}}.token-uri=uri

Solution 2:

From the open api some properties are generated. So there is a new property file oauth2-client.properties.
In this property file the same information are generated as before so authorization-grant-type, token-uri, authorizationUrl are used directly from the yaml file.
If you would like to reuse this information, just import the Configuration file into you application
@Import( { ClientPropertiesConfiguration.class} )
or use directly
@PropertySource( "classpath:/oauth2-client.properties" )

Then replace all old properties to this new properties:

spring.security.oauth2.client.registration.{{{your-name}}}.enabled=true
spring.security.oauth2.client.registration.{{{your-name}}}.client-id=
spring.security.oauth2.client.registration.{{{your-name}}}.client-secret=
spring.security.oauth2.client.registration.{{{your-name}}}.scope=

With this PR, the resource folder for the property file can now also be changed in the maven plugin. Default is src/main/resources/

Open points: Where should the migration guide be added?

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.
  • In case you are adding a new generator, run the following additional script :
    ./bin/utils/ensure-up-to-date
    
    Commit all changed files.
  • File the PR against 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.

@cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09)

@MelleD MelleD requested a review from jimschubert as a code owner July 5, 2023 13:37
@MelleD
Copy link
Contributor Author

MelleD commented Jul 5, 2023

@wing328 don't understand the changes for ./bin/generate-samples.sh with the FakeApi.cs.
Didn't change anything on this place, correct?

@wing328
Copy link
Member

wing328 commented Jul 7, 2023

Thanks for the PR. Is it correct to say that you added resourceFolder as a global option (similar to httpUserAgent, which is available and should be supported in all generators) ?

Why not add it as an option in the spring generator?

(for example, I don't think the Groovy client generator supports this new option)

@MelleD
Copy link
Contributor Author

MelleD commented Jul 7, 2023

Why not add it as an option in the spring generator?

(for example, I don't think the Groovy client generator supports this new option)

No strong opinion on that can move it, if you want.

I just see that some generator have hardcoded resource folder. So I thought maybe they also want to use in future this resource folder option, but also fine for me to move it.

How can I change the doc for spring.md? If I change the spring.md all mds are changed after the export docs?

@wing328
Copy link
Member

wing328 commented Jul 8, 2023

How can I change the doc for spring.md? If I change the spring.md all mds are changed after the export docs?

spring.md is autogenerated. you will need to update the code (e.g. option description) in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java#L194

@wing328
Copy link
Member

wing328 commented Jul 8, 2023

I just see that some generator have hardcoded resource folder. So I thought maybe they also want to use in future this resource folder option, but also fine for me to move it.

Your intention is good 👍

We want to avoid escalations saying certain option is not working in the generators so we will instead add the option to the supported generators one by one.

@MelleD
Copy link
Contributor Author

MelleD commented Jul 8, 2023

@wing328 fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REQ] [SPRING-CLOUD] Generates deprecated code
2 participants