Skip to content

Commit

Permalink
✅ Test[#10]: Swagger 인증 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kduoh99 committed Nov 21, 2024
1 parent c9d904c commit 2dcf07f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public class SecurityConfig {
"swagger-ui/**",
"v3/api-docs/**",
"/v1/**",
"/profile",
"/**" // 테스트용
"/profile"
};

@Bean
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/groom/swipo/global/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

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.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;

@Configuration
Expand All @@ -28,6 +31,8 @@ private Info apiInfo() {

@Bean
public OpenAPI openAPI() {
String authHeader = "Authorization";

Server localServer = new Server();
localServer.description("Local Server")
.url(localUrl);
Expand All @@ -38,6 +43,13 @@ public OpenAPI openAPI() {

return new OpenAPI()
.info(apiInfo())
.addSecurityItem(new SecurityRequirement().addList(authHeader))
.components(new Components()
.addSecuritySchemes(authHeader, new SecurityScheme()
.name(authHeader)
.type(SecurityScheme.Type.HTTP)
.scheme("Bearer")
.bearerFormat("accessToken")))
.servers(Arrays.asList(localServer, prodServer));
}
}

0 comments on commit 2dcf07f

Please sign in to comment.