@point3/logto-module
Version:
포인트3 내부 logto Authentication 모듈입니다
157 lines • 5.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LOGTO_ENV_REGISTRY = exports.LogtoEnvValidationError = void 0;
exports.resolveEnv = resolveEnv;
exports.resolveEnvOrThrow = resolveEnvOrThrow;
exports.validateLogtoEnv = validateLogtoEnv;
const errors_1 = require("./errors");
class LogtoEnvValidationError extends errors_1.LogtoError {
constructor(mode, missingVars) {
super(`LogtoModule 초기화 실패 [${mode} 모드]: 필수 환경변수가 누락되었습니다 - ${missingVars.join(', ')}`);
this.name = 'LogtoEnvValidationError';
}
}
exports.LogtoEnvValidationError = LogtoEnvValidationError;
exports.LOGTO_ENV_REGISTRY = [
{
newName: 'LOGTO/JWKS_URI',
legacyName: 'LOGTO_JWKS_URI',
requirement: 'always',
description: 'JWT 검증용 JWKS 엔드포인트',
},
{
newName: 'LOGTO/AUTH_ISSUER',
legacyName: 'LOGTO_AUTH_ISSUER',
requirement: 'always',
description: 'JWT 발급자(iss)',
},
{
newName: 'LOGTO/AUTH_ENDPOINT',
legacyName: 'LOGTO_AUTH_ENDPOINT',
requirement: 'client',
description: 'Logto 인증 서버 OIDC 엔드포인트',
},
{
newName: 'LOGTO/CLIENT_ID',
legacyName: 'LOGTO_CLIENT_ID',
requirement: 'client',
description: 'OAuth 클라이언트 ID',
},
{
newName: 'LOGTO/CLIENT_SECRET',
legacyName: 'LOGTO_CLIENT_SECRET',
requirement: 'client',
description: 'OAuth 클라이언트 시크릿',
},
{
newName: 'LOGTO/RESOURCES',
legacyName: 'LOGTO_RESOURCES',
requirement: 'client',
description: '접근할 리소스 서버',
},
{
newName: 'LOGTO/SCOPES',
legacyName: 'LOGTO_SCOPES',
requirement: 'client',
description: '요청할 OAuth 스코프',
},
{
newName: 'LOGTO/PROMPT',
legacyName: 'LOGTO_PROMPT',
requirement: 'client',
description: 'OAuth prompt 파라미터',
},
{
newName: 'LOGTO/REDIRECT_URI',
legacyName: 'LOGTO_REDIRECT_URI',
requirement: 'client',
description: '인증 후 리다이렉트 URI',
},
{
newName: 'LOGTO/SIGN_IN_URI',
legacyName: 'LOGTO_SIGN_IN_URI',
requirement: 'client',
description: '기본 로그인 URI',
},
{
newName: 'LOGTO/M2M_CLIENT_ID',
legacyName: 'LOGTO_M2M_CLIENT_ID',
requirement: 'client',
description: 'M2M 인증용 클라이언트 ID',
},
{
newName: 'LOGTO/M2M_CLIENT_SECRET',
legacyName: 'LOGTO_M2M_CLIENT_SECRET',
requirement: 'client',
description: 'M2M 인증용 클라이언트 시크릿',
},
{
newName: 'LOGTO/M2M_RESOURCE',
legacyName: 'LOGTO_M2M_RESOURCE',
requirement: 'client',
description: 'M2M 인증용 리소스',
},
{
newName: 'LOGTO/M2M_API_URL',
legacyName: 'LOGTO_M2M_API_URL',
requirement: 'client',
description: 'M2M API 서버 base URL',
},
{
newName: 'LOGTO/DASHBOARD_SIGN_IN_URI',
legacyName: 'LOGTO_DASHBOARD_SIGN_IN_URI',
requirement: 'optional',
description: '대시보드 로그인 URI',
},
];
const warnedDeprecations = new Set();
function resolveEnv(newName, legacyName) {
const newValue = process.env[newName];
if (newValue !== undefined) {
return newValue;
}
const legacyValue = process.env[legacyName];
if (legacyValue !== undefined) {
if (!warnedDeprecations.has(legacyName)) {
console.warn(`[DEPRECATION WARNING] 환경변수 '${legacyName}'는 deprecated되었습니다. '${newName}'를 사용하세요.`);
warnedDeprecations.add(legacyName);
}
return legacyValue;
}
return undefined;
}
function resolveEnvOrThrow(newName, legacyName) {
const value = resolveEnv(newName, legacyName);
if (value === undefined) {
throw new Error(`환경변수 '${newName}' 또는 '${legacyName}'가 설정되지 않았습니다.`);
}
return value;
}
function validateLogtoEnv(enableClient) {
const mode = enableClient ? 'Stateful' : 'Stateless';
const missingVars = [];
for (const entry of exports.LOGTO_ENV_REGISTRY) {
const isRequired = entry.requirement === 'always' ||
(enableClient && entry.requirement === 'client');
if (isRequired) {
const value = resolveEnv(entry.newName, entry.legacyName);
if (value === undefined) {
missingVars.push(`${entry.newName} (또는 ${entry.legacyName})`);
}
}
}
if (missingVars.length > 0) {
throw new LogtoEnvValidationError(mode, missingVars);
}
if (enableClient) {
for (const entry of exports.LOGTO_ENV_REGISTRY) {
if (entry.requirement === 'optional') {
const value = resolveEnv(entry.newName, entry.legacyName);
if (value === undefined) {
console.warn(`[WARNING] 선택적 환경변수 '${entry.newName}' (또는 '${entry.legacyName}')가 설정되지 않았습니다.`);
}
}
}
}
}
//# sourceMappingURL=env-config.js.map