-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[Spring] Add clientRegistrationId option for OAuth2 HTTP Interface #22726
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
Open
ng-galien
wants to merge
4
commits into
OpenAPITools:master
Choose a base branch
from
ng-galien:claude/add-clientregistrationid-annotation-rmTC0
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+9,460
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1e32930
feat(spring): Add @ClientRegistrationId support for Spring HTTP Inter…
claude fc5d3a1
refactor: Move @ClientRegistrationId annotation to class level
claude 260a295
test(spring): Add unit tests for clientRegistrationId option
ng-galien 8b6063c
fix: Update Spring Boot to 3.5.0 for @ClientRegistrationId support
ng-galien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| generatorName: spring | ||
| library: spring-http-interface | ||
| outputDir: samples/client/petstore/spring-http-interface-oauth | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
| additionalProperties: | ||
| artifactId: spring-http-interface-oauth | ||
| snapshotVersion: "true" | ||
| hideGenerationTimestamp: "true" | ||
| modelNameSuffix: 'Dto' | ||
| generatedConstructorWithRequiredArgs: "false" | ||
| clientRegistrationId: "petstore-oauth" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
samples/client/petstore/spring-http-interface-oauth/.openapi-generator-ignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # OpenAPI Generator Ignore | ||
| # Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
|
||
| # Use this file to prevent files from being overwritten by the generator. | ||
| # The patterns follow closely to .gitignore or .dockerignore. | ||
|
|
||
| # As an example, the C# client generator defines ApiClient.cs. | ||
| # You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
| #ApiClient.cs | ||
|
|
||
| # You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
| #foo/*/qux | ||
| # The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
|
||
| # You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
| #foo/**/qux | ||
| # This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
|
||
| # You can also negate patterns with an exclamation (!). | ||
| # For example, you can ignore all files in a docs folder with the file extension .md: | ||
| #docs/*.md | ||
| # Then explicitly reverse the ignore rule for a single file: | ||
| #!docs/README.md |
60 changes: 60 additions & 0 deletions
60
samples/client/petstore/spring-http-interface-oauth/.openapi-generator/FILES
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| .openapi-generator-ignore | ||
| README.md | ||
| pom.xml | ||
| src/main/java/org/openapitools/api/AnotherFakeApi.java | ||
| src/main/java/org/openapitools/api/FakeApi.java | ||
| src/main/java/org/openapitools/api/FakeClassnameTags123Api.java | ||
| src/main/java/org/openapitools/api/PetApi.java | ||
| src/main/java/org/openapitools/api/StoreApi.java | ||
| src/main/java/org/openapitools/api/UserApi.java | ||
| src/main/java/org/openapitools/configuration/HttpInterfacesAbstractConfigurator.java | ||
| src/main/java/org/openapitools/model/AdditionalPropertiesAnyTypeDto.java | ||
| src/main/java/org/openapitools/model/AdditionalPropertiesArrayDto.java | ||
| src/main/java/org/openapitools/model/AdditionalPropertiesBooleanDto.java | ||
| src/main/java/org/openapitools/model/AdditionalPropertiesClassDto.java | ||
| src/main/java/org/openapitools/model/AdditionalPropertiesIntegerDto.java | ||
| src/main/java/org/openapitools/model/AdditionalPropertiesNumberDto.java | ||
| src/main/java/org/openapitools/model/AdditionalPropertiesObjectDto.java | ||
| src/main/java/org/openapitools/model/AdditionalPropertiesStringDto.java | ||
| src/main/java/org/openapitools/model/AnimalDto.java | ||
| src/main/java/org/openapitools/model/ApiResponseDto.java | ||
| src/main/java/org/openapitools/model/ArrayOfArrayOfNumberOnlyDto.java | ||
| src/main/java/org/openapitools/model/ArrayOfNumberOnlyDto.java | ||
| src/main/java/org/openapitools/model/ArrayTestDto.java | ||
| src/main/java/org/openapitools/model/BigCatDto.java | ||
| src/main/java/org/openapitools/model/CapitalizationDto.java | ||
| src/main/java/org/openapitools/model/CatDto.java | ||
| src/main/java/org/openapitools/model/CategoryDto.java | ||
| src/main/java/org/openapitools/model/ChildWithNullableDto.java | ||
| src/main/java/org/openapitools/model/ClassModelDto.java | ||
| src/main/java/org/openapitools/model/ClientDto.java | ||
| src/main/java/org/openapitools/model/ContainerDefaultValueDto.java | ||
| src/main/java/org/openapitools/model/DogDto.java | ||
| src/main/java/org/openapitools/model/EnumArraysDto.java | ||
| src/main/java/org/openapitools/model/EnumClassDto.java | ||
| src/main/java/org/openapitools/model/EnumTestDto.java | ||
| src/main/java/org/openapitools/model/FileDto.java | ||
| src/main/java/org/openapitools/model/FileSchemaTestClassDto.java | ||
| src/main/java/org/openapitools/model/FormatTestDto.java | ||
| src/main/java/org/openapitools/model/HasOnlyReadOnlyDto.java | ||
| src/main/java/org/openapitools/model/ListDto.java | ||
| src/main/java/org/openapitools/model/MapTestDto.java | ||
| src/main/java/org/openapitools/model/MixedPropertiesAndAdditionalPropertiesClassDto.java | ||
| src/main/java/org/openapitools/model/Model200ResponseDto.java | ||
| src/main/java/org/openapitools/model/NameDto.java | ||
| src/main/java/org/openapitools/model/NullableMapPropertyDto.java | ||
| src/main/java/org/openapitools/model/NumberOnlyDto.java | ||
| src/main/java/org/openapitools/model/OrderDto.java | ||
| src/main/java/org/openapitools/model/OuterCompositeDto.java | ||
| src/main/java/org/openapitools/model/OuterEnumDto.java | ||
| src/main/java/org/openapitools/model/ParentWithNullableDto.java | ||
| src/main/java/org/openapitools/model/PetDto.java | ||
| src/main/java/org/openapitools/model/ReadOnlyFirstDto.java | ||
| src/main/java/org/openapitools/model/ResponseObjectWithDifferentFieldNamesDto.java | ||
| src/main/java/org/openapitools/model/ReturnDto.java | ||
| src/main/java/org/openapitools/model/SpecialModelNameDto.java | ||
| src/main/java/org/openapitools/model/TagDto.java | ||
| src/main/java/org/openapitools/model/TypeHolderDefaultDto.java | ||
| src/main/java/org/openapitools/model/TypeHolderExampleDto.java | ||
| src/main/java/org/openapitools/model/UserDto.java | ||
| src/main/java/org/openapitools/model/XmlItemDto.java |
1 change: 1 addition & 0 deletions
1
samples/client/petstore/spring-http-interface-oauth/.openapi-generator/VERSION
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 7.19.0-SNAPSHOT |
97 changes: 97 additions & 0 deletions
97
samples/client/petstore/spring-http-interface-oauth/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # Spring HTTP Interface with OAuth2 (@ClientRegistrationId) | ||
|
|
||
| This sample demonstrates the use of the `@ClientRegistrationId` annotation with Spring HTTP Interface clients. | ||
|
|
||
| ## Overview | ||
|
|
||
| This code was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. | ||
| When generating Spring HTTP Interface clients, you can specify a `clientRegistrationId` parameter to automatically add the `@ClientRegistrationId` annotation to all generated API interfaces. | ||
|
|
||
| ## Configuration | ||
|
|
||
| Add the `clientRegistrationId` property to your generator configuration: | ||
|
|
||
| ```yaml | ||
| generatorName: spring | ||
| library: spring-http-interface | ||
| additionalProperties: | ||
| clientRegistrationId: "petstore-oauth" | ||
| ``` | ||
|
|
||
| Or via command line: | ||
|
|
||
| ```bash | ||
| openapi-generator-cli generate \ | ||
| -g spring \ | ||
| --library spring-http-interface \ | ||
| --additional-properties clientRegistrationId=petstore-oauth \ | ||
| -i petstore.yaml \ | ||
| -o ./output | ||
| ``` | ||
|
|
||
| ## Generated Code | ||
|
|
||
| The generated interface will include the `@ClientRegistrationId` annotation at the class level: | ||
|
|
||
| ```java | ||
| @ClientRegistrationId("petstore-oauth") | ||
| public interface PetApi { | ||
|
|
||
| @HttpExchange( | ||
| method = "GET", | ||
| value = "/pet/{petId}", | ||
| accept = { "application/json" } | ||
| ) | ||
| ResponseEntity<PetDto> getPetById(@PathVariable("petId") Long petId); | ||
| } | ||
| ``` | ||
|
|
||
| ## Spring Security Integration | ||
|
|
||
| This annotation is part of Spring Security's OAuth2 integration for HTTP Service Clients. It automatically associates OAuth2 tokens with HTTP requests. | ||
|
|
||
| ### Requirements | ||
|
|
||
| - Spring Boot 3.5+ | ||
| - Spring Security 6.5+ | ||
|
|
||
| ### Application Properties | ||
|
|
||
| Configure your Spring application with the OAuth2 client registration: | ||
|
|
||
| ```yaml | ||
| spring: | ||
| security: | ||
| oauth2: | ||
| client: | ||
| registration: | ||
| petstore-oauth: | ||
| client-id: your-client-id | ||
| client-secret: your-client-secret | ||
| authorization-grant-type: client_credentials | ||
| scope: read,write | ||
| provider: | ||
| petstore-oauth: | ||
| token-uri: https://auth.example.com/oauth/token | ||
| ``` | ||
|
|
||
| ### Bean Configuration | ||
|
|
||
| Use `RestClientHttpServiceGroupConfigurer` to configure the HTTP Service Proxy Factory: | ||
|
|
||
| ```java | ||
| @Configuration | ||
| public class HttpInterfaceConfig extends HttpInterfacesAbstractConfigurator { | ||
|
|
||
| public HttpInterfaceConfig() { | ||
| super(RestClient.builder() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Bean configuration example builds a bare RestClient and passes it to HttpInterfacesAbstractConfigurator, which takes a WebClient and applies no OAuth2 configurer—clients will lack OAuth2 support and the snippet won’t compile. Prompt for AI agents |
||
| .baseUrl("https://petstore.example.com/v2") | ||
| .build()); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## References | ||
|
|
||
| - [Spring Security HTTP Service Client Integration](https://docs.spring.io/spring-security/reference/servlet/oauth2/client/http-service-client.html) | ||
| - [Spring Framework HTTP Interface](https://docs.spring.io/spring-framework/reference/integration/rest-clients.html#rest-http-interface) | ||
80 changes: 80 additions & 0 deletions
80
samples/client/petstore/spring-http-interface-oauth/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| <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/maven-v4_0_0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <groupId>org.openapitools</groupId> | ||
| <artifactId>spring-http-interface-oauth</artifactId> | ||
| <packaging>jar</packaging> | ||
| <name>spring-http-interface-oauth</name> | ||
| <version>1.0.0-SNAPSHOT</version> | ||
| <properties> | ||
| <java.version>17</java.version> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
| <parent> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-parent</artifactId> | ||
| <version>3.5.0</version> | ||
| <relativePath/> <!-- lookup parent from repository --> | ||
| </parent> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <version>3.8.1</version> | ||
| <configuration> | ||
| <source>${java.version}</source> | ||
| <target>${java.version}</target> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-source-plugin</artifactId> | ||
| <version>3.2.1</version> | ||
| <executions> | ||
| <execution> | ||
| <id>attach-sources</id> | ||
| <goals> | ||
| <goal>jar-no-fork</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-webflux</artifactId> | ||
| </dependency> | ||
| <!-- @Nullable annotation --> | ||
| <dependency> | ||
| <groupId>com.google.code.findbugs</groupId> | ||
| <artifactId>jsr305</artifactId> | ||
| <version>3.0.2</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>jakarta.validation</groupId> | ||
| <artifactId>jakarta.validation-api</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.datatype</groupId> | ||
| <artifactId>jackson-datatype-jsr310</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.openapitools</groupId> | ||
| <artifactId>jackson-databind-nullable</artifactId> | ||
| <version>0.2.8</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-oauth2-client</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.