Closed tamilsmani closed 3 years ago
Attached the screenshot.
Hello @tamilsmani , did you solve your problem? I'm having the same difficulty.
Just to be sure that we are all on the same page, is your app registered with the destination app?
Hi @debargharoy, I didn't understand the question.
CORS is related to your configuration. You need to have CORS enabled, on your applications that is blocking the swagger-ui.
You should add swagger configuration
@Configuration
@OpenAPIDefinition(servers = {
@Server(url = "/", description = "Default Server URL")
})
public class SwaggerConfiguration {
@Bean
public OpenAPI customOpenAPI(@Value("springdoc-openapi-ui") String serviceTitle, @Value("1.6.12") String serviceVersion) {
final String securitySchemeName = "bearerAuth";
return new OpenAPI()
.components(
new Components().addSecuritySchemes(
securitySchemeName,
new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")
)
)
.security(List.of(new SecurityRequirement().addList(securitySchemeName)))
.info(new Info().title(serviceTitle).version(serviceVersion));
}
}
Hello, I have the same problem. I have tried ot remove the Origin header, replicating the request with cURL, and it works. How to is possible to avoid the Origin header apppended?
Just to note here, even if I disable CORS in my application, the integrated swagger will throw a CORS error.
Same issue by me anyone has a solution?
I have the same issue with the latest version of spring boot, java (21) and springdoc
Same issue for me as well
I am trying to integrate spring boot with Swagger using springdoc-openapi-ui. I have enabled OAuth security (Client credentials). when I fetch the OAuth token, I am getting the CORS error on the UI (attached the screenshot on the same)
Config details
@Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurer() { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("") .allowedOrigins("").allowCredentials(true) .allowedHeaders("") .allowedMethods(""); } }; }
@Bean public OpenAPI oauthOpenAPI(Server server) { LOGGER.info(String.format(SWAGGER_SECURITY_LOG, "oauth2-security")); return openAPI .servers(List.of(server)) .components(new Components() .addSecuritySchemes("Authentication", new SecurityScheme() .type(SecurityScheme.Type.OAUTH2) .description("Oauth2 flow") .flows(new OAuthFlows() .clientCredentials(new OAuthFlow() .authorizationUrl(tokenURL) .refreshUrl(tokenURL) .tokenUrl(tokenURL) .scopes(new Scopes())) ))); }
Spring boot version: 2.3.3.RELEASE org.springdoc:springdoc-openapi-ui:jar:1.5.9
Could u help me in resolve the issue?