@thinkingcat/auth-utils 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -139,7 +139,7 @@ import {
139
139
  createMiddlewareConfig,
140
140
  handleMiddleware,
141
141
  verifyAndRefreshTokenWithNextAuth,
142
-
142
+
143
143
  // 라이센스
144
144
  checkLicenseKey,
145
145
 
@@ -166,7 +166,8 @@ const response = await handleMiddleware(req, middlewareConfig, {
166
166
  });
167
167
  ```
168
168
 
169
- **중요**:
169
+ **중요**:
170
+
170
171
  - 라이센스 키는 모든 함수 호출 시 필수 파라미터입니다.
171
172
  - 라이센스 키가 없거나 유효하지 않으면 함수가 에러를 발생시킵니다.
172
173
  - 라이센스 키는 SHA-256 해시로 변환되어 모듈 내부의 유효한 키 목록과 비교됩니다.
package/dist/index.d.ts CHANGED
@@ -325,7 +325,7 @@ export interface MiddlewareOptions {
325
325
  /** 라이센스 키 (필수) */
326
326
  licenseKey: string;
327
327
  }
328
- export declare function checkLicenseKey(licenseKey: string): void;
328
+ export declare function checkLicenseKey(licenseKey: string): Promise<void>;
329
329
  export declare function checkRoleAccess(pathname: string, role: string, roleConfig: RoleAccessConfig): {
330
330
  allowed: boolean;
331
331
  message?: string;
package/dist/index.js CHANGED
@@ -67,7 +67,14 @@ exports.handleMiddleware = handleMiddleware;
67
67
  const jwt_1 = require("next-auth/jwt");
68
68
  const jose_1 = require("jose");
69
69
  const server_1 = require("next/server");
70
- const crypto_1 = require("crypto");
70
+ // Edge Runtime 호환을 위해 Web Crypto API 사용
71
+ async function createHashSHA256(data) {
72
+ const encoder = new TextEncoder();
73
+ const dataBuffer = encoder.encode(data);
74
+ const hashBuffer = await crypto.subtle.digest('SHA-256', dataBuffer);
75
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
76
+ return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
77
+ }
71
78
  /**
72
79
  * 토큰 검증 및 디코딩
73
80
  * @param accessToken JWT access token
@@ -331,7 +338,7 @@ function createRedirectHTML(redirectPath, text) {
331
338
  * @returns NextResponse 객체
332
339
  */
333
340
  async function createAuthResponse(accessToken, secret, options) {
334
- checkLicenseKey(options.licenseKey);
341
+ await checkLicenseKey(options.licenseKey);
335
342
  const { refreshToken, redirectPath, text, cookiePrefix, isProduction = false, cookieDomain, serviceId, } = options;
336
343
  // 1. 토큰 검증
337
344
  const tokenResult = await verifyToken(accessToken, secret);
@@ -600,11 +607,11 @@ function requiresSubscription(pathname, role, subscriptionRequiredPaths, systemA
600
607
  const VALID_LICENSE_KEY_HASHES = new Set([
601
608
  '73bce4f3b64804c255cdab450d759a8b53038f9edb59ae42d9988b08dfd007e2',
602
609
  ]);
603
- function checkLicenseKey(licenseKey) {
610
+ async function checkLicenseKey(licenseKey) {
604
611
  if (!licenseKey || licenseKey.length < 10) {
605
612
  throw new Error('License key is required');
606
613
  }
607
- const keyHash = (0, crypto_1.createHash)('sha256').update(licenseKey).digest('hex');
614
+ const keyHash = await createHashSHA256(licenseKey);
608
615
  if (!VALID_LICENSE_KEY_HASHES.has(keyHash)) {
609
616
  throw new Error('Invalid license key');
610
617
  }
@@ -858,7 +865,7 @@ async function handleMiddleware(req, config, options) {
858
865
  try {
859
866
  const pathname = req.nextUrl.pathname;
860
867
  const { secret, isProduction, cookieDomain, getNextAuthToken, licenseKey } = options;
861
- checkLicenseKey(licenseKey);
868
+ await checkLicenseKey(licenseKey);
862
869
  if (!config.serviceId) {
863
870
  throw new Error('serviceId is required in middleware config');
864
871
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkingcat/auth-utils",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Authentication utilities for ThinkingCat SSO services",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",