Hi,
when using authorization via Oauth2 the redirect URL is set to /oauth2-redirect.html so it misses contextpath and the path to /swagger-ui.
I've fixed it by overriding the SwaggerUiConfigProperties and add oauth2RedirectUrl to the configParameters property.
ExtenedSwaggerUiConfigProperties.java
````java
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.springdoc.core.SwaggerUiConfigProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import java.util.Map;
@Configuration
@Primary
@Getter
@Setter
public class ExtenedSwaggerUiConfigProperties extends SwaggerUiConfigProperties {
private String oauth2RedirectUrl;
public Map<String, String> getConfigParameters() {
Map<String, String> params = super.getConfigParameters();
if (StringUtils.isNotEmpty(oauth2RedirectUrl)) {
put("oauth2RedirectUrl"
, ServletUriComponentsBuilder.fromCurrentContextPath().path(oauth2RedirectUrl).build().toString()
, params);
}
return params;
}
}
application.properties
springdoc.swagger-ui.oauth2RedirectUrl=/swagger-ui/oauth2-redirect.html
````
Maybe it's possible to add the support for this property by default.
Hi,
Thank you for your sharing.
It will be added to v1.2.18. Please note that ServletUriComponentsBuilder will not be used, as this configuration will be shared with webflux as well.
The path of the Oauth2 redirect URL, should then the redirect url. (including the base path)
Hi,
I've tested the new v1.2.18 and I'm glad to see the attribute for oauth2RedirectUrl there, thanks for that..
But I have still an Issue. I can't set the Host, Port and Context Root. Which is a problem because my Oauth2 Server is on an another Server than my application. So I have still to use my workaround with some minor changes
````java
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.springdoc.core.SwaggerUiConfigProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import java.util.Map;
@Configuration
@Primary
@Getter
@Setter
public class ExtenedSwaggerUiConfigProperties extends SwaggerUiConfigProperties {
@Override
public Map<String, String> getConfigParameters() {
Map<String, String> params = super.getConfigParameters();
String oauth2RedirectUrl = getOauth2RedirectUrl();
if (StringUtils.isNotEmpty(oauth2RedirectUrl)) {
put("oauth2RedirectUrl"
, ServletUriComponentsBuilder.fromCurrentContextPath().path(oauth2RedirectUrl).build().toString()
, params);
}
return params;
}
}
Is there any way to solve this in the application.properties ? Something like
properties
springdoc.swagger-ui.oauth2RedirectUrl=${ServletUriComponentsBuilder.fromCurrentContextPath().path(\"/api/swagger-ui/oauth2-redirect.html\").build()}
@springdoc Shouldn't the default behavior be more in line with what @GrmpfNarf has laid out above? Where the default behavior defaults to the current context path? That's how the other swagger-ui properties work such as the swagger-ui.html property right?