【发布时间】:2020-11-27 23:39:42
【问题描述】:
我使用 Spring Security 5 为 Swagger 构建 OAuth2 登录和 SpringFox。
有一个端点/oauth2/authorization/my-oauth,但这个端点没有出现在/swagger-ui/ 中。如何让它出现在swagger-ui?需要登录的端点也不正确。
端点的工作方式类似于重定向到应该由浏览器打开的 Google/Facebook/Github 登录网页,但 Swagger 显示
已经尝试了https://stackoverflow.com/a/45921169/3952994的解决方案,但是还是不行,端点还是没有出现。
相关代码:
@Configuration
@EnableSwagger2
class SwaggerConfig {
@Bean
fun api() = Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
@Configuration
@EnableWebSecurity
class OAuth2SecurityConfig @Autowired constructor(
private val myAuthRequestResolver: MyAuthRequestResolver,
private val myAccessTokenResponseClient: MyAccessTokenResponseClient): WebSecurityConfigurerAdapter() {
override fun configure(http: HttpSecurity) {
http.authorizeRequests()
.antMatchers("/v1/token**")
.authenticated()
.and()
.csrf()
.disable()
.oauth2Login()
.authorizationEndpoint()
.authorizationRequestResolver(myAuthRequestResolver)
.and()
.tokenEndpoint()
.accessTokenResponseClient(myAccessTokenResponseClient)
}
}
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
【问题讨论】:
标签: spring spring-boot spring-security springfox