mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 11:49:25 +00:00
Openapi read oauth url from properties
This commit is contained in:
@@ -9,22 +9,32 @@ import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(TwitchOAuthProperties.class)
|
||||
public class OpenApiConfig {
|
||||
|
||||
private static final String TWITCH_OAUTH_SCHEME = "twitchOAuth";
|
||||
|
||||
private final TwitchOAuthProperties twitchProps;
|
||||
|
||||
public OpenApiConfig(TwitchOAuthProperties twitchProps) {
|
||||
this.twitchProps = twitchProps;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public OpenAPI imgfloatOpenAPI() {
|
||||
return new OpenAPI()
|
||||
.components(new Components().addSecuritySchemes(TWITCH_OAUTH_SCHEME, twitchOAuthScheme()))
|
||||
.components(new Components().addSecuritySchemes(
|
||||
TWITCH_OAUTH_SCHEME,
|
||||
twitchOAuthScheme()
|
||||
))
|
||||
.addSecurityItem(new SecurityRequirement().addList(TWITCH_OAUTH_SCHEME))
|
||||
.info(
|
||||
new Info()
|
||||
.title("Imgfloat API")
|
||||
.description("OpenAPI documentation for Imgfloat admin and broadcaster APIs.")
|
||||
.version("v1")
|
||||
.info(new Info()
|
||||
.title("Imgfloat API")
|
||||
.description("OpenAPI documentation for Imgfloat admin and broadcaster APIs.")
|
||||
.version("v1")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,12 +42,10 @@ public class OpenApiConfig {
|
||||
return new SecurityScheme()
|
||||
.name(TWITCH_OAUTH_SCHEME)
|
||||
.type(SecurityScheme.Type.OAUTH2)
|
||||
.flows(
|
||||
new OAuthFlows().authorizationCode(
|
||||
new OAuthFlow()
|
||||
.authorizationUrl("https://id.twitch.tv/oauth2/authorize")
|
||||
.tokenUrl("https://id.twitch.tv/oauth2/token")
|
||||
)
|
||||
);
|
||||
.flows(new OAuthFlows().authorizationCode(
|
||||
new OAuthFlow()
|
||||
.authorizationUrl(twitchProps.getAuthorizationUri())
|
||||
.tokenUrl(twitchProps.getTokenUri())
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package dev.kruhlmann.imgfloat.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "spring.security.oauth2.client.provider.twitch")
|
||||
public class TwitchOAuthProperties {
|
||||
|
||||
private String authorizationUri;
|
||||
private String tokenUri;
|
||||
|
||||
public String getAuthorizationUri() {
|
||||
return authorizationUri;
|
||||
}
|
||||
|
||||
public void setAuthorizationUri(String authorizationUri) {
|
||||
this.authorizationUri = authorizationUri;
|
||||
}
|
||||
|
||||
public String getTokenUri() {
|
||||
return tokenUri;
|
||||
}
|
||||
|
||||
public void setTokenUri(String tokenUri) {
|
||||
this.tokenUri = tokenUri;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user