Я использую org.springdoc:springdoc-openapi -starter-webmvc-ui:2.6.0.
Код: Выделить всё
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@RequiredArgsConstructor
public class SpringdocConfiguration {
private static final String OAUTH_SCHEME = "auth";
@Value("${spring.security.oauth2.resourceserver.jwt.issuer-uri}")
String authURL;
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info().title("Application"))
.addSecurityItem(new SecurityRequirement()
.addList(OAUTH_SCHEME))
.components(new Components()
.addSecuritySchemes(OAUTH_SCHEME, createOAuthScheme()))
.info(new Info());
}
private SecurityScheme createOAuthScheme() {
return new SecurityScheme().type(SecurityScheme.Type.OAUTH2).flows(createOAuthFlows());
}
private OAuthFlows createOAuthFlows() {
final var oauthFlow = new OAuthFlow()
.authorizationUrl(authURL + "/protocol/openid-connect" + "/auth")
.refreshUrl(authURL + "/protocol/openid-connect" + "/token")
.tokenUrl(authURL + "/protocol/openid-connect" + "/token")
.scopes(new Scopes());
return new OAuthFlows().authorizationCode(oauthFlow);
}
}
Код: Выделить всё
https://user.example.com/auth/realms/om-test-dev/protocol/openid-connect/auth?response_type=code&client_id=om-test-dev&state=VGVpN351Z3ZJLS1jYksuUnNjUzFDZHdUSEh3ZmVSTGpMeC5yaS5jck13SnMtsemicolon%252Fuser-dashboard&redirect_uri=https%3A%2F%2Ftest.example.com%2Fhome&scope=openid%20profile%20email%20offline_access&code_challenge=Nuk3JzAnPRtg9Mmxiok26kj3qCQ_0H87T-PB5VgIPVw&code_challenge_method=S256&nonce=VGVpN351Z3ZJLS1jYksuUnNjUzFDZHdUSEh3ZmVSTGpMeC5yaS5jck13SnMt
Код: Выделить всё
https://user.example.com/auth/realms/om-test-dev/protocol/openid-connect/auth?response_type=code&client_id=aaaaaaaaaaaaaaaa&redirect_uri=https%3A%2F%2Ftest.example.com%3A8080%2Fapi%2Fswagger-ui%2Foauth2-redirect.html&state=VGh1IE9jdCAyNCAyMDI0IDE2OjA4OjM5IEdNVCswMzAwIChFYXN0ZXJuIEV1cm9wZWFuIFN1bW1lciBUaW1lKQ%3D%3D
Подробнее здесь: https://stackoverflow.com/questions/791 ... th-swagger
Мобильная версия