All checks were successful
sample gradle build and test / build (pull_request) Successful in 1m49s
- Configure OpenAPI with OAuth2 authorization code flow and required scopes - Add security scheme and requirements for API documentation - Remove unused swagger redirect methods from HomeController - Comment out swagger endpoint permissions in SecurityConfig
55 lines
2.3 KiB
Java
55 lines
2.3 KiB
Java
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<Server> 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;
|
|
}
|
|
}
|