Skip to content
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

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

Closed
PhilKes opened this issue Jun 23, 2023 · 1 comment
Closed

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

PhilKes opened this issue Jun 23, 2023 · 1 comment
Labels
invalid This doesn't seem right

Comments

@PhilKes
Copy link

PhilKes commented Jun 23, 2023

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.

@bnasslahsen
Copy link
Collaborator

@PhilKes,

It's definetly a CORS setting issue in your code - that has nothing to do with springdoc-openapi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants