'Oauth2 token request missing Basic credentials with openapi-generator generated java code
I'm trying to use generated (java) code with openapi-generator to access oauth2 securized api endpoints.
Generated code is done with open-api-generator-maven-plugin with pom :
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.4.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>/home/git/scpec.json</inputSpec>
<skipValidateSpec>true</skipValidateSpec>
<generatorName>java</generatorName>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<apiPackage>test.storage.api</apiPackage>
<modelPackage>test.storage.model</modelPackage>
<configOptions>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The generated code seams to be welll formed. To use the generated code i'm running the here under exemple :
HashMap parameters = new HashMap<>();
parameters.put("scope","perf");
parameters.put("login","user-login");
parameters.put("password","xxxxxxxxxxxxxxx");
parameters.put("grant_type","password");
ApiClient client = new ApiClient(url, "clientId", "clientSecret", parameters);
PluginControllerApi api = new PluginControllerApi(client);
List<EntityModelString> types = api.getPluginTypes(true);
Assertions.assertTrue(!types.isEmpty());
The generate code is generated with the here under spec :
{
"openapi": "3.0.1",
"info": {
"title": "Storage service",
"description": "Files storage management",
"license": {
"name": "GPL-3.0"
},
"version": "1.0.0"
},
"servers": [
{
"url": "http://myserver/api/v1/rs-storage",
"description": "Generated server url"
}
],
"security": [
{
"REGARDS_OAUTH2": []
}
],
"paths": {
"/plugintypes": {
"get": {
"tags": [
"plugin-controller"
],
"operationId": "getPluginTypes",
"parameters": [
{
"name": "available",
"in": "query",
"required": false,
"schema": {
"type": "boolean"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/EntityModelString"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"EntityModelString": {
"type": "object",
"properties": {
"content": {
"type": "string"
},
"links": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Link"
}
}
}
},
"Link": {
"type": "object",
"properties": {
"rel": {
"type": "string"
},
"href": {
"type": "string"
},
"hreflang": {
"type": "string"
},
"media": {
"type": "string"
},
"title": {
"type": "string"
},
"type": {
"type": "string"
},
"deprecation": {
"type": "string"
},
"profile": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"securitySchemes": {
"REGARDS_OAUTH2": {
"type": "oauth2",
"flows": {
"password": {
"tokenUrl": "http://myserver/api/v1/rs-authentication/oauth/token",
"scopes": {
"perf": ""
}
}
}
}
}
}
}
When i run my test code, the client api call the configured endpoint to authneticate but in the oauth/token@POST request sent the header "Authorization: basic xxxxxxx" (where xxxx is clientId:clientSecret coded in base64) is not proovided. This header is needed by oauth2 to authenticate the client before authenticate the user.
Is there a way to configure anything to add this header in the oauth2 token request ?
Thanks.
EDIT : It seems that my question is related to an opend issue : https://github.com/swagger-api/swagger-codegen/issues/7648. Is there any fix planned ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
