Spring セキュリティを使用して OAuth 2.0 承認サーバーのセットアップに取り組んでいます。Swagger を使用して OAuth 2.0 API を文書化したいと思います。どうすればいいですか?
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 Config は次のようになります。
@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();
}
}
私のエンドポイントの 1 つの一部 (注: マップに注釈を付ける適切な方法がありませんでした。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 に答える