forked from AcaMate/AcaMate_API
[♻️] PUSH API 리팩토링 진행 중_5
This commit is contained in:
parent
9413dbbea8
commit
f443f3410c
42
Program.cs
42
Program.cs
|
@ -5,10 +5,17 @@ using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
using AcaMate.Common.Models;
|
using AcaMate.Common.Models;
|
||||||
using AcaMate.V1.Services;
|
using AcaMate.V1.Services;
|
||||||
using AcaMate.Common.Data;
|
using AcaMate.Common.Data;
|
||||||
using AcaMate.V1.Controllers;
|
using AcaMate.V1.Controllers;
|
||||||
|
using AcaMate.V1.Models;
|
||||||
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
@ -71,6 +78,37 @@ builder.Services.AddAuthentication(options =>
|
||||||
});
|
});
|
||||||
// JWT 설정부 끝
|
// JWT 설정부 끝
|
||||||
|
|
||||||
|
// PUSH 설정부
|
||||||
|
// 설정 바인딩 (appsettings.json의 "ApnsPushService" 섹션)
|
||||||
|
builder.Services.Configure<PushFileSetting>(builder.Configuration.GetSection("PushFileSetting"));
|
||||||
|
|
||||||
|
// HttpClientFactory를 이용한 ApnsPushService 등록 (핸들러에 인증서 추가)
|
||||||
|
builder.Services.AddHttpClient<IApnsPushService, ApnsPushService>(client =>
|
||||||
|
{
|
||||||
|
var settings = builder.Configuration.GetSection("PushFileSetting").Get<PushFileSetting>();
|
||||||
|
client.BaseAddress = new Uri(settings.uri);
|
||||||
|
client.Timeout = TimeSpan.FromSeconds(60);
|
||||||
|
})
|
||||||
|
.ConfigurePrimaryHttpMessageHandler(() =>
|
||||||
|
{
|
||||||
|
var config = builder.Configuration.GetSection("PushFileSetting").Get<PushFileSetting>();
|
||||||
|
var handler = new HttpClientHandler();
|
||||||
|
// using var reader = new StreamReader(config.p12PWPath, new UTF8Encoding(false));
|
||||||
|
// var json = reader.ReadToEndAsync();
|
||||||
|
// p12PWPath 파일에서 비밀번호 읽어오기 (예시: JSON {"Password": "비밀번호"})
|
||||||
|
var json = File.ReadAllText(config.p12PWPath);
|
||||||
|
var keys = JsonSerializer.Deserialize<Dictionary<string, string>>(json);
|
||||||
|
var certificate = new X509Certificate2(config.p12Path, keys["Password"]);
|
||||||
|
handler.ClientCertificates.Add(certificate);
|
||||||
|
handler.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
|
||||||
|
return handler;
|
||||||
|
});
|
||||||
|
|
||||||
|
// InMemoryPushQueue와 백그라운드 서비스 등록
|
||||||
|
builder.Services.AddSingleton<IPushQueue, InMemoryPushQueue>();
|
||||||
|
builder.Services.AddHostedService<PushBackgroundService>();
|
||||||
|
// PUSH 설정부 끝
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
// 여기다가 API 있는 컨트롤러들 AddScoped 하면 되는건가?
|
// 여기다가 API 있는 컨트롤러들 AddScoped 하면 되는건가?
|
||||||
|
@ -114,7 +152,7 @@ else
|
||||||
|
|
||||||
|
|
||||||
// 로컬 테스트 위한 부분 (올릴때는 꺼두기)
|
// 로컬 테스트 위한 부분 (올릴때는 꺼두기)
|
||||||
builder.WebHost.UseUrls("http://0.0.0.0:5144");
|
// builder.WebHost.UseUrls("http://0.0.0.0:5144");
|
||||||
|
|
||||||
///// ===== builder 설정 부 ===== /////
|
///// ===== builder 설정 부 ===== /////
|
||||||
|
|
||||||
|
@ -134,7 +172,7 @@ else
|
||||||
}
|
}
|
||||||
|
|
||||||
// 로컬 테스트 위한 부분 (올릴떄는 켜두기)
|
// 로컬 테스트 위한 부분 (올릴떄는 켜두기)
|
||||||
// app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
// app.MapControllers();
|
// app.MapControllers();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user