-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiServiceCollectionExtensions.cs
More file actions
88 lines (76 loc) · 2.87 KB
/
ApiServiceCollectionExtensions.cs
File metadata and controls
88 lines (76 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using Microsoft.Extensions.DependencyInjection;
using ProjectVG.Api.Services;
using ProjectVG.Api.Filters;
using Microsoft.AspNetCore.Authentication.Negotiate;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.IdentityModel.Tokens;
namespace ProjectVG.Api
{
public static class ApiServiceCollectionExtensions
{
/// <summary>
/// API 서비스 등록
/// </summary>
public static IServiceCollection AddApiServices(this IServiceCollection services)
{
services.AddControllers(options => {
options.Filters.Add<ModelStateValidationFilter>();
});
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(c => {
c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo {
Title = "ProjectVG API",
Version = "v1",
Description = "ProjectVG API Server"
});
});
services.AddSingleton<TestClientLauncher>();
return services;
}
/// <summary>
/// 인증 및 인가 서비스
/// </summary>
public static IServiceCollection AddApiAuthentication(this IServiceCollection services)
{
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
.AddNegotiate();
services.AddAuthorization(options => {
options.FallbackPolicy = null;
});
return services;
}
/// <summary>
/// OAuth2 인증 서비스 (선택적)
/// </summary>
public static IServiceCollection AddOAuth2Authentication(this IServiceCollection services)
{
// OAuth2는 별도 컨트롤러에서 처리하므로 기본 인증만 설정
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie();
return services;
}
/// <summary>
/// 개발용 CORS 정책
/// </summary>
public static IServiceCollection AddDevelopmentCors(this IServiceCollection services)
{
services.AddCors(options => {
options.AddPolicy("AllowAll",
policy => policy.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()
.WithExposedHeaders("X-Access-Credit", "X-Refresh-Credit", "X-Expires-In", "X-UID"));
});
return services;
}
/// <summary>
/// 부하테스트 전용 성능 모니터링 서비스
/// </summary>
public static IServiceCollection AddLoadTestPerformanceServices(this IServiceCollection services)
{
services.AddSingleton<PerformanceCounterService>();
return services;
}
}
}