我正在使用springdoc-openapi-ui-1.4.3的swagger
@SecurityRequirement(name = "security_auth")
public class ProductController {}设置安全架构
@SecurityScheme(name = "security_auth", type = SecuritySchemeType.OAUTH2,
flows = @OAuthFlows(authorizationCode = @OAuthFlow(
authorizationUrl = "${springdoc.oAuthFlow.authorizationUrl}"
, tokenUrl = "${springdoc.oAuthFlow.tokenUrl}",scopes = {
@OAuthScope(name = "IdentityPortal.API", description = "IdentityPortal.API")})))
public class OpenApiConfig {}安全配置
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {// @formatter:off
http
.authorizeRequests()
.antMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html")
.permitAll()
.antMatchers(HttpMethod.GET, "/user/info", "/api/foos/**")
.hasAuthority("SCOPE_read")
.antMatchers(HttpMethod.POST, "/api/foos")
.hasAuthority("SCOPE_write")
.anyRequest()
.authenticated()
.and()
.oauth2ResourceServer()
.jwt();
}
}使用依赖项
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springdoc:springdoc-openapi-ui:1.4.3'
implementation 'org.springdoc:springdoc-openapi-security:1.4.3'
implementation "org.springframework.boot:spring-boot-starter-security"配置设置
spring:
profiles:
active: dev
####### resource server configuration properties
security:
oauth2:
resourceserver:
jwt:
issuer-uri: https://localhost:5001
jwk-set-uri: https://localhost:5001/connect/token
springdoc:
swagger-ui:
oauth:
clientId: Local
usepkcewithauthorizationcodegrant: true
oAuthFlow:
authorizationUrl: https://localhost:5001
tokenUrl: https://localhost:5001/connect/token在swagger UI中,clientId为空,客户端密钥存在,因为授权码+ PKCE流客户端密钥不应存在。

发布于 2020-08-02 21:30:43
您的属性语法
使用带授权码授权的kce.
不正确:
以下是PKCE的正确属性:
springdoc.swagger-ui.oauth.use-pkce-with-authorization-code-grant=true要填充客户端id,只需使用:
springdoc.swagger-ui.oauth.client-id=yourSPAClientId你对现有机密文件的评论是可以隐藏的。这看起来像是swagger-ui的增强。
您应该提交关于swagger-ui项目的增强:
发布于 2021-05-28 16:10:59
你问这个问题已经有一段时间了,但我会回答其他人的信息。主要的问题是UI的误导性实现。您必须在配置中使用授权码流,因为缺少带有PKCE的授权码。因此,您必须使用授权码(因为您需要提供授权和令牌url),并在yaml中放置一个虚拟秘密。下面是一个例子。
@SecurityScheme(name = "security_auth", type = SecuritySchemeType.OAUTH2,
flows = @OAuthFlows(authorizationCode = @OAuthFlow(
authorizationUrl = "${springdoc.oAuthFlow.authorizationUrl}"
, tokenUrl = "${springdoc.oAuthFlow.tokenUrl}")))
public class OpenApiConfig {}如果你想使用PKCE而不是纯隐式的设置正确的属性(如@brianbro所指出的)和一个虚拟秘密,如下所示:
springdoc.swagger-ui.oauth.use-pkce-with-authorization-code-grant=true
springdoc.swagger-ui.oauth.clent-secret=justFillerBecausePKCEisUsed最重要的是,如果您想预先填充client_id use配置:
springdoc.swagger-ui.oauth.client-id=YourClientIdhttps://stackoverflow.com/questions/62950730
复制相似问题