- POST /api/v1/internal/exchange-token 추가 - HMAC-SHA256 서명 기반 서버간 인증 - InternalTokenService: 서명 검증 및 Sanctum 토큰 발급 - ExchangeTokenRequest: 요청 검증 (user_id, tenant_id, exp, signature) - ApiKeyMiddleware: 내부 통신 경로 화이트리스트 추가 - i18n 메시지 추가 (error.internal.*, message.internal.*) 환경변수 필요: INTERNAL_EXCHANGE_SECRET (MNG와 동일)
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Helpers\ApiResponse;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Internal\ExchangeTokenRequest;
|
|
use App\Services\InternalTokenService;
|
|
|
|
/**
|
|
* 내부 서버간 통신 컨트롤러
|
|
*
|
|
* MNG → API 서버간 인증 토큰 교환 등을 처리합니다.
|
|
*/
|
|
class InternalController extends Controller
|
|
{
|
|
public function __construct(
|
|
private InternalTokenService $tokenService
|
|
) {}
|
|
|
|
/**
|
|
* 토큰 교환
|
|
*
|
|
* MNG 서버에서 HMAC 서명된 페이로드로 API 토큰을 발급받습니다.
|
|
*/
|
|
public function exchangeToken(ExchangeTokenRequest $request)
|
|
{
|
|
$validated = $request->validated();
|
|
|
|
$result = $this->tokenService->exchange(
|
|
userId: $validated['user_id'],
|
|
tenantId: $validated['tenant_id'],
|
|
exp: $validated['exp'],
|
|
signature: $validated['signature']
|
|
);
|
|
|
|
if (! $result['success']) {
|
|
return ApiResponse::error($result['error'], 401);
|
|
}
|
|
|
|
return ApiResponse::success(
|
|
data: $result['data'],
|
|
message: __('message.internal.token_exchanged')
|
|
);
|
|
}
|
|
}
|