Skip to content

Commit 91517d1

Browse files
committed
Merge remote-tracking branch 'origin/2.x' into 2.x
2 parents 82a4567 + 725e98d commit 91517d1

File tree

2 files changed

+74
-9
lines changed

2 files changed

+74
-9
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/configuration/SpringDocSecurityOAuth2Customizer.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.swagger.v3.oas.models.media.ObjectSchema;
1515
import io.swagger.v3.oas.models.media.Schema;
1616
import io.swagger.v3.oas.models.media.StringSchema;
17+
import io.swagger.v3.oas.models.parameters.HeaderParameter;
1718
import io.swagger.v3.oas.models.parameters.Parameter;
1819
import io.swagger.v3.oas.models.parameters.RequestBody;
1920
import io.swagger.v3.oas.models.responses.ApiResponse;
@@ -32,6 +33,7 @@
3233
import org.springframework.context.ApplicationContextAware;
3334
import org.springframework.http.HttpMethod;
3435
import org.springframework.http.HttpStatus;
36+
import org.springframework.security.oauth2.core.AuthorizationGrantType;
3537
import org.springframework.security.oauth2.core.OAuth2Error;
3638
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
3739
import org.springframework.security.oauth2.server.authorization.web.NimbusJwkSetEndpointFilter;
@@ -202,8 +204,28 @@ private void getOAuth2TokenEndpoint(OpenAPI openAPI, SecurityFilterChain securit
202204
buildApiResponsesOnBadRequest(apiResponses, openAPI);
203205
buildOAuth2Error(openAPI, apiResponses, HttpStatus.UNAUTHORIZED);
204206
Operation operation = buildOperation(apiResponses);
205-
Schema<?> schema = new ObjectSchema().additionalProperties(new StringSchema());
206-
operation.addParametersItem(new Parameter().name("parameters").in(ParameterIn.QUERY.toString()).schema(schema));
207+
208+
Schema<?> requestSchema = new ObjectSchema()
209+
.addProperty(OAuth2ParameterNames.GRANT_TYPE,
210+
new StringSchema()
211+
.addEnumItem(AuthorizationGrantType.AUTHORIZATION_CODE.getValue())
212+
.addEnumItem(AuthorizationGrantType.REFRESH_TOKEN.getValue())
213+
.addEnumItem(AuthorizationGrantType.CLIENT_CREDENTIALS.getValue()))
214+
.addProperty(OAuth2ParameterNames.CODE, new StringSchema())
215+
.addProperty(OAuth2ParameterNames.REDIRECT_URI, new StringSchema())
216+
.addProperty(OAuth2ParameterNames.REFRESH_TOKEN, new StringSchema())
217+
.addProperty(OAuth2ParameterNames.SCOPE, new StringSchema())
218+
.addProperty(OAuth2ParameterNames.CLIENT_ID, new StringSchema())
219+
.addProperty(OAuth2ParameterNames.CLIENT_SECRET, new StringSchema())
220+
.addProperty(OAuth2ParameterNames.CLIENT_ASSERTION_TYPE, new StringSchema())
221+
.addProperty(OAuth2ParameterNames.CLIENT_ASSERTION, new StringSchema())
222+
.addProperty("additionalParameters", new ObjectSchema().additionalProperties(new StringSchema()));
223+
224+
String mediaType = org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE;
225+
RequestBody requestBody = new RequestBody().content(new Content().addMediaType(mediaType, new MediaType().schema(requestSchema)));
226+
operation.setRequestBody(requestBody);
227+
operation.addParametersItem(new HeaderParameter().name("Authorization"));
228+
207229
buildPath(oAuth2EndpointFilter, "tokenEndpointMatcher", openAPI, operation, HttpMethod.POST);
208230
}
209231
}

springdoc-openapi-tests/springdoc-openapi-security-tests/src/test/resources/results/app10.json

+50-7
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,59 @@
101101
],
102102
"parameters": [
103103
{
104-
"name": "parameters",
105-
"in": "query",
106-
"schema": {
107-
"type": "object",
108-
"additionalProperties": {
109-
"type": "string"
104+
"in": "header",
105+
"name": "Authorization"
106+
}
107+
],
108+
"requestBody": {
109+
"content": {
110+
"application/x-www-form-urlencoded": {
111+
"schema": {
112+
"type": "object",
113+
"properties": {
114+
"grant_type": {
115+
"type": "string",
116+
"enum": [
117+
"authorization_code",
118+
"refresh_token",
119+
"client_credentials"
120+
]
121+
},
122+
"code": {
123+
"type": "string"
124+
},
125+
"redirect_uri": {
126+
"type": "string"
127+
},
128+
"refresh_token": {
129+
"type": "string"
130+
},
131+
"scope": {
132+
"type": "string"
133+
},
134+
"client_id": {
135+
"type": "string"
136+
},
137+
"client_secret": {
138+
"type": "string"
139+
},
140+
"client_assertion_type": {
141+
"type": "string"
142+
},
143+
"client_assertion": {
144+
"type": "string"
145+
},
146+
"additionalParameters": {
147+
"type": "object",
148+
"additionalProperties": {
149+
"type": "string"
150+
}
151+
}
152+
}
110153
}
111154
}
112155
}
113-
],
156+
},
114157
"responses": {
115158
"200": {
116159
"description": "OK",

0 commit comments

Comments
 (0)