Skip to content

OAuth2: Cors Error #1179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JamesTaylor04 opened this issue Jun 6, 2021 · 1 comment
Closed

OAuth2: Cors Error #1179

JamesTaylor04 opened this issue Jun 6, 2021 · 1 comment

Comments

@JamesTaylor04
Copy link

Hello, when using springdoc and spring security oauth2 server, I encountered a problem, called CORS error after authenticated from keycloak, and below is the error message of browser, Sincerely need your help.

屏幕截图 2021-06-06 110150

  • My OpenAPI COnfiguration FIle
package com.dooool.cloud.services.usm.config;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.security.OAuthFlow;
import io.swagger.v3.oas.annotations.security.OAuthFlows;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.annotations.servers.Server;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 文档配置类
 *
 * @author Aris Hu created at 2021-04-17
 */
@Configuration
@OpenAPIDefinition(
    servers = @Server(url = "http://localhost:9080/usm"),
    info = @Info(
        title = "Upload Service API",
        description = "上传服务接口",
        version = "V1.0.0",
        license = @License(name = "MIT License", url = "/usm/LICENSE.txt")
    )
)
@SecurityScheme(
    name = "keycloak",
    type = SecuritySchemeType.OAUTH2,
    openIdConnectUrl = "${provider.keycloak.url}",
    flows = @OAuthFlows(
        authorizationCode = @OAuthFlow(
            authorizationUrl = "${provider.keycloak.authorization-uri}",
            tokenUrl = "${provider.keycloak.token-uri}"
        )
    )
)
public class DocumentationConfig {

  @Bean
  public GroupedOpenApi uploadApi() {
    return GroupedOpenApi.builder()
        .group("Upload API")
        .pathsToMatch("/api/upload/**")
        .build();
  }
}
@JamesTaylor04
Copy link
Author

solved

@springdoc springdoc deleted a comment from tanercakiroglu Sep 18, 2021
@springdoc springdoc locked as too heated and limited conversation to collaborators Sep 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant