Skip to content

OAuth2: Cors Error #1179

Closed
Closed
@JamesTaylor04

Description

@JamesTaylor04

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();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions