Skip to content

Support for oauth2RedirectUrl #240

@GrmpfNarf

Description

@GrmpfNarf

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.

My Workaround

ExtenedSwaggerUiConfigProperties.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions