Skip to content

Swagger-UI OAuth2: CORS Error when requesting token  #2277

Closed
@PhilKes

Description

@PhilKes

In short, I have the exact same problem as described in #1179 by @JamesTaylor04, unfortunately the author closed the issue and did not report what his solution was.
I configured OpenAPI as follows:

@OpenAPIDefinition(info = @Info(title = "application",
        description = "TODO", version = "v1"))
@SecurityScheme(name = "oauth2, type = SecuritySchemeType.OAUTH2,
        flows = @OAuthFlows(clientCredentials = @OAuthFlow(tokenUrl = "${spring.security.oauth2.client.provider.oauth2-provider.token-uri}")))
public class OpenApiConfig {
}

Swagger-Ui shows the authorize button, the form with the correct values for the token endpoint, client-id + client-secret.
But when I press authorize and it requests the POST https://{OAUTH2_SERVER}/realms/${OAUTH2_REALM}/protocol/openid-connect/token' endpoint, but then returns a CORS error:

Access to fetch at '.../token' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

The OAuth2 server is not hosted on the same domain as the Swagger-UI/Spring-Boot-Application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions