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

add request parameter for token endpoint #2167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -14,6 +14,7 @@
import io.swagger.v3.oas.models.media.ObjectSchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.parameters.HeaderParameter;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.parameters.RequestBody;
import io.swagger.v3.oas.models.responses.ApiResponse;
Expand All @@ -32,6 +33,7 @@
import org.springframework.context.ApplicationContextAware;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.core.OAuth2Error;
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
import org.springframework.security.oauth2.server.authorization.web.NimbusJwkSetEndpointFilter;
Expand Down Expand Up @@ -202,8 +204,28 @@ private void getOAuth2TokenEndpoint(OpenAPI openAPI, SecurityFilterChain securit
buildApiResponsesOnBadRequest(apiResponses, openAPI);
buildOAuth2Error(openAPI, apiResponses, HttpStatus.UNAUTHORIZED);
Operation operation = buildOperation(apiResponses);
Schema<?> schema = new ObjectSchema().additionalProperties(new StringSchema());
operation.addParametersItem(new Parameter().name("parameters").in(ParameterIn.QUERY.toString()).schema(schema));

Schema<?> requestSchema = new ObjectSchema()
.addProperty(OAuth2ParameterNames.GRANT_TYPE,
new StringSchema()
.addEnumItem(AuthorizationGrantType.AUTHORIZATION_CODE.getValue())
.addEnumItem(AuthorizationGrantType.REFRESH_TOKEN.getValue())
.addEnumItem(AuthorizationGrantType.CLIENT_CREDENTIALS.getValue()))
.addProperty(OAuth2ParameterNames.CODE, new StringSchema())
.addProperty(OAuth2ParameterNames.REDIRECT_URI, new StringSchema())
.addProperty(OAuth2ParameterNames.REFRESH_TOKEN, new StringSchema())
.addProperty(OAuth2ParameterNames.SCOPE, new StringSchema())
.addProperty(OAuth2ParameterNames.CLIENT_ID, new StringSchema())
.addProperty(OAuth2ParameterNames.CLIENT_SECRET, new StringSchema())
.addProperty(OAuth2ParameterNames.CLIENT_ASSERTION_TYPE, new StringSchema())
.addProperty(OAuth2ParameterNames.CLIENT_ASSERTION, new StringSchema())
.addProperty("additionalParameters", new ObjectSchema().additionalProperties(new StringSchema()));

String mediaType = org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE;
RequestBody requestBody = new RequestBody().content(new Content().addMediaType(mediaType, new MediaType().schema(requestSchema)));
operation.setRequestBody(requestBody);
operation.addParametersItem(new HeaderParameter().name("Authorization"));

buildPath(oAuth2EndpointFilter, "tokenEndpointMatcher", openAPI, operation, HttpMethod.POST);
}
}
Expand Down
57 changes: 50 additions & 7 deletions springdoc-openapi-security/src/test/resources/results/app10.json
Expand Up @@ -101,16 +101,59 @@
],
"parameters": [
{
"name": "parameters",
"in": "query",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
"in": "header",
"name": "Authorization"
}
],
"requestBody": {
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"type": "object",
"properties": {
"grant_type": {
"type": "string",
"enum": [
"authorization_code",
"refresh_token",
"client_credentials"
]
},
"code": {
"type": "string"
},
"redirect_uri": {
"type": "string"
},
"refresh_token": {
"type": "string"
},
"scope": {
"type": "string"
},
"client_id": {
"type": "string"
},
"client_secret": {
"type": "string"
},
"client_assertion_type": {
"type": "string"
},
"client_assertion": {
"type": "string"
},
"additionalParameters": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
}
],
},
"responses": {
"200": {
"description": "OK",
Expand Down