[Feature] X-Service-Code / X-API-KEY 서비스 식별 미들웨어 구현 #32

Closed
opened 2026-02-09 08:23:28 +00:00 by seonkyu.kim · 0 comments
Owner

설명

멀티테넌시 지원을 위해 X-Service-Code 헤더 기반 서비스 식별 미들웨어와 X-API-KEY 검증 미들웨어를 구현한다.

📌 참조: Documents/ProgramSetup.md §7 (파이프라인 순서 12~13번) 및 §8.4~8.5 (구현 가이드) 필독

체크리스트

ServiceRepository (선행 — 미들웨어가 DB 조회 필요)

  • SPMS.Infrastructure/Persistence/Repositories/ServiceRepository.cs — IServiceRepository 구현
    • GetByServiceCodeAsync: service_code로 서비스 조회
    • GetByApiKeyAsync: api_key로 서비스 조회
  • DependencyInjection.cs에 ServiceRepository DI 등록

ServiceCodeMiddleware (파이프라인 순서 12번)

  • SPMS.API/Middlewares/ServiceCodeMiddleware.cs
    • X-Service-Code 헤더 추출
    • DB에서 서비스 존재 여부 및 활성 상태 확인
    • 비활성 서비스 → HTTP 503 반환
    • HttpContext.Items에 서비스 정보 저장 ("Service", "ServiceId")
    • 공개 API 경로 예외 처리 (/v1/out/*, /swagger)

ApiKeyMiddleware (파이프라인 순서 13번)

  • SPMS.API/Middlewares/ApiKeyMiddleware.cs
    • /v1/in/device/* 경로만 X-API-KEY 검증
    • 유효하지 않은 API Key → HTTP 403 반환
    • HttpContext.Items에 서비스 정보 저장

파이프라인 등록

  • ApplicationBuilderExtensions.cs — 미들웨어 주석 해제 및 등록
  • 빌드 성공 확인
## 설명 멀티테넌시 지원을 위해 X-Service-Code 헤더 기반 서비스 식별 미들웨어와 X-API-KEY 검증 미들웨어를 구현한다. > **📌 참조**: `Documents/ProgramSetup.md` §7 (파이프라인 순서 12~13번) 및 §8.4~8.5 (구현 가이드) 필독 ## 체크리스트 ### ServiceRepository (선행 — 미들웨어가 DB 조회 필요) - [x] `SPMS.Infrastructure/Persistence/Repositories/ServiceRepository.cs` — IServiceRepository 구현 - GetByServiceCodeAsync: service_code로 서비스 조회 - GetByApiKeyAsync: api_key로 서비스 조회 - [x] DependencyInjection.cs에 ServiceRepository DI 등록 ### ServiceCodeMiddleware (파이프라인 순서 12번) - [x] `SPMS.API/Middlewares/ServiceCodeMiddleware.cs` - X-Service-Code 헤더 추출 - DB에서 서비스 존재 여부 및 활성 상태 확인 - 비활성 서비스 → HTTP 503 반환 - HttpContext.Items에 서비스 정보 저장 ("Service", "ServiceId") - 공개 API 경로 예외 처리 (`/v1/out/*`, `/swagger`) ### ApiKeyMiddleware (파이프라인 순서 13번) - [x] `SPMS.API/Middlewares/ApiKeyMiddleware.cs` - `/v1/in/device/*` 경로만 X-API-KEY 검증 - 유효하지 않은 API Key → HTTP 403 반환 - HttpContext.Items에 서비스 정보 저장 ### 파이프라인 등록 - [x] `ApplicationBuilderExtensions.cs` — 미들웨어 주석 해제 및 등록 - [x] 빌드 성공 확인
seonkyu.kim added the
Priority
High
Status
Available
Type
Feature
labels 2026-02-09 08:23:35 +00:00
seonkyu.kim self-assigned this 2026-02-09 08:23:36 +00:00
seonkyu.kim added this to the Phase 1: 인프라 & 공통 모듈 milestone 2026-02-09 08:23:38 +00:00
seonkyu.kim added
Status
Done
and removed
Status
Available
labels 2026-02-09 08:27:20 +00:00
Sign in to join this conversation.
No description provided.