package com.hithomelabs.cftunnels.Config; import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.security.*; import io.swagger.v3.oas.models.servers.Server; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import java.util.ArrayList; @Configuration @Profile("!integration") public class OpenApiConfig { @Value("${api.baseUrl}") private String baseUrl; @Value("${springdoc.swagger-ui.oauth.authorization-url}") private String authorizationUri; @Value("${springdoc.swagger-ui.oauth.token-url}") private String tokenUri; @Bean public OpenAPI openAPI() { Server httpsServer = new Server().url(baseUrl); OpenAPI openApi = new OpenAPI(); ArrayList servers = new ArrayList<>(); servers.add(httpsServer); openApi.setServers(servers); openApi.addSecurityItem(new SecurityRequirement().addList("oidcAuth")) .components(new Components() .addSecuritySchemes("oidcAuth", new SecurityScheme() .type(SecurityScheme.Type.OAUTH2) .flows(new OAuthFlows() .authorizationCode(new OAuthFlow() .authorizationUrl(authorizationUri) .tokenUrl(tokenUri) .scopes(new Scopes() .addString("openid", "OpenID scope") .addString("profile", "OpenID profile") .addString("email", "OpenID email")) ) ) ) ) .addSecurityItem(new SecurityRequirement().addList("oidcAuth")); return openApi; } }