我正在使用 Spring 安全性设置 OAuth 2.0 授权服务器。我想使用 Swagger 记录 OAuth 2.0 API。我该怎么做呢?
问问题
700 次
1 回答
1
我目前正在研究它,我正在使用 Springfox 库来记录它。
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
我的 Swagger 配置如下所示:
@Configuration
@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig {
@Bean
public Docket documentation() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.useDefaultResponseMessages(false)
.pathMapping("/")
.apiInfo(apiInfo());
}
/**
* API INFO
* @return
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("xxx")
.description("xxx")
.version("xxx")
.contact("xxx")
.build();
}
}
我的端点之一的一部分(注意:没有正确的方法来注释地图。2.4.0 添加了支持,但我还没有尝试过。)
@Api(value = "xxx")
@FrameworkEndpoint
@SessionAttributes("authorizationRequest")
public class OAuthAuthorizationEndpoint {
private AuthorizationEndpoint authorizationEndpoint;
/**
* @param endpoint
* base AuthorizationCheckpoint
*/
public OAuthAuthorizationEndpoint(AuthorizationEndpoint endpoint){
this.authorizationEndpoint = endpoint;
}
@ApiOperation(value = "xxx", httpMethod = "GET", notes = "xxx")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid input:...", response = Auth400Response.class),
@ApiResponse(code = 200, message = "Ok", response = Auth200Response.class)
})
@RequestMapping(value = "/oauth/authorize", produces = "application/json")
@ResponseBody
public ModelAndView authorize(@ApiIgnore Map<String, Object> model,
@ApiParam(value = "xxx", required = true, defaultValue = "xxx") @RequestParam String response_type,
@ApiParam(value = "xxx", required = true) @RequestParam String client_id,
@ApiParam(value = "xxx", required = true) @RequestParam String redirect_uri,
@ApiParam(value = "xxx", required = false, defaultValue = "/") @RequestParam String realm,
@ApiParam(value = "xxx", required = false) @RequestParam String state,
@ApiIgnore SessionStatus sessionStatus, @ApiIgnore Principal principal){
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("response_type", response_type);
parameters.put("client_id", client_id);
parameters.put("realm", realm);
parameters.put("redirect_uri", redirect_uri);
parameters.put("state", state);
return this.authorizationEndpoint.authorize(model, parameters, sessionStatus, principal);
这可能会帮助你。
于 2016-03-09T11:05:47.870 回答