To enable the Authorize button for authorization in a Swagger API with springdoc-openapi-starter-webmvc-ui, follow these steps:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>{version}</version>
</dependency>
@EnableWebSecurity
:@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/api/**")
.authenticated()
.and()
.httpBasic();
}
}
@SecurityScheme
:@SecurityScheme(
name = "basicAuth",
type = SecuritySchemeType.HTTP,
scheme = "basic")
public class SpringdocOpenApiConfig {
// ...
}
@OpenAPIDefinition
annotation:@OpenAPIDefinition(
security = @SecurityRequirement(
name = "basicAuth",
scopes = {})
)
public class SpringdocOpenApiConfig {
// ...
}
Run your application and navigate to the Swagger UI page. The Authorize button should now be enabled.
Click the Authorize button and enter your username and password in the dialog box that appears.
After clicking the Authorize button, you should be authenticated and authorized to access the protected API resources.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-09-25 11:00:00 +0000
Seen: 16 times
Last updated: Aug 07 '21
How can SSL passthrough be implemented with Traefik in Kubernetes?
What is the way to name parameters and REST API urls in Spring Boot?
How can Django Admin accommodate a variety of formats and locales for its input fields?
How can an array be passed using typo3 flexform xml and itemsProcConfig?
Is it possible to invoke an asynchronous function without using the await keyword?